Skip to content

Commit

Permalink
chore: stop using deprecated GetCpuProfiler() in node 10 (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanmar511 authored and aalexand committed May 17, 2018
1 parent 41483df commit 3915027
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions bindings/time-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

using namespace v8;

#if NODE_MODULE_VERSION > NODE_8_0_MODULE_VERSION
// This profiler exists for the lifetime of the program. Not calling
// CpuProfiler::Dispose() is intentional.
CpuProfiler* cpuProfiler = CpuProfiler::New(v8::Isolate::GetCurrent());
#else
CpuProfiler* cpuProfiler = v8::Isolate::GetCurrent()->GetCpuProfiler();
#endif


Local<Value> TranslateTimeProfileNode(const CpuProfileNode* node) {
Local<Object> js_node = Nan::New<Object>();
js_node->Set(Nan::New<String>("name").ToLocalChecked(),
Expand Down Expand Up @@ -61,26 +70,26 @@ NAN_METHOD(StartProfiling) {

// Sample counts and timestamps are not used, so we do not need to record
// samples.
info.GetIsolate()->GetCpuProfiler()->StartProfiling(name, false);
cpuProfiler->StartProfiling(name, false);
}

NAN_METHOD(StopProfiling) {
Local<String> name = info[0].As<String>();
CpuProfile* profile =
info.GetIsolate()->GetCpuProfiler()->StopProfiling(name);
cpuProfiler->StopProfiling(name);
Local<Value> translated_profile = TranslateTimeProfile(profile);
profile->Delete();
info.GetReturnValue().Set(translated_profile);
}

NAN_METHOD(SetSamplingInterval) {
int us = info[0].As<Integer>()->IntegerValue();
info.GetIsolate()->GetCpuProfiler()->SetSamplingInterval(us);
cpuProfiler->SetSamplingInterval(us);
}

NAN_METHOD(SetIdle) {
bool is_idle = info[0].As<Boolean>()->BooleanValue();
info.GetIsolate()->GetCpuProfiler()->SetIdle(is_idle);
cpuProfiler->SetIdle(is_idle);
}

NAN_MODULE_INIT(InitAll) {
Expand Down

0 comments on commit 3915027

Please sign in to comment.