aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/prof/tcmalloc.cpp
blob: 3d4f203dbb4bd8a3b71f519beab38d27430c56b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}

}