Skip to content

Commit 630d700

Browse files
committed
Don't use RingBuffer.push_front
1 parent dc71490 commit 630d700

File tree

2 files changed

+8
-30
lines changed

2 files changed

+8
-30
lines changed

bindings/buffer.hh

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace dd {
44
template <class T>
55
class RingBuffer {
66
public:
7-
explicit RingBuffer(size_t size)
8-
: buffer(std::make_unique<T[]>(size)),
9-
capacity_(size),
7+
explicit RingBuffer(size_t capacity)
8+
: buffer(std::make_unique<T[]>(capacity)),
9+
capacity_(capacity),
1010
size_(0),
1111
back_index_(0),
1212
front_index_(0) {}
@@ -37,24 +37,6 @@ class RingBuffer {
3737
}
3838
}
3939

40-
template <typename T2>
41-
void push_front(T2&& t) {
42-
if (full()) {
43-
if (empty()) {
44-
return;
45-
}
46-
// overwrite buffer head
47-
decrement(front_index_);
48-
buffer[front_index_] = std::forward<T2>(t);
49-
// move buffer head
50-
back_index_ = front_index_;
51-
} else {
52-
decrement(front_index_);
53-
buffer[front_index_] = std::forward<T2>(t);
54-
++size_;
55-
}
56-
}
57-
5840
T pop_front() {
5941
auto idx = front_index_;
6042
increment(front_index_);

bindings/profilers/wall.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,11 @@ bool isIdleSample(const CpuProfileNode* sample) {
304304
LabelSetsByNode 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

Comments
 (0)