-
Notifications
You must be signed in to change notification settings - Fork 7
/
linux-perf.cc
65 lines (50 loc) · 1.6 KB
/
linux-perf.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <nan.h>
#include "linux-perf.h"
namespace node {
void LinuxPerf::Initialize(v8::Local<v8::Object> target) {
Nan::HandleScope scope;
auto className = Nan::New<v8::String>("LinuxPerf").ToLocalChecked();
v8::Local<v8::FunctionTemplate> t =
Nan::New<v8::FunctionTemplate>(LinuxPerf::New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(className);
Nan::SetPrototypeMethod(t, "start", LinuxPerf::Start);
Nan::SetPrototypeMethod(t, "stop", LinuxPerf::Stop);
Nan::Set(target, className, Nan::GetFunction(t).ToLocalChecked());
}
NAN_METHOD(LinuxPerf::New) {
Nan::HandleScope scope;
LinuxPerf *linuxPerf = new LinuxPerf();
linuxPerf->handler = nullptr;
linuxPerf->Wrap(info.This());
info.GetReturnValue().Set(info.This());
}
NAN_METHOD(LinuxPerf::Start) {
Nan::HandleScope scope;
LinuxPerf *linuxPerf = Nan::ObjectWrap::Unwrap<LinuxPerf>(info.Holder());
if (linuxPerf->handler == nullptr) {
linuxPerf->handler = new LinuxPerfHandler(info.GetIsolate());
linuxPerf->handler->Enable();
info.GetReturnValue().Set(true);
return;
}
info.GetReturnValue().Set(false);
}
NAN_METHOD(LinuxPerf::Stop) {
Nan::HandleScope scope;
LinuxPerf *linuxPerf = Nan::ObjectWrap::Unwrap<LinuxPerf>(info.Holder());
if (linuxPerf->handler != nullptr) {
linuxPerf->handler->Disable();
delete linuxPerf->handler;
linuxPerf->handler = nullptr;
info.GetReturnValue().Set(true);
return;
}
info.GetReturnValue().Set(false);
}
extern "C" void
init(v8::Local<v8::Object> target) {
LinuxPerf::Initialize(target);
}
NODE_MODULE(LiuxPerfBindings, init)
};