perf_hooks: fix gc elapsed time
PR-URL: https://github.com/nodejs/node/pull/44058 Refs: https://github.com/nodejs/node/issues/44046 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
37115034dd
commit
eb7f22a6b4
@ -116,7 +116,13 @@ void MarkGarbageCollectionStart(
|
|||||||
GCCallbackFlags flags,
|
GCCallbackFlags flags,
|
||||||
void* data) {
|
void* data) {
|
||||||
Environment* env = static_cast<Environment*>(data);
|
Environment* env = static_cast<Environment*>(data);
|
||||||
|
// Prevent gc callback from reentering with different type
|
||||||
|
// See https://github.com/nodejs/node/issues/44046
|
||||||
|
if (env->performance_state()->current_gc_type != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
env->performance_state()->performance_last_gc_start_mark = PERFORMANCE_NOW();
|
env->performance_state()->performance_last_gc_start_mark = PERFORMANCE_NOW();
|
||||||
|
env->performance_state()->current_gc_type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeLocal<Object> GCPerformanceEntryTraits::GetDetails(
|
MaybeLocal<Object> GCPerformanceEntryTraits::GetDetails(
|
||||||
@ -153,6 +159,10 @@ void MarkGarbageCollectionEnd(
|
|||||||
void* data) {
|
void* data) {
|
||||||
Environment* env = static_cast<Environment*>(data);
|
Environment* env = static_cast<Environment*>(data);
|
||||||
PerformanceState* state = env->performance_state();
|
PerformanceState* state = env->performance_state();
|
||||||
|
if (type != state->current_gc_type) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
env->performance_state()->current_gc_type = 0;
|
||||||
// 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 (LIKELY(!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]))
|
if (LIKELY(!state->observers[NODE_PERFORMANCE_ENTRY_TYPE_GC]))
|
||||||
return;
|
return;
|
||||||
@ -178,6 +188,8 @@ void MarkGarbageCollectionEnd(
|
|||||||
|
|
||||||
void GarbageCollectionCleanupHook(void* data) {
|
void GarbageCollectionCleanupHook(void* data) {
|
||||||
Environment* env = static_cast<Environment*>(data);
|
Environment* env = static_cast<Environment*>(data);
|
||||||
|
// Reset current_gc_type to 0
|
||||||
|
env->performance_state()->current_gc_type = 0;
|
||||||
env->isolate()->RemoveGCPrologueCallback(MarkGarbageCollectionStart, data);
|
env->isolate()->RemoveGCPrologueCallback(MarkGarbageCollectionStart, data);
|
||||||
env->isolate()->RemoveGCEpilogueCallback(MarkGarbageCollectionEnd, data);
|
env->isolate()->RemoveGCEpilogueCallback(MarkGarbageCollectionEnd, data);
|
||||||
}
|
}
|
||||||
@ -185,7 +197,8 @@ void GarbageCollectionCleanupHook(void* data) {
|
|||||||
static void InstallGarbageCollectionTracking(
|
static void InstallGarbageCollectionTracking(
|
||||||
const FunctionCallbackInfo<Value>& args) {
|
const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
|
// Reset current_gc_type to 0
|
||||||
|
env->performance_state()->current_gc_type = 0;
|
||||||
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
|
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
|
||||||
static_cast<void*>(env));
|
static_cast<void*>(env));
|
||||||
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
|
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
|
||||||
|
@ -71,6 +71,7 @@ class PerformanceState {
|
|||||||
AliasedUint32Array observers;
|
AliasedUint32Array observers;
|
||||||
|
|
||||||
uint64_t performance_last_gc_start_mark = 0;
|
uint64_t performance_last_gc_start_mark = 0;
|
||||||
|
uint16_t current_gc_type = 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