summaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/prof/tcmalloc.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/actors/prof/tcmalloc.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/actors/prof/tcmalloc.cpp')
-rw-r--r--library/cpp/actors/prof/tcmalloc.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/library/cpp/actors/prof/tcmalloc.cpp b/library/cpp/actors/prof/tcmalloc.cpp
new file mode 100644
index 00000000000..3d4f203dbb4
--- /dev/null
+++ b/library/cpp/actors/prof/tcmalloc.cpp
@@ -0,0 +1,32 @@
+#include "tcmalloc.h"
+
+#include <contrib/libs/tcmalloc/tcmalloc/malloc_extension.h>
+
+namespace NProfiling {
+
+static thread_local ui32 AllocationTag = 0;
+
+static struct TInitTCMallocCallbacks {
+ static void* CreateTag() {
+ return reinterpret_cast<void*>(AllocationTag);
+ }
+ static void* CopyTag(void* tag) {
+ return tag;
+ }
+ static void DestroyTag(void* tag) {
+ Y_UNUSED(tag);
+ }
+
+ TInitTCMallocCallbacks() {
+ tcmalloc::MallocExtension::SetSampleUserDataCallbacks(
+ CreateTag, CopyTag, DestroyTag);
+ }
+} InitTCMallocCallbacks;
+
+ui32 SetTCMallocThreadAllocTag(ui32 tag) {
+ ui32 prev = AllocationTag;
+ AllocationTag = tag;
+ return prev;
+}
+
+}