Skip to content

Commit

Permalink
src: add Env::profiler_idle_notifier_started()
Browse files Browse the repository at this point in the history
Refs: ayojs/ayo#93
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
  • Loading branch information
TimothyGu authored and addaleax committed May 22, 2018
1 parent 35c66d3 commit 00e079b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ inline Environment* Environment::GetThreadLocalEnv() {
return static_cast<Environment*>(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_;
}
Expand Down
6 changes: 6 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,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_data()->GetCpuProfiler()->SetIdle(true);
Expand All @@ -266,6 +271,7 @@ void Environment::StartProfilerIdleNotifier() {
}

void Environment::StopProfilerIdleNotifier() {
profiler_idle_notifier_started_ = false;
uv_prepare_stop(&idle_prepare_handle_);
uv_check_stop(&idle_check_handle_);
}
Expand Down
2 changes: 2 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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;
Expand Down Expand Up @@ -816,6 +817,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_;
Expand Down

0 comments on commit 00e079b

Please sign in to comment.