dbg_info.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <util/generic/ptr.h>
  3. #include <util/system/types.h>
  4. namespace NAllocDbg {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. // Allocation statistics
  7. enum ELFAllocCounter {
  8. CT_USER_ALLOC, // accumulated size requested by user code
  9. CT_MMAP, // accumulated mmapped size
  10. CT_MMAP_CNT, // number of mmapped regions
  11. CT_MUNMAP, // accumulated unmmapped size
  12. CT_MUNMAP_CNT, // number of munmaped regions
  13. CT_SYSTEM_ALLOC, // accumulated allocated size for internal lfalloc needs
  14. CT_SYSTEM_FREE, // accumulated deallocated size for internal lfalloc needs
  15. CT_SMALL_ALLOC, // accumulated allocated size for fixed-size blocks
  16. CT_SMALL_FREE, // accumulated deallocated size for fixed-size blocks
  17. CT_LARGE_ALLOC, // accumulated allocated size for large blocks
  18. CT_LARGE_FREE, // accumulated deallocated size for large blocks
  19. CT_SLOW_ALLOC_CNT, // number of slow (not LF) allocations
  20. CT_DEGRAGMENT_CNT, // number of memory defragmentations
  21. CT_MAX
  22. };
  23. i64 GetAllocationCounterFast(ELFAllocCounter counter);
  24. i64 GetAllocationCounterFull(ELFAllocCounter counter);
  25. ////////////////////////////////////////////////////////////////////////////////
  26. // Allocation statistics could be tracked on per-tag basis
  27. int SetThreadAllocTag(int tag);
  28. class TScopedTag {
  29. private:
  30. int PrevTag;
  31. public:
  32. explicit TScopedTag(int tag) {
  33. PrevTag = SetThreadAllocTag(tag);
  34. }
  35. ~TScopedTag() {
  36. SetThreadAllocTag(PrevTag);
  37. }
  38. };
  39. struct TPerTagAllocInfo {
  40. ssize_t Count;
  41. ssize_t Size;
  42. };
  43. TArrayPtr<TPerTagAllocInfo> GetPerTagAllocInfo(
  44. bool flushPerThreadCounters,
  45. int& maxTag,
  46. int& numSizes);
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // Allocation sampling could be used to collect detailed information
  49. bool SetProfileCurrentThread(bool newVal);
  50. bool SetProfileAllThreads(bool newVal);
  51. bool SetAllocationSamplingEnabled(bool newVal);
  52. size_t SetAllocationSampleRate(size_t newVal);
  53. size_t SetAllocationSampleMaxSize(size_t newVal);
  54. #define DBG_ALLOC_INVALID_COOKIE (-1)
  55. using TAllocationCallback = int(int tag, size_t size, int sizeIdx);
  56. using TDeallocationCallback = void(int cookie, int tag, size_t size, int sizeIdx);
  57. TAllocationCallback* SetAllocationCallback(TAllocationCallback* newVal);
  58. TDeallocationCallback* SetDeallocationCallback(TDeallocationCallback* newVal);
  59. }