profiler.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "stackcollect.h"
  3. #include <library/cpp/lfalloc/dbg_info/dbg_info.h>
  4. #include <util/generic/noncopyable.h>
  5. #include <util/stream/output.h>
  6. namespace NAllocProfiler {
  7. ////////////////////////////////////////////////////////////////////////////////
  8. inline int SetCurrentScopeTag(int value)
  9. {
  10. return NAllocDbg::SetThreadAllocTag(value);
  11. }
  12. inline bool SetProfileCurrentThread(bool value)
  13. {
  14. return NAllocDbg::SetProfileCurrentThread(value);
  15. }
  16. bool StartAllocationSampling(bool profileAllThreads = false);
  17. bool StopAllocationSampling(IAllocationStatsDumper& out, int count = 100);
  18. bool StopAllocationSampling(IOutputStream& out, int count = 100);
  19. ////////////////////////////////////////////////////////////////////////////////
  20. class TProfilingScope: private TNonCopyable {
  21. private:
  22. const int Prev;
  23. public:
  24. explicit TProfilingScope(int value)
  25. : Prev(SetCurrentScopeTag(value))
  26. {}
  27. ~TProfilingScope()
  28. {
  29. SetCurrentScopeTag(Prev);
  30. }
  31. };
  32. } // namespace NAllocProfiler