forked from bnoordhuis/node-profiler
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprofiler.cc
65 lines (51 loc) · 2.17 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <v8.h>
#include <node.h>
using namespace v8;
using namespace node;
namespace {
struct ProfilerArguments {
const int flags;
const int tag;
inline ProfilerArguments(const Arguments& args)
: flags (args.Length() >= 1 ? args[0]->Uint32Value() : -1)
, tag (args.Length() >= 2 ? args[1]->Uint32Value() : 0)
{
}
};
static Handle<Value> GC(const Arguments& args) {
HandleScope scope;
while (!V8::IdleNotification());
return Undefined();
}
static Handle<Value> Resume(const Arguments& args) {
HandleScope scope;
const ProfilerArguments pa(args);
V8::ResumeProfilerEx(pa.flags, pa.tag);
return Undefined();
}
static Handle<Value> Pause(const Arguments& args) {
HandleScope scope;
const ProfilerArguments pa(args);
V8::PauseProfilerEx(pa.flags, pa.tag);
return Undefined();
}
static Handle<Value> HeapSize(Local<String> property, const AccessorInfo& info) {
return ThrowException(Exception::Error(String::New("profiler.heapSize is deprecated, use process.memoryUsage().heapTotal instead.")));
}
static Handle<Value> HeapUsed(Local<String> property, const AccessorInfo& info) {
return ThrowException(Exception::Error(String::New("profiler.heapUsed is deprecated, use process.memoryUsage().heapUsed instead.")));
}
extern "C" 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());
target->SetAccessor(String::New("heapSize"), HeapSize, 0, Undefined(), DEFAULT, DontEnum);
target->SetAccessor(String::New("heapUsed"), HeapUsed, 0, Undefined(), DEFAULT, DontEnum);
const PropertyAttribute attribs = (PropertyAttribute) (ReadOnly | DontDelete);
target->Set(String::New("CPU"), Integer::New(PROFILER_MODULE_CPU), attribs);
target->Set(String::New("HEAP_STATS"), Integer::New(PROFILER_MODULE_HEAP_STATS), attribs);
target->Set(String::New("HEAP_SNAPSHOT"), Integer::New(PROFILER_MODULE_HEAP_SNAPSHOT), attribs);
target->Set(String::New("JS_CONSTRUCTORS"), Integer::New(PROFILER_MODULE_JS_CONSTRUCTORS), attribs);
}
}