From 314b47d1cf4d229d52e8626740d2625810f2a615 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 25 Sep 2017 16:28:55 -0700 Subject: [PATCH] src: add Env::profiler_idle_notifier_started() Refs: https://github.com/ayojs/ayo/pull/93 Reviewed-By: Anna Henningsen Reviewed-By: Stephen Belanger PR-URL: https://github.com/nodejs/node/pull/20876 Reviewed-By: Gireesh Punathil Reviewed-By: Benjamin Gruenbaum Reviewed-By: Shingo Inoue Reviewed-By: Matteo Collina Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: John-David Dalton Reviewed-By: Gus Caplan --- src/env-inl.h | 4 ++++ src/env.cc | 6 ++++++ src/env.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/src/env-inl.h b/src/env-inl.h index aadb81271cf5d4..50328bd77c1a89 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -322,6 +322,10 @@ inline Environment* Environment::GetThreadLocalEnv() { return static_cast(uv_key_get(&thread_local_env)); } +inline bool Environment::profiler_idle_notifier_started() const { + return profiler_idle_notifier_started_; +} + inline v8::Isolate* Environment::isolate() const { return isolate_; } diff --git a/src/env.cc b/src/env.cc index cb514828d2cdc4..090b43968bf665 100644 --- a/src/env.cc +++ b/src/env.cc @@ -263,6 +263,11 @@ void Environment::CleanupHandles() { } void Environment::StartProfilerIdleNotifier() { + if (profiler_idle_notifier_started_) + return; + + profiler_idle_notifier_started_ = true; + uv_prepare_start(&idle_prepare_handle_, [](uv_prepare_t* handle) { Environment* env = ContainerOf(&Environment::idle_prepare_handle_, handle); env->isolate()->SetIdle(true); @@ -275,6 +280,7 @@ void Environment::StartProfilerIdleNotifier() { } void Environment::StopProfilerIdleNotifier() { + profiler_idle_notifier_started_ = false; uv_prepare_stop(&idle_prepare_handle_); uv_check_stop(&idle_check_handle_); } diff --git a/src/env.h b/src/env.h index f1e9ccaef268f0..cdb592732a4264 100644 --- a/src/env.h +++ b/src/env.h @@ -615,6 +615,7 @@ class Environment { void StartProfilerIdleNotifier(); void StopProfilerIdleNotifier(); + inline bool profiler_idle_notifier_started() const; inline v8::Isolate* isolate() const; inline tracing::Agent* tracing_agent() const; @@ -840,6 +841,7 @@ class Environment { uv_idle_t immediate_idle_handle_; uv_prepare_t idle_prepare_handle_; uv_check_t idle_check_handle_; + bool profiler_idle_notifier_started_ = false; AsyncHooks async_hooks_; ImmediateInfo immediate_info_;