Skip to content

Commit 483eea5

Browse files
ofrobots3y3
authored andcommitted
add ability to get lineTicks in cpu profile
1 parent 170e484 commit 483eea5

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/cpu_profile_node.cc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@ namespace nodex {
1212
using v8::Array;
1313

1414
uint32_t ProfileNode::UIDCounter = 1;
15+
16+
#if (NODE_MODULE_VERSION >= 42)
17+
static Handle<Value> GetLineTicks(const CpuProfileNode* node) {
18+
NanEscapableScope();
19+
20+
unsigned int count = node->GetHitLineCount();
21+
v8::CpuProfileNode::LineTick *entries = new v8::CpuProfileNode::LineTick[count];
22+
bool result = node->GetLineTicks(entries, count);
23+
24+
Local<Value> lineTicks;
25+
if (result) {
26+
Local<Array> array = NanNew<Array>(count);
27+
for (unsigned int index = 0; index < count; index++) {
28+
Local<Object> tick = NanNew<Object>();
29+
tick->Set(NanNew<String>("line"), NanNew<Integer>(entries[index].line));
30+
tick->Set(NanNew<String>("hitCount"), NanNew<Integer>(entries[index].hit_count));
31+
array->Set(index, tick);
32+
}
33+
lineTicks = array;
34+
} else {
35+
lineTicks = NanNull();
36+
}
37+
38+
delete[] entries;
39+
return NanEscapeScope(lineTicks);
40+
}
41+
#endif
1542

1643
Handle<Value> ProfileNode::New (const CpuProfileNode* node) {
1744
NanEscapableScope();
@@ -40,7 +67,15 @@ namespace nodex {
4067
profile_node->Set(NanNew<String>("hitCount"), NanNew(node->GetSelfSamplesCount()));
4168
#endif
4269
profile_node->Set(NanNew<String>("children"), children);
43-
70+
71+
#if (NODE_MODULE_VERSION >= 42)
72+
auto lineTicks = GetLineTicks(node);
73+
if (!lineTicks->IsNull()) {
74+
profile_node->Set(NanNew<String>("lineTicks"), lineTicks);
75+
}
76+
#endif
77+
4478
return NanEscapeScope(profile_node);
4579
}
80+
4681
}

0 commit comments

Comments
 (0)