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_;