callstack.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #ifndef NDEBUG
  3. //#define ENABLE_ACTOR_CALLSTACK
  4. #endif
  5. #ifdef ENABLE_ACTOR_CALLSTACK
  6. #include "defs.h"
  7. #include <util/system/backtrace.h>
  8. #include <util/stream/str.h>
  9. #include <util/generic/deque.h>
  10. #define USE_ACTOR_CALLSTACK
  11. namespace NActors {
  12. struct TCallstack {
  13. struct TTrace {
  14. static const size_t CAPACITY = 50;
  15. void* Data[CAPACITY];
  16. size_t Size;
  17. size_t LinesToSkip;
  18. TTrace()
  19. : Size(0)
  20. , LinesToSkip(0)
  21. {
  22. }
  23. };
  24. static const size_t RECORDS = 8;
  25. static const size_t RECORDS_TO_SKIP = 2;
  26. TTrace Record[RECORDS];
  27. size_t BeginIdx;
  28. size_t Size;
  29. size_t LinesToSkip;
  30. TCallstack();
  31. void SetLinesToSkip();
  32. void Trace();
  33. void TraceIfEmpty();
  34. static TCallstack& GetTlsCallstack();
  35. static void DumpCallstack(TStringStream& str);
  36. };
  37. void EnableActorCallstack();
  38. void DisableActorCallstack();
  39. }
  40. #else
  41. namespace NActors {
  42. inline void EnableActorCallstack(){}
  43. inline void DisableActorCallstack(){}
  44. }
  45. #endif