tcmalloc.cpp 711 B

1234567891011121314151617181920212223242526272829303132
  1. #include "tcmalloc.h"
  2. #include <contrib/libs/tcmalloc/tcmalloc/malloc_extension.h>
  3. namespace NProfiling {
  4. static thread_local ui32 AllocationTag = 0;
  5. static struct TInitTCMallocCallbacks {
  6. static void* CreateTag() {
  7. return reinterpret_cast<void*>(AllocationTag);
  8. }
  9. static void* CopyTag(void* tag) {
  10. return tag;
  11. }
  12. static void DestroyTag(void* tag) {
  13. Y_UNUSED(tag);
  14. }
  15. TInitTCMallocCallbacks() {
  16. tcmalloc::MallocExtension::SetSampleUserDataCallbacks(
  17. CreateTag, CopyTag, DestroyTag);
  18. }
  19. } InitTCMallocCallbacks;
  20. ui32 SetTCMallocThreadAllocTag(ui32 tag) {
  21. ui32 prev = AllocationTag;
  22. AllocationTag = tag;
  23. return prev;
  24. }
  25. }