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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#include "probes.h"
#include <library/cpp/lwtrace/protos/lwtrace.pb.h>
#include <util/generic/string.h>
namespace NLWTrace {
LWTRACE_USING(LWTRACE_INTERNAL_PROVIDER);
TProbeMap TManager::GetProbesMap() {
class TProbeReader
{
private:
TProbeMap& Result;
public:
TProbeReader(TProbeMap& result)
: Result(result)
{}
void Push(NLWTrace::TProbe* probe)
{
Result[std::make_pair(probe->Event.Name, probe->Event.GetProvider())] = probe;
}
};
TProbeMap result;
auto reader = TProbeReader(result);
ReadProbes(reader);
return result;
}
void TManager::CreateTraceRequest(TTraceRequest& msg, TOrbit& orbit)
{
msg.SetIsTraced(orbit.HasShuttles());
}
bool TManager::HandleTraceRequest(
const TTraceRequest& msg,
TOrbit& orbit)
{
if (!msg.GetIsTraced()) {
return false;
}
TParams params;
SerializingExecutor->Execute(orbit, params);
return true;
}
TTraceDeserializeStatus TManager::HandleTraceResponse(
const TTraceResponse& msg,
const TProbeMap& probesMap,
TOrbit& orbit,
i64 timeOffset,
double timeScale)
{
TTraceDeserializeStatus result;
if (!msg.GetTrace().GetEvents().size()) {
return result;
}
ui64 prev = EpochNanosecondsToCycles(
msg.GetTrace().GetEvents()[0].GetTimestampNanosec());
for (auto& v : msg.GetTrace().GetEvents()) {
auto it = probesMap.find(std::make_pair(v.GetName(), v.GetProvider()));
if (it != probesMap.end()) {
TProbe* probe = it->second;
TParams params;
if(!probe->Event.Signature.DeserializeFromPb(params, v.GetParams())) {
LWTRACK(DeserializationError, orbit, probe->Event.Name, probe->Event.GetProvider());
result.AddFailedEventName(v.GetName());
} else {
ui64 timestamp = EpochNanosecondsToCycles(v.GetTimestampNanosec());
orbit.AddProbe(
probe,
params,
prev + (timestamp-prev)*timeScale + timeOffset);
probe->Event.Signature.DestroyParams(params);
prev = timestamp;
}
} else {
result.AddFailedEventName(v.GetName());
}
}
return result;
}
void TManager::CreateTraceResponse(TTraceResponse& msg, TOrbit& orbit)
{
orbit.Serialize(0, *msg.MutableTrace());
}
}
|