summaryrefslogtreecommitdiff
path: root/src/node_perf.cc
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-02-01 01:04:44 +0800
committerAnna Henningsen <anna@addaleax.net>2019-02-06 20:02:59 +0100
commit475c43c1b006e186036817c364dfc24a4d12c44f (patch)
treedbbc5df0bdc8e78c034be9402b62f23db64b776e /src/node_perf.cc
parentcc5de5a5cc08551c54a2c1c40c05aa934d2156eb (diff)
downloadnode-new-475c43c1b006e186036817c364dfc24a4d12c44f.tar.gz
perf_hooks: only enable GC tracking when it's requested
Previously a GC prologue callback and a GC epilogue callback are always unconditionally enabled during bootstrap when the `performance` binding is loaded, even when the user does not use the performance timeline API to enable GC tracking. This patch makes the callback addition conditional and only enables them when the user explicitly requests `observer.observe(['gc'])` to avoid the overhead. PR-URL: https://github.com/nodejs/node/pull/25853 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_perf.cc')
-rw-r--r--src/node_perf.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/node_perf.cc b/src/node_perf.cc
index cefd0ff26d..33dd1d2051 100644
--- a/src/node_perf.cc
+++ b/src/node_perf.cc
@@ -296,8 +296,10 @@ void MarkGarbageCollectionEnd(Isolate* isolate,
entry);
}
+static void SetupGarbageCollectionTracking(
+ const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
-inline void SetupGarbageCollectionTracking(Environment* env) {
env->isolate()->AddGCPrologueCallback(MarkGarbageCollectionStart,
static_cast<void*>(env));
env->isolate()->AddGCEpilogueCallback(MarkGarbageCollectionEnd,
@@ -416,6 +418,8 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "markMilestone", MarkMilestone);
env->SetMethod(target, "setupObservers", SetupPerformanceObservers);
env->SetMethod(target, "timerify", Timerify);
+ env->SetMethod(
+ target, "setupGarbageCollectionTracking", SetupGarbageCollectionTracking);
Local<Object> constants = Object::New(isolate);
@@ -452,8 +456,6 @@ void Initialize(Local<Object> target,
env->constants_string(),
constants,
attr).ToChecked();
-
- SetupGarbageCollectionTracking(env);
}
} // namespace performance