aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/lwtrace/log_shuttle.cpp
blob: 695aa90b316712ce0498c6a06182dfb3ebb0ac92 (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
59
60
61
62
63
64
65
66
67
#include "log_shuttle.h"
#include "probes.h"

namespace NLWTrace {
    LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER);

#ifdef LWTRACE_DISABLE

    template <class TDepot>
    bool TLogShuttle<TDepot>::DoFork(TShuttlePtr& child) {
        Y_UNUSED(child);
        return false;
    }

    template <class TDepot>
    bool TLogShuttle<TDepot>::DoJoin(const TShuttlePtr& child) {
        Y_UNUSED(child);
        return false;
    }

#else

    template <class TDepot>
    bool TLogShuttle<TDepot>::DoFork(TShuttlePtr& child) {
        if (child = Executor->RentShuttle()) {
            child->SetParentSpanId(GetSpanId());
            Executor->Cast(child)->SetIgnore(true);
            TParams params;
            params.Param[0].CopyConstruct<ui64>(child->GetSpanId());
            bool result = DoAddProbe(&LWTRACE_GET_NAME(Fork).Probe, params, 0);
            TUserSignature<ui64>::DestroyParams(params);
            return result;
        }
        AtomicIncrement(ForkFailed);
        return false;
    }

    template <class TDepot>
    bool TLogShuttle<TDepot>::DoJoin(const TShuttlePtr& shuttle) {
        auto* child = Executor->Cast(shuttle);
        TParams params;
        params.Param[0].CopyConstruct<ui64>(child->GetSpanId());
        params.Param[1].CopyConstruct<ui64>(child->TrackLog.Items.size());
        bool result = DoAddProbe(&LWTRACE_GET_NAME(Join).Probe, params, 0);
        TUserSignature<ui64, ui64>::DestroyParams(params);
        if (result) {
            with_lock (Lock) {
                ssize_t n = MaxTrackLength - TrackLog.Items.size();
                for (auto& item: child->TrackLog.Items) {
                    if (n-- <= 0) {
                        TrackLog.Truncated = true;
                        break;
                    }
                    TrackLog.Items.emplace_back(item);
                }
            }
        }
        AtomicAdd(ForkFailed, AtomicGet(child->ForkFailed));
        Executor->ParkShuttle(child);
        return result;
    }

#endif

    template class TLogShuttle<TDurationDepot>;
    template class TLogShuttle<TCyclicDepot>;
}