@@ -304,13 +304,11 @@ bool isIdleSample(const CpuProfileNode* sample) {
304304LabelSetsByNode WallProfiler::GetLabelSetsByNode (CpuProfile* profile) {
305305 LabelSetsByNode labelSetsByNode;
306306
307- if (contexts.empty () || profile->GetSamplesCount () == 0 ) {
307+ auto sampleCount = profile->GetSamplesCount ();
308+ if (contexts.empty () || sampleCount == 0 ) {
308309 return labelSetsByNode;
309310 }
310311 auto isolate = Isolate::GetCurrent ();
311- SampleContext sampleContext = contexts.pop_front ();
312-
313- auto sampleCount = profile->GetSamplesCount ();
314312
315313 for (int i = 0 ; i < sampleCount; i++) {
316314 auto sample = profile->GetSample (i);
@@ -324,12 +322,13 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile) {
324322 // to it in time, and stop as soon as it sees a context that's too recent
325323 // for this sample.
326324 for (;;) {
325+ auto & sampleContext = contexts.front ();
327326 if (sampleContext.time_to < sampleTimestamp) {
328327 // Current sample context is too old, discard it and fetch the next one.
328+ contexts.pop_front ();
329329 if (contexts.empty ()) {
330330 return labelSetsByNode;
331331 }
332- sampleContext = contexts.pop_front ();
333332 } else if (sampleContext.time_from > sampleTimestamp) {
334333 // Current sample context is too recent, we'll try to match it to the
335334 // next sample.
@@ -349,17 +348,14 @@ LabelSetsByNode WallProfiler::GetLabelSetsByNode(CpuProfile* profile) {
349348 array, array->Length (), sampleContext.labels .get ()->Get (isolate));
350349 }
351350 // Sample context was consumed, fetch the next one
351+ contexts.pop_front ();
352352 if (contexts.empty ()) {
353353 return labelSetsByNode;
354354 }
355- sampleContext = contexts.pop_front ();
356355 break ; // don't match more than one context to one sample
357356 }
358357 }
359358 }
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));
363359 return labelSetsByNode;
364360}
365361
0 commit comments