aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core/callstack.h
blob: 034d0becf137956307c062ea7c7b54e4cc6019dc (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#ifndef NDEBUG
//#define ENABLE_ACTOR_CALLSTACK
#endif

#ifdef ENABLE_ACTOR_CALLSTACK
#include "defs.h"
#include <util/system/backtrace.h>
#include <util/stream/str.h>
#include <util/generic/deque.h>
#define USE_ACTOR_CALLSTACK

namespace NActors {
    struct TCallstack {
        struct TTrace {
            static const size_t CAPACITY = 50;
            void* Data[CAPACITY];
            size_t Size;
            size_t LinesToSkip;

            TTrace()
                : Size(0)
                , LinesToSkip(0)
            {
            }
        };

        static const size_t RECORDS = 8;
        static const size_t RECORDS_TO_SKIP = 2;
        TTrace Record[RECORDS];
        size_t BeginIdx;
        size_t Size;
        size_t LinesToSkip;

        TCallstack();
        void SetLinesToSkip();
        void Trace();
        void TraceIfEmpty();
        static TCallstack& GetTlsCallstack();
        static void DumpCallstack(TStringStream& str);
    };

    void EnableActorCallstack();
    void DisableActorCallstack();

}

#else

namespace NActors {
    inline void EnableActorCallstack(){}

    inline void DisableActorCallstack(){}

}

#endif