Skip to content

Commit 6e6b503

Browse files
committed
perf_hooks: rename internal ELDHistogram to IterationHistogram
The C++ class `ELDHistogram` is the per-iteration sampling implementation that sits next to `IntervalHistogram` (the timer-based one). Its name collided with the JS exposed `ELDHistogram` class that `monitorEventLoopDelay()` returns regardless of sampling mode, making the layering confusing: "ELDHistogram" was both the generic JS concept and the name of one specific C++ backing.
1 parent 26b7684 commit 6e6b503

5 files changed

Lines changed: 47 additions & 45 deletions

File tree

src/env_properties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434
V(http2ping_constructor_template, v8::ObjectTemplate) \
435435
V(i18n_converter_template, v8::ObjectTemplate) \
436436
V(intervalhistogram_constructor_template, v8::FunctionTemplate) \
437-
V(eldhistogram_constructor_template, v8::FunctionTemplate) \
437+
V(iterationhistogram_constructor_template, v8::FunctionTemplate) \
438438
V(iter_template, v8::DictionaryTemplate) \
439439
V(js_transferable_constructor_template, v8::FunctionTemplate) \
440440
V(libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \

src/histogram.cc

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ CFunction IntervalHistogram::fast_start_(
6868
CFunction::Make(&IntervalHistogram::FastStart));
6969
CFunction IntervalHistogram::fast_stop_(
7070
CFunction::Make(&IntervalHistogram::FastStop));
71-
CFunction ELDHistogram::fast_start_(CFunction::Make(&ELDHistogram::FastStart));
72-
CFunction ELDHistogram::fast_stop_(CFunction::Make(&ELDHistogram::FastStop));
71+
CFunction IterationHistogram::fast_start_(
72+
CFunction::Make(&IterationHistogram::FastStart));
73+
CFunction IterationHistogram::fast_stop_(
74+
CFunction::Make(&IterationHistogram::FastStop));
7375

7476
void HistogramImpl::AddMethods(Isolate* isolate, Local<FunctionTemplate> tmpl) {
7577
// TODO(@jasnell): The bigint API variations do not yet support fast
@@ -446,24 +448,24 @@ void IntervalHistogram::FastStop(Local<Value> receiver) {
446448
histogram->OnStop();
447449
}
448450

449-
Local<FunctionTemplate> ELDHistogram::GetConstructorTemplate(Environment* env) {
450-
Local<FunctionTemplate> tmpl = env->eldhistogram_constructor_template();
451+
Local<FunctionTemplate> IterationHistogram::GetConstructorTemplate(Environment* env) {
452+
Local<FunctionTemplate> tmpl = env->iterationhistogram_constructor_template();
451453
if (tmpl.IsEmpty()) {
452454
Isolate* isolate = env->isolate();
453455
tmpl = NewFunctionTemplate(isolate, nullptr);
454456
tmpl->Inherit(HandleWrap::GetConstructorTemplate(env));
455457
tmpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "Histogram"));
456458
auto instance = tmpl->InstanceTemplate();
457-
instance->SetInternalFieldCount(ELDHistogram::kInternalFieldCount);
459+
instance->SetInternalFieldCount(IterationHistogram::kInternalFieldCount);
458460
HistogramImpl::AddMethods(isolate, tmpl);
459461
SetFastMethod(isolate, instance, "start", Start, &fast_start_);
460462
SetFastMethod(isolate, instance, "stop", Stop, &fast_stop_);
461-
env->set_eldhistogram_constructor_template(tmpl);
463+
env->set_iterationhistogram_constructor_template(tmpl);
462464
}
463465
return tmpl;
464466
}
465467

466-
void ELDHistogram::RegisterExternalReferences(
468+
void IterationHistogram::RegisterExternalReferences(
467469
ExternalReferenceRegistry* registry) {
468470
registry->Register(Start);
469471
registry->Register(Stop);
@@ -472,10 +474,10 @@ void ELDHistogram::RegisterExternalReferences(
472474
HistogramImpl::RegisterExternalReferences(registry);
473475
}
474476

475-
ELDHistogram::ELDHistogram(Environment* env,
476-
Local<Object> wrap,
477-
AsyncWrap::ProviderType type,
478-
const Histogram::Options& options)
477+
IterationHistogram::IterationHistogram(Environment* env,
478+
Local<Object> wrap,
479+
AsyncWrap::ProviderType type,
480+
const Histogram::Options& options)
479481
: HandleWrap(
480482
env, wrap, reinterpret_cast<uv_handle_t*>(&check_handle_), type),
481483
HistogramImpl(options) {
@@ -491,7 +493,7 @@ ELDHistogram::ELDHistogram(Environment* env,
491493
prepare_handle_.data = this;
492494
}
493495

494-
BaseObjectPtr<ELDHistogram> ELDHistogram::Create(
496+
BaseObjectPtr<IterationHistogram> IterationHistogram::Create(
495497
Environment* env, const Histogram::Options& options) {
496498
Local<Object> obj;
497499
if (!GetConstructorTemplate(env)
@@ -501,19 +503,19 @@ BaseObjectPtr<ELDHistogram> ELDHistogram::Create(
501503
return nullptr;
502504
}
503505

504-
return MakeBaseObject<ELDHistogram>(
506+
return MakeBaseObject<IterationHistogram>(
505507
env, obj, AsyncWrap::PROVIDER_ELDHISTOGRAM, options);
506508
}
507509

508-
void ELDHistogram::PrepareCB(uv_prepare_t* handle) {
509-
ELDHistogram* self = static_cast<ELDHistogram*>(handle->data);
510+
void IterationHistogram::PrepareCB(uv_prepare_t* handle) {
511+
IterationHistogram* self = static_cast<IterationHistogram*>(handle->data);
510512
if (!self->enabled_) return;
511513
self->prepare_time_ = uv_hrtime();
512514
self->timeout_ = uv_backend_timeout(handle->loop);
513515
}
514516

515-
void ELDHistogram::CheckCB(uv_check_t* handle) {
516-
ELDHistogram* self = ContainerOf(&ELDHistogram::check_handle_, handle);
517+
void IterationHistogram::CheckCB(uv_check_t* handle) {
518+
IterationHistogram* self = ContainerOf(&IterationHistogram::check_handle_, handle);
517519
if (!self->enabled_) return;
518520

519521
uint64_t check_time = uv_hrtime();
@@ -531,11 +533,11 @@ void ELDHistogram::CheckCB(uv_check_t* handle) {
531533
self->check_time_ = check_time;
532534
}
533535

534-
void ELDHistogram::MemoryInfo(MemoryTracker* tracker) const {
536+
void IterationHistogram::MemoryInfo(MemoryTracker* tracker) const {
535537
tracker->TrackField("histogram", histogram());
536538
}
537539

538-
void ELDHistogram::OnStart(StartFlags flags) {
540+
void IterationHistogram::OnStart(StartFlags flags) {
539541
if (enabled_ || IsHandleClosing()) return;
540542
enabled_ = true;
541543
if (flags == StartFlags::RESET) histogram()->Reset();
@@ -548,42 +550,42 @@ void ELDHistogram::OnStart(StartFlags flags) {
548550
uv_unref(reinterpret_cast<uv_handle_t*>(&prepare_handle_));
549551
}
550552

551-
void ELDHistogram::OnStop() {
553+
void IterationHistogram::OnStop() {
552554
if (!enabled_ || IsHandleClosing()) return;
553555
enabled_ = false;
554556
uv_check_stop(&check_handle_);
555557
uv_prepare_stop(&prepare_handle_);
556558
}
557559

558-
void ELDHistogram::Close(Local<Value> close_callback) {
560+
void IterationHistogram::Close(Local<Value> close_callback) {
559561
if (IsHandleClosing()) return;
560562
OnStop();
561563
HandleWrap::Close(close_callback);
562564
uv_close(reinterpret_cast<uv_handle_t*>(&prepare_handle_), nullptr);
563565
}
564566

565-
void ELDHistogram::Start(const FunctionCallbackInfo<Value>& args) {
566-
ELDHistogram* histogram;
567+
void IterationHistogram::Start(const FunctionCallbackInfo<Value>& args) {
568+
IterationHistogram* histogram;
567569
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.This());
568570
histogram->OnStart(args[0]->IsTrue() ? StartFlags::RESET : StartFlags::NONE);
569571
}
570572

571-
void ELDHistogram::FastStart(Local<Value> receiver, bool reset) {
573+
void IterationHistogram::FastStart(Local<Value> receiver, bool reset) {
572574
TRACK_V8_FAST_API_CALL("histogram.eventLoopDelay.start");
573-
ELDHistogram* histogram;
575+
IterationHistogram* histogram;
574576
ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver);
575577
histogram->OnStart(reset ? StartFlags::RESET : StartFlags::NONE);
576578
}
577579

578-
void ELDHistogram::Stop(const FunctionCallbackInfo<Value>& args) {
579-
ELDHistogram* histogram;
580+
void IterationHistogram::Stop(const FunctionCallbackInfo<Value>& args) {
581+
IterationHistogram* histogram;
580582
ASSIGN_OR_RETURN_UNWRAP(&histogram, args.This());
581583
histogram->OnStop();
582584
}
583585

584-
void ELDHistogram::FastStop(Local<Value> receiver) {
586+
void IterationHistogram::FastStop(Local<Value> receiver) {
585587
TRACK_V8_FAST_API_CALL("histogram.eventLoopDelay.stop");
586-
ELDHistogram* histogram;
588+
IterationHistogram* histogram;
587589
ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver);
588590
histogram->OnStop();
589591
}
@@ -751,7 +753,7 @@ HistogramImpl* HistogramImpl::FromJSObject(Local<Value> value) {
751753
HistogramImpl::kImplField, EmbedderDataTag::kDefault));
752754
}
753755

754-
std::unique_ptr<worker::TransferData> ELDHistogram::CloneForMessaging() const {
756+
std::unique_ptr<worker::TransferData> IterationHistogram::CloneForMessaging() const {
755757
return std::make_unique<HistogramBase::HistogramTransferData>(histogram());
756758
}
757759

src/histogram.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class IntervalHistogram final : public HandleWrap, public HistogramImpl {
266266
static v8::CFunction fast_stop_;
267267
};
268268

269-
class ELDHistogram final : public HandleWrap, public HistogramImpl {
269+
class IterationHistogram final : public HandleWrap, public HistogramImpl {
270270
public:
271271
enum InternalFields {
272272
kInternalFieldCount = std::max<uint32_t>(
@@ -280,13 +280,13 @@ class ELDHistogram final : public HandleWrap, public HistogramImpl {
280280
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
281281
Environment* env);
282282

283-
static BaseObjectPtr<ELDHistogram> Create(Environment* env,
284-
const Histogram::Options& options);
283+
static BaseObjectPtr<IterationHistogram> Create(
284+
Environment* env, const Histogram::Options& options);
285285

286-
ELDHistogram(Environment* env,
287-
v8::Local<v8::Object> wrap,
288-
AsyncWrap::ProviderType type,
289-
const Histogram::Options& options = Histogram::Options{});
286+
IterationHistogram(Environment* env,
287+
v8::Local<v8::Object> wrap,
288+
AsyncWrap::ProviderType type,
289+
const Histogram::Options& options = Histogram::Options{});
290290

291291
static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
292292
static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -303,8 +303,8 @@ class ELDHistogram final : public HandleWrap, public HistogramImpl {
303303
v8::Local<v8::Value> close_callback = v8::Local<v8::Value>()) override;
304304

305305
void MemoryInfo(MemoryTracker* tracker) const override;
306-
SET_MEMORY_INFO_NAME(ELDHistogram)
307-
SET_SELF_SIZE(ELDHistogram)
306+
SET_MEMORY_INFO_NAME(IterationHistogram)
307+
SET_SELF_SIZE(IterationHistogram)
308308

309309
private:
310310
static void PrepareCB(uv_prepare_t* handle);

src/node_perf.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void CreateELDHistogram(const FunctionCallbackInfo<Value>& args) {
283283
int64_t interval = args[0].As<Integer>()->Value();
284284
CHECK_GT(interval, 0);
285285
if (args[1]->IsTrue()) {
286-
BaseObjectPtr<ELDHistogram> histogram =
287-
ELDHistogram::Create(env, Histogram::Options{1});
286+
BaseObjectPtr<IterationHistogram> histogram =
287+
IterationHistogram::Create(env, Histogram::Options{1});
288288
args.GetReturnValue().Set(histogram->object());
289289
return;
290290
}
@@ -420,7 +420,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
420420
registry->Register(fast_performance_now);
421421
HistogramBase::RegisterExternalReferences(registry);
422422
IntervalHistogram::RegisterExternalReferences(registry);
423-
ELDHistogram::RegisterExternalReferences(registry);
423+
IterationHistogram::RegisterExternalReferences(registry);
424424
}
425425
} // namespace performance
426426
} // namespace node

test/sequential/test-performance-eventloopdelay.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ const { sleep } = require('internal/util');
153153
// enable()/disable() return values for ELDHistogram (samplePerIteration: true)
154154
const histogram = monitorEventLoopDelay({ samplePerIteration: true });
155155
assert.strictEqual(histogram.enable(), true);
156-
assert.strictEqual(histogram.enable(), false); // already enabled, no-op
156+
assert.strictEqual(histogram.enable(), false); // Already enabled, no-op
157157
assert.strictEqual(histogram.disable(), true);
158-
assert.strictEqual(histogram.disable(), false); // already disabled, no-op
158+
assert.strictEqual(histogram.disable(), false); // Already disabled, no-op
159159
// Re-enabling after disable should work
160160
assert.strictEqual(histogram.enable(), true);
161161
setTimeout(common.mustCall(() => {

0 commit comments

Comments
 (0)