Skip to content

Commit

Permalink
bootstrap: support perf hooks in snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Jun 8, 2021
1 parent 1f109da commit f0a70fa
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
33 changes: 32 additions & 1 deletion src/histogram.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "histogram.h" // NOLINT(build/include_inline)
#include "histogram-inl.h"
#include "base_object-inl.h"
#include "histogram-inl.h"
#include "memory_tracker-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"

namespace node {

using v8::BigInt;
Expand Down Expand Up @@ -197,6 +199,21 @@ Local<FunctionTemplate> HistogramBase::GetConstructorTemplate(
return tmpl;
}

void HistogramBase::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(New);
registry->Register(GetExceeds);
registry->Register(GetMin);
registry->Register(GetMax);
registry->Register(GetMean);
registry->Register(GetStddev);
registry->Register(GetPercentile);
registry->Register(GetPercentiles);
registry->Register(DoReset);
registry->Register(Record);
registry->Register(RecordDelta);
}

void HistogramBase::Initialize(Environment* env, Local<Object> target) {
env->SetConstructorFunction(target, "Histogram", GetConstructorTemplate(env));
}
Expand Down Expand Up @@ -240,6 +257,20 @@ Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate(
return tmpl;
}

void IntervalHistogram::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(GetExceeds);
registry->Register(GetMin);
registry->Register(GetMax);
registry->Register(GetMean);
registry->Register(GetStddev);
registry->Register(GetPercentile);
registry->Register(GetPercentiles);
registry->Register(DoReset);
registry->Register(Start);
registry->Register(Stop);
}

IntervalHistogram::IntervalHistogram(
Environment* env,
Local<Object> wrap,
Expand Down
5 changes: 5 additions & 0 deletions src/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace node {

class ExternalReferenceRegistry;

constexpr int kDefaultHistogramFigures = 3;

class Histogram : public MemoryRetainer {
Expand Down Expand Up @@ -78,6 +80,7 @@ class HistogramBase : public BaseObject, public HistogramImpl {
static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
Environment* env);
static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

static BaseObjectPtr<HistogramBase> Create(
Environment* env,
Expand Down Expand Up @@ -154,6 +157,8 @@ class IntervalHistogram : public HandleWrap, public HistogramImpl {
RESET
};

static void RegisterExternalReferences(ExternalReferenceRegistry* registry);

static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
Environment* env);

Expand Down
1 change: 1 addition & 0 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ExternalReferenceRegistry {
V(heap_utils) \
V(messaging) \
V(native_module) \
V(performance) \
V(process_methods) \
V(process_object) \
V(task_queue) \
Expand Down
25 changes: 23 additions & 2 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "node_perf.h"
#include "aliased_buffer.h"
#include "env-inl.h"
#include "histogram-inl.h"
#include "memory_tracker-inl.h"
#include "node_internals.h"
#include "node_perf.h"
#include "node_buffer.h"
#include "node_external_reference.h"
#include "node_internals.h"
#include "node_process-inl.h"
#include "util-inl.h"

Expand Down Expand Up @@ -250,6 +251,12 @@ void ELDHistogram::Initialize(Environment* env, Local<Object> target) {
env->SetConstructorFunction(target, "ELDHistogram", tmpl);
}

void ELDHistogram::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(New);
IntervalHistogram::RegisterExternalReferences(registry);
}

ELDHistogram::ELDHistogram(
Environment* env,
Local<Object> wrap,
Expand Down Expand Up @@ -364,7 +371,21 @@ void Initialize(Local<Object> target,
ELDHistogram::Initialize(env, target);
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(MarkMilestone);
registry->Register(SetupPerformanceObservers);
registry->Register(InstallGarbageCollectionTracking);
registry->Register(RemoveGarbageCollectionTracking);
registry->Register(Notify);
registry->Register(LoopIdleTime);
registry->Register(GetTimeOrigin);
registry->Register(GetTimeOriginTimeStamp);
HistogramBase::RegisterExternalReferences(registry);
ELDHistogram::RegisterExternalReferences(registry);
}
} // namespace performance
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(performance, node::performance::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(performance,
node::performance::RegisterExternalReferences)
7 changes: 5 additions & 2 deletions src/node_perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include "node.h"
#include "node_perf_common.h"
#include "base_object-inl.h"
#include "histogram.h"
#include "node.h"
#include "node_internals.h"
#include "node_perf_common.h"

#include "v8.h"
#include "uv.h"
Expand All @@ -16,6 +17,7 @@
namespace node {

class Environment;
class ExternalReferenceRegistry;

namespace performance {

Expand Down Expand Up @@ -160,6 +162,7 @@ using GCPerformanceEntry = PerformanceEntry<GCPerformanceEntryTraits>;

class ELDHistogram : public IntervalHistogram {
public:
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static void Initialize(Environment* env, v8::Local<v8::Object> target);
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down

0 comments on commit f0a70fa

Please sign in to comment.