-
Notifications
You must be signed in to change notification settings - Fork 93
/
stats.h
216 lines (197 loc) · 7.46 KB
/
stats.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef OTEL_CLR_PROFILER_STATS_H_
#define OTEL_CLR_PROFILER_STATS_H_
#include <chrono>
#include "util.h"
namespace trace
{
class SWStat
{
std::atomic_ullong* _value;
std::chrono::steady_clock::time_point _startTime;
public:
SWStat(std::atomic_ullong* value)
{
_value = value;
_startTime = std::chrono::steady_clock::now();
}
~SWStat()
{
Refresh();
}
void Refresh()
{
auto now = std::chrono::steady_clock::now();
auto increment = (now - _startTime).count();
_startTime = now;
_value->fetch_add(increment);
}
};
class Stats : public Singleton<Stats>
{
friend class Singleton<Stats>;
private:
std::atomic_ullong totalTime = {0};
std::unique_ptr<SWStat> totalTimeCounter = nullptr;
std::atomic_ullong initializeProfiler = {0};
std::atomic_ullong jitCachedFunctionSearchStarted = {0};
std::atomic_ullong callTargetRequestRejit = {0};
std::atomic_ullong callTargetRewriter = {0};
std::atomic_ullong jitInlining = {0};
std::atomic_ullong jitCompilationStarted = {0};
std::atomic_ullong moduleUnloadStarted = {0};
std::atomic_ullong moduleLoadFinished = {0};
std::atomic_ullong assemblyLoadFinished = {0};
std::atomic_ullong initialize = {0};
//
std::atomic_uint initializeProfilerCount = {0};
std::atomic_uint jitCachedFunctionSearchStartedCount = {0};
std::atomic_uint callTargetRequestRejitCount = {0};
std::atomic_uint callTargetRewriterCount = {0};
std::atomic_uint jitInliningCount = {0};
std::atomic_uint jitCompilationStartedCount = {0};
std::atomic_uint moduleUnloadStartedCount = {0};
std::atomic_uint moduleLoadFinishedCount = {0};
std::atomic_uint assemblyLoadFinishedCount = {0};
public:
Stats()
{
totalTime = 0;
totalTimeCounter = std::make_unique<SWStat>(&totalTime);
initializeProfiler = 0;
jitCachedFunctionSearchStarted = 0;
callTargetRequestRejit = 0;
jitInlining = 0;
jitCompilationStarted = 0;
moduleUnloadStarted = 0;
moduleLoadFinished = 0;
assemblyLoadFinished = 0;
initialize = 0;
initializeProfilerCount = 0;
jitCachedFunctionSearchStartedCount = 0;
callTargetRequestRejitCount = 0;
jitInliningCount = 0;
jitCompilationStartedCount = 0;
moduleUnloadStartedCount = 0;
moduleLoadFinishedCount = 0;
assemblyLoadFinishedCount = 0;
}
SWStat InitializeProfilerMeasure()
{
initializeProfilerCount++;
return SWStat(&initializeProfiler);
}
SWStat JITCachedFunctionSearchStartedMeasure()
{
jitCachedFunctionSearchStartedCount++;
return SWStat(&jitCachedFunctionSearchStarted);
}
SWStat CallTargetRequestRejitMeasure()
{
callTargetRequestRejitCount++;
return SWStat(&callTargetRequestRejit);
}
SWStat CallTargetRewriterCallbackMeasure()
{
callTargetRewriterCount++;
return SWStat(&callTargetRewriter);
}
SWStat JITInliningMeasure()
{
jitInliningCount++;
return SWStat(&jitInlining);
}
SWStat JITCompilationStartedMeasure()
{
jitCompilationStartedCount++;
return SWStat(&jitCompilationStarted);
}
SWStat ModuleUnloadStartedMeasure()
{
moduleUnloadStartedCount++;
return SWStat(&moduleUnloadStarted);
}
SWStat ModuleLoadFinishedMeasure()
{
moduleLoadFinishedCount++;
return SWStat(&moduleLoadFinished);
}
SWStat AssemblyLoadFinishedMeasure()
{
assemblyLoadFinishedCount++;
return SWStat(&assemblyLoadFinished);
}
SWStat InitializeMeasure()
{
return SWStat(&initialize);
}
std::string ToString()
{
const auto ns_initialize = initialize.load();
const auto ns_moduleLoadFinished = moduleLoadFinished.load();
const auto ns_callTargetRequestRejit = callTargetRequestRejit.load();
const auto ns_callTargetRewriter = callTargetRewriter.load();
const auto ns_assemblyLoadFinished = assemblyLoadFinished.load();
const auto ns_moduleUnloadStarted = moduleUnloadStarted.load();
const auto ns_jitCompilationStarted = jitCompilationStarted.load();
const auto ns_jitInlining = jitInlining.load();
const auto ns_jitCachedFunctionSearchStarted = jitCachedFunctionSearchStarted.load();
const auto ns_initializeProfiler = initializeProfiler.load();
const auto count_moduleLoadFinishedCount = moduleLoadFinishedCount.load();
const auto count_callTargetRequestRejitCount = callTargetRequestRejitCount.load();
const auto count_callTargetRewriterCount = callTargetRewriterCount.load();
const auto count_assemblyLoadFinishedCount = assemblyLoadFinishedCount.load();
const auto count_moduleUnloadStartedCount = moduleUnloadStartedCount.load();
const auto count_jitCompilationStartedCount = jitCompilationStartedCount.load();
const auto count_jitInliningCount = jitInliningCount.load();
const auto count_jitCachedFunctionSearchStartedCount = jitCachedFunctionSearchStartedCount.load();
const auto count_initializeProfilerCount = initializeProfilerCount.load();
const auto ns_total = ns_initialize + ns_moduleLoadFinished + ns_callTargetRequestRejit +
ns_callTargetRewriter + ns_assemblyLoadFinished + ns_moduleUnloadStarted +
ns_jitCompilationStarted + ns_jitInlining + ns_jitCachedFunctionSearchStarted +
ns_initializeProfiler;
totalTimeCounter->Refresh();
const auto ns_fromBeginToEndTotal = totalTime.load();
std::stringstream ss;
ss << "Total time: ";
ss << ns_fromBeginToEndTotal / 1000000 << "ms";
ss << " | Total time in Callbacks: ";
ss << ns_total / 1000000 << "ms ";
ss << "[Initialize=";
ss << ns_initialize / 1000000 << "ms";
ss << ", ModuleLoadFinished=";
ss << ns_moduleLoadFinished / 1000000 << "ms"
<< "/" << count_moduleLoadFinishedCount;
ss << ", CallTargetRequestRejit=";
ss << ns_callTargetRequestRejit / 1000000 << "ms"
<< "/" << count_callTargetRequestRejitCount;
ss << ", CallTargetRewriter=";
ss << ns_callTargetRewriter / 1000000 << "ms"
<< "/" << count_callTargetRewriterCount;
ss << ", AssemblyLoadFinished=";
ss << ns_assemblyLoadFinished / 1000000 << "ms"
<< "/" << count_assemblyLoadFinishedCount;
ss << ", ModuleUnloadStarted=";
ss << ns_moduleUnloadStarted / 1000000 << "ms"
<< "/" << count_moduleUnloadStartedCount;
ss << ", JitCompilationStarted=";
ss << ns_jitCompilationStarted / 1000000 << "ms"
<< "/" << count_jitCompilationStartedCount;
ss << ", JitInlining=";
ss << ns_jitInlining / 1000000 << "ms"
<< "/" << count_jitInliningCount;
ss << ", JitCacheFunctionSearchStarted=";
ss << ns_jitCachedFunctionSearchStarted / 1000000 << "ms"
<< "/" << count_jitCachedFunctionSearchStartedCount;
ss << ", InitializeProfiler=";
ss << ns_initializeProfiler / 1000000 << "ms"
<< "/" << count_initializeProfilerCount;
ss << "]";
return ss.str();
}
};
} // namespace trace
#endif // OTEL_CLR_PROFILER_STATS_H_