@@ -155,31 +155,7 @@ TTraceContextPtr SwapTraceContext(TTraceContextPtr newContext, TSourceLocation l
155
155
return oldContext;
156
156
}
157
157
158
- void OnContextSwitchOut ()
159
- {
160
- if (auto * context = TryGetCurrentTraceContext ()) {
161
- auto & traceContextTimingCheckpoint = TraceContextTimingCheckpoint ();
162
- auto now = GetApproximateCpuInstant ();
163
- context->IncrementElapsedCpuTime (now - traceContextTimingCheckpoint);
164
- SetCurrentTraceContext (nullptr );
165
- traceContextTimingCheckpoint = 0 ;
166
- }
167
- }
168
-
169
- void OnContextSwitchIn ()
170
- {
171
- if (auto * context = TryGetTraceContextFromPropagatingStorage (GetCurrentPropagatingStorage ())) {
172
- SetCurrentTraceContext (context);
173
- TraceContextTimingCheckpoint () = GetApproximateCpuInstant ();
174
- } else {
175
- SetCurrentTraceContext (nullptr );
176
- TraceContextTimingCheckpoint () = 0 ;
177
- }
178
- }
179
-
180
- void OnPropagatingStorageSwitch (
181
- const TPropagatingStorage& oldStorage,
182
- const TPropagatingStorage& newStorage)
158
+ void OnPropagatingStorageBeforeSwitch (const TPropagatingStorage& oldStorage)
183
159
{
184
160
TCpuInstant now = 0 ;
185
161
auto & traceContextTimingCheckpoint = TraceContextTimingCheckpoint ();
@@ -190,6 +166,12 @@ void OnPropagatingStorageSwitch(
190
166
now = GetApproximateCpuInstant ();
191
167
oldContext->IncrementElapsedCpuTime (now - traceContextTimingCheckpoint);
192
168
}
169
+ }
170
+
171
+ void OnPropagatingStorageAfterSwitch (const TPropagatingStorage& newStorage)
172
+ {
173
+ TCpuInstant now = 0 ;
174
+ auto & traceContextTimingCheckpoint = TraceContextTimingCheckpoint ();
193
175
194
176
if (auto * newContext = TryGetTraceContextFromPropagatingStorage (newStorage)) {
195
177
SetCurrentTraceContext (newContext);
@@ -203,6 +185,24 @@ void OnPropagatingStorageSwitch(
203
185
}
204
186
}
205
187
188
+ void OnPropagatingStorageSwitch (
189
+ const TPropagatingStorage& oldStorage,
190
+ const TPropagatingStorage& newStorage)
191
+ {
192
+ OnPropagatingStorageBeforeSwitch (oldStorage);
193
+ OnPropagatingStorageAfterSwitch (newStorage);
194
+ }
195
+
196
+ void OnContextSwitchOut ()
197
+ {
198
+ OnPropagatingStorageBeforeSwitch (GetCurrentPropagatingStorage ());
199
+ }
200
+
201
+ void OnContextSwitchIn ()
202
+ {
203
+ OnPropagatingStorageAfterSwitch (GetCurrentPropagatingStorage ());
204
+ }
205
+
206
206
void InitializeTraceContexts ()
207
207
{
208
208
static std::once_flag Initialized;
0 commit comments