Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: make GC tracking state per-Environment #25053

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ const double timeOriginTimestamp = GetCurrentTimeInMicroseconds();
uint64_t performance_node_start;
uint64_t performance_v8_start;

uint64_t performance_last_gc_start_mark_ = 0;
GCType performance_last_gc_type_ = GCType::kGCTypeAll;

void performance_state::Mark(enum PerformanceMilestone milestone,
uint64_t ts) {
this->milestones[milestone] = ts;
Expand Down Expand Up @@ -268,9 +265,10 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
// Marks the start of a GC cycle
void MarkGarbageCollectionStart(Isolate* isolate,
GCType type,
GCCallbackFlags flags) {
performance_last_gc_start_mark_ = PERFORMANCE_NOW();
performance_last_gc_type_ = type;
GCCallbackFlags flags,
void* data) {
Environment* env = static_cast<Environment*>(data);
env->performance_state()->performance_last_gc_start_mark = PERFORMANCE_NOW();
}

// Marks the end of a GC cycle
Expand All @@ -279,21 +277,23 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
GCCallbackFlags flags,
void* data) {
Environment* env = static_cast<Environment*>(data);
performance_state* state = env->performance_state();
// If no one is listening to gc performance entries, do not create them.
if (!env->performance_state()->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC])
if (!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC])
return;
GCPerformanceEntry* entry =
new GCPerformanceEntry(env,
static_cast<PerformanceGCKind>(type),
performance_last_gc_start_mark_,
state->performance_last_gc_start_mark,
PERFORMANCE_NOW());
env->SetUnrefImmediate(PerformanceGCCallback,
entry);
}


inline void SetupGarbageCollectionTracking(Environment* env) {
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart);
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
static_cast<void*>(env));
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
static_cast<void*>(env));
}
Expand Down
2 changes: 2 additions & 0 deletions src/node_perf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class performance_state {
AliasedBuffer<double, v8::Float64Array> milestones;
AliasedBuffer<uint32_t, v8::Uint32Array> observers;

uint64_t performance_last_gc_start_mark = 0;

void Mark(enum PerformanceMilestone milestone,
uint64_t ts = PERFORMANCE_NOW());

Expand Down