Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix GetCpuProfiler() deprecation warning #18534

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/env.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "node_internals.h"
#include "async_wrap.h"
#include "v8-profiler.h"
#include "node_buffer.h"
#include "node_platform.h"

Expand Down Expand Up @@ -67,6 +66,15 @@ IsolateData::IsolateData(Isolate* isolate,
IsolateData::~IsolateData() {
if (platform_ != nullptr)
platform_->UnregisterIsolate(this);
if (cpu_profiler_ != nullptr)
cpu_profiler_->Dispose();
}

v8::CpuProfiler* IsolateData::GetCpuProfiler() {
if (cpu_profiler_ != nullptr) return cpu_profiler_;
cpu_profiler_ = v8::CpuProfiler::New(isolate());
CHECK_NE(cpu_profiler_, nullptr);
return cpu_profiler_;
}

void Environment::Start(int argc,
Expand Down Expand Up @@ -152,12 +160,12 @@ void Environment::CleanupHandles() {
void Environment::StartProfilerIdleNotifier() {
uv_prepare_start(&idle_prepare_handle_, [](uv_prepare_t* handle) {
Environment* env = ContainerOf(&Environment::idle_prepare_handle_, handle);
env->isolate()->GetCpuProfiler()->SetIdle(true);
env->isolate_data()->GetCpuProfiler()->SetIdle(true);
});

uv_check_start(&idle_check_handle_, [](uv_check_t* handle) {
Environment* env = ContainerOf(&Environment::idle_check_handle_, handle);
env->isolate()->GetCpuProfiler()->SetIdle(false);
env->isolate_data()->GetCpuProfiler()->SetIdle(false);
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "req_wrap.h"
#include "util.h"
#include "uv.h"
#include "v8-profiler.h"
#include "v8.h"
#include "node.h"
#include "node_http2_state.h"
Expand Down Expand Up @@ -333,6 +334,8 @@ class IsolateData {
std::unordered_map<nghttp2_rcbuf*, v8::Eternal<v8::String>> http2_static_strs;
inline v8::Isolate* isolate() const;

v8::CpuProfiler* GetCpuProfiler();

private:
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
#define VS(PropertyName, StringValue) V(v8::String, PropertyName)
Expand All @@ -348,6 +351,7 @@ class IsolateData {
uv_loop_t* const event_loop_;
uint32_t* const zero_fill_field_;
MultiIsolatePlatform* platform_;
v8::CpuProfiler* cpu_profiler_ = nullptr;

DISALLOW_COPY_AND_ASSIGN(IsolateData);
};
Expand Down