-
Notifications
You must be signed in to change notification settings - Fork 30
/
profiler.cc
51 lines (37 loc) · 1.19 KB
/
profiler.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
#include "v8.h"
#include "node.h"
using namespace v8;
using namespace node;
namespace {
Handle<Value> GC(const Arguments& args) {
while (!V8::IdleNotification());
return Undefined();
}
Handle<Value> Resume(const Arguments& args) {
V8::ResumeProfiler();
return Undefined();
}
Handle<Value> Pause(const Arguments& args) {
V8::PauseProfiler();
return Undefined();
}
void Init(Handle<Object> target) {
HandleScope scope;
target->Set(String::New("gc"),
FunctionTemplate::New(GC)->GetFunction());
target->Set(String::New("pause"),
FunctionTemplate::New(Pause)->GetFunction());
target->Set(String::New("resume"),
FunctionTemplate::New(Resume)->GetFunction());
// mimic browser API
Local<Object> global = Context::GetCurrent()->Global();
Local<Value> console_v = global->Get(String::New("console"));
if (console_v.IsEmpty() || !console_v->IsObject()) return;
Local<Object> console = console_v->ToObject();
console->Set(String::New("profile"),
FunctionTemplate::New(Resume)->GetFunction());
console->Set(String::New("profileEnd"),
FunctionTemplate::New(Pause)->GetFunction());
}
NODE_MODULE(profiler, Init)
}