@@ -304,13 +304,11 @@ bool isIdleSample(const CpuProfileNode* sample) {
304
304
LabelSetsByNode WallProfiler::GetLabelSetsByNode (CpuProfile* profile) {
305
305
LabelSetsByNode labelSetsByNode;
306
306
307
- if (contexts.empty () || profile->GetSamplesCount () == 0 ) {
307
+ auto sampleCount = profile->GetSamplesCount ();
308
+ if (contexts.empty () || sampleCount == 0 ) {
308
309
return labelSetsByNode;
309
310
}
310
311
auto isolate = Isolate::GetCurrent ();
311
- SampleContext sampleContext = contexts.pop_front ();
312
-
313
- auto sampleCount = profile->GetSamplesCount ();
314
312
315
313
for (int i = 0 ; i < sampleCount; i++) {
316
314
auto sample = profile->GetSample (i);
@@ -324,12 +322,13 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile) {
324
322
// to it in time, and stop as soon as it sees a context that's too recent
325
323
// for this sample.
326
324
for (;;) {
325
+ auto & sampleContext = contexts.front ();
327
326
if (sampleContext.time_to < sampleTimestamp) {
328
327
// Current sample context is too old, discard it and fetch the next one.
328
+ contexts.pop_front ();
329
329
if (contexts.empty ()) {
330
330
return labelSetsByNode;
331
331
}
332
- sampleContext = contexts.pop_front ();
333
332
} else if (sampleContext.time_from > sampleTimestamp) {
334
333
// Current sample context is too recent, we'll try to match it to the
335
334
// next sample.
@@ -349,17 +348,14 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile) {
349
348
array, array->Length (), sampleContext.labels .get ()->Get (isolate));
350
349
}
351
350
// Sample context was consumed, fetch the next one
351
+ contexts.pop_front ();
352
352
if (contexts.empty ()) {
353
353
return labelSetsByNode;
354
354
}
355
- sampleContext = contexts.pop_front ();
356
355
break ; // don't match more than one context to one sample
357
356
}
358
357
}
359
358
}
360
- // Push the last popped sample context back into the ring to be used by the
361
- // next profile
362
- contexts.push_front (std::move (sampleContext));
363
359
return labelSetsByNode;
364
360
}
365
361
0 commit comments