perf_hooks: make GC tracking state per-Environment
Otherwise this is global state that may be subject to race conditions e.g. when running `perf_hooks` inside of Worker threads. Tracking the GC type is removed entirely since the variable was unused. PR-URL: https://github.com/nodejs/node/pull/25053 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
cc0e1770d9
commit
8dfd757337
@ -42,9 +42,6 @@ const double timeOriginTimestamp = GetCurrentTimeInMicroseconds();
|
|||||||
uint64_t performance_node_start;
|
uint64_t performance_node_start;
|
||||||
uint64_t performance_v8_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,
|
void performance_state::Mark(enum PerformanceMilestone milestone,
|
||||||
uint64_t ts) {
|
uint64_t ts) {
|
||||||
this->milestones[milestone] = ts;
|
this->milestones[milestone] = ts;
|
||||||
@ -268,9 +265,10 @@ void PerformanceGCCallback(Environment* env, void* ptr) {
|
|||||||
// Marks the start of a GC cycle
|
// Marks the start of a GC cycle
|
||||||
void MarkGarbageCollectionStart(Isolate* isolate,
|
void MarkGarbageCollectionStart(Isolate* isolate,
|
||||||
GCType type,
|
GCType type,
|
||||||
GCCallbackFlags flags) {
|
GCCallbackFlags flags,
|
||||||
performance_last_gc_start_mark_ = PERFORMANCE_NOW();
|
void* data) {
|
||||||
performance_last_gc_type_ = type;
|
Environment* env = static_cast<Environment*>(data);
|
||||||
|
env->performance_state()->performance_last_gc_start_mark = PERFORMANCE_NOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marks the end of a GC cycle
|
// Marks the end of a GC cycle
|
||||||
@ -279,13 +277,14 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
|
|||||||
GCCallbackFlags flags,
|
GCCallbackFlags flags,
|
||||||
void* data) {
|
void* data) {
|
||||||
Environment* env = static_cast<Environment*>(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 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;
|
return;
|
||||||
GCPerformanceEntry* entry =
|
GCPerformanceEntry* entry =
|
||||||
new GCPerformanceEntry(env,
|
new GCPerformanceEntry(env,
|
||||||
static_cast<PerformanceGCKind>(type),
|
static_cast<PerformanceGCKind>(type),
|
||||||
performance_last_gc_start_mark_,
|
state->performance_last_gc_start_mark,
|
||||||
PERFORMANCE_NOW());
|
PERFORMANCE_NOW());
|
||||||
env->SetUnrefImmediate(PerformanceGCCallback,
|
env->SetUnrefImmediate(PerformanceGCCallback,
|
||||||
entry);
|
entry);
|
||||||
@ -293,7 +292,8 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
|
|||||||
|
|
||||||
|
|
||||||
inline void SetupGarbageCollectionTracking(Environment* env) {
|
inline void SetupGarbageCollectionTracking(Environment* env) {
|
||||||
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart);
|
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
|
||||||
|
static_cast<void*>(env));
|
||||||
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
|
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
|
||||||
static_cast<void*>(env));
|
static_cast<void*>(env));
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,8 @@ class performance_state {
|
|||||||
AliasedBuffer<double, v8::Float64Array> milestones;
|
AliasedBuffer<double, v8::Float64Array> milestones;
|
||||||
AliasedBuffer<uint32_t, v8::Uint32Array> observers;
|
AliasedBuffer<uint32_t, v8::Uint32Array> observers;
|
||||||
|
|
||||||
|
uint64_t performance_last_gc_start_mark = 0;
|
||||||
|
|
||||||
void Mark(enum PerformanceMilestone milestone,
|
void Mark(enum PerformanceMilestone milestone,
|
||||||
uint64_t ts = PERFORMANCE_NOW());
|
uint64_t ts = PERFORMANCE_NOW());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user