Permalink
Browse files

Prepare to v5.0.0

Now compatible with NodeJS v0.11.13
Added prefixes for cpu and heap files
  (profile.cc -> cpu_profile.cc)
Added Heap_Graph API
Updated Nan dependence to 1.2.0
Rewrited HEAP getHeapStats
  (now receives iterator and callback functions)
Cleared JS API
  • Loading branch information...
3y3 committed Jun 5, 2014
1 parent f47b6c5 commit 77b814d1b813e85028613ba5c036fc80694c89db
View
@@ -3,16 +3,19 @@
{
'target_name': 'profiler',
'sources': [
+ 'src/profiler.cc',
'src/cpu_profiler.cc',
+ 'src/cpu_profile.cc',
+ 'src/cpu_profile_node.cc',
'src/heap_profiler.cc',
- 'src/profile.cc',
- 'src/profile_node.cc',
- 'src/profiler.cc',
- 'src/snapshot.cc',
+ 'src/heap_snapshot.cc',
+ 'src/heap_output_stream.cc',
+ 'src/heap_graph_node.cc',
+ 'src/heap_graph_edge.cc'
],
'include_dirs' : [
"<!(node -e \"require('nan')\")"
- ],
+ ]
}
]
}
View
@@ -20,6 +20,6 @@
"postinstall": "ln -sf build/Release/profiler.node profiler.node"
},
"dependencies": {
- "nan": "~0.8.0"
+ "nan": "~1.2.0"
}
}
View
@@ -0,0 +1,105 @@
+#include "cpu_profile.h"
+#include "cpu_profile_node.h"
+
+namespace nodex {
+ using v8::Array;
+ using v8::CpuProfile;
+ using v8::CpuProfileNode;
+ using v8::Handle;
+ using v8::Number;
+ using v8::Integer;
+ using v8::Local;
+ using v8::Object;
+ using v8::ObjectTemplate;
+ using v8::Persistent;
+ using v8::String;
+ using v8::Function;
+ using v8::Value;
+
+ Persistent<ObjectTemplate> Profile::profile_template_;
+ Persistent<Array> Profile::profiles;
+ uint32_t Profile::uid_counter = 0;
+
+ void Profile::Initialize () {
+ NanScope();
+
+ Local<ObjectTemplate> o = NanNew<ObjectTemplate>();
+ o->SetInternalFieldCount(1);
+ NODE_SET_METHOD(o, "delete", Profile::Delete);
+ NanAssignPersistent(profile_template_, o);
+ }
+
+ NAN_METHOD(Profile::Delete) {
+ NanScope();
+
+ Handle<Object> self = args.This();
+ void* ptr = NanGetInternalFieldPointer(self, 0);
+ Local<Array> profiles = NanNew<Array>(Profile::profiles);
+
+ uint32_t count = profiles->Length();
+ for (uint32_t index = 0; index < count; index++) {
+ if (profiles->Get(index) == args.This()) {
+ Local<Value> argv[2] = {
+ NanNew<Integer>(index),
+ NanNew<Integer>(1)
+ };
+ Handle<Function>::Cast(profiles->Get(NanNew<String>("splice")))->Call(profiles, 2, argv);
+ break;
+ }
+ }
+ static_cast<CpuProfile*>(ptr)->Delete();
+
+ NanReturnUndefined();
+ }
+
+ Handle<Value> Profile::New (const CpuProfile* node) {
+ NanEscapableScope();
+
+ if (profile_template_.IsEmpty()) {
+ Profile::Initialize();
+ }
+
+ uid_counter++;
+
+ Local<Object> profile = NanNew(profile_template_)->NewInstance();
+ NanSetInternalFieldPointer(profile, 0, const_cast<CpuProfile*>(node));
+
+ Local<Value> CPU = NanNew<String>("CPU");
+ Local<Value> uid = NanNew<Integer>(uid_counter);
+ Handle<String> title = node->GetTitle();
+ if (!title->Length()) {
+ char _title[32];
+ sprintf(_title, "Profile %i", uid_counter);
+ title = NanNew<String>(_title);
+ }
+ Handle<Value> head = ProfileNode::New(node->GetTopDownRoot());
+
+ profile->Set(NanNew<String>("typeId"), CPU);
+ profile->Set(NanNew<String>("uid"), uid);
+ profile->Set(NanNew<String>("title"), title);
+ profile->Set(NanNew<String>("head"), head);
+
+#if (NODE_MODULE_VERSION > 0x000B)
+ Local<Value> start_time = NanNew<Number>(node->GetStartTime()/1000000);
+ Local<Value> end_time = NanNew<Number>(node->GetEndTime()/1000000);
+ Local<Array> samples = NanNew<Array>();
+
+ uint32_t count = node->GetSamplesCount();
+ for (uint32_t index = 0; index < count; ++index) {
+ samples->Set(index, ProfileNode::New(node->GetSample(index)));
+ }
+
+ profile->Set(NanNew<String>("startTime"), start_time);
+ profile->Set(NanNew<String>("endTime"), end_time);
+ profile->Set(NanNew<String>("samples"), samples);
+#else
+ Handle<Value> bottom = ProfileNode::New(node->GetBottomUpRoot());
+ profile->Set(NanNew<String>("bottomRoot"), bottom);
+#endif
+
+ Local<Array> profiles = NanNew<Array>(Profile::profiles);
+ profiles->Set(profiles->Length(), profile);
+
+ return NanEscapeScope(profile);
+ }
+}
View
@@ -0,0 +1,21 @@
+#ifndef NODE_PROFILE_
+#define NODE_PROFILE_
+
+#include "v8-profiler.h"
+#include "nan.h"
+
+namespace nodex {
+
+ class Profile {
+ public:
+ static v8::Handle<v8::Value> New(const v8::CpuProfile* node);
+ static v8::Persistent<v8::Array> profiles;
+ private:
+ static NAN_METHOD(Delete);
+ static void Initialize();
+ static v8::Persistent<v8::ObjectTemplate> profile_template_;
+ static uint32_t uid_counter;
+ };
+
+} //namespace nodex
+#endif // NODE_PROFILE_
View
@@ -0,0 +1,44 @@
+#include "cpu_profile_node.h"
+
+namespace nodex {
+ using v8::CpuProfileNode;
+ using v8::Handle;
+ using v8::String;
+ using v8::Number;
+ using v8::Integer;
+ using v8::Value;
+ using v8::Local;
+ using v8::Object;
+ using v8::Array;
+
+ Handle<Value> ProfileNode::New (const CpuProfileNode* node) {
+ NanEscapableScope();
+
+ int32_t count = node->GetChildrenCount();
+ Local<Object> profile_node = NanNew<Object>();
+ Local<Array> children = NanNew<Array>(count);
+
+ for (int32_t index = 0; index < count; index++) {
+ children->Set(index, ProfileNode::New(node->GetChild(index)));
+ }
+
+ profile_node->Set(NanNew<String>("functionName"), NanNew<String>(node->GetFunctionName()));
+ profile_node->Set(NanNew<String>("url"), NanNew<String>(node->GetScriptResourceName()));
+ profile_node->Set(NanNew<String>("lineNumber"), NanNew<Integer>(node->GetLineNumber()));
+ profile_node->Set(NanNew<String>("callUID"), NanNew<Number>(node->GetCallUid()));
+#if (NODE_MODULE_VERSION > 0x000B)
+ profile_node->Set(NanNew<String>("bailoutReason"), NanNew<String>(node->GetBailoutReason()));
+ profile_node->Set(NanNew<String>("id"), NanNew<Integer>(node->GetNodeId()));
+ profile_node->Set(NanNew<String>("scriptId"), NanNew<Integer>(node->GetScriptId()));
+ profile_node->Set(NanNew<String>("hitCount"), NanNew<Integer>(node->GetHitCount()));
+#else
+ profile_node->Set(NanNew<String>("totalTime"), NanNew<Integer>(node->GetTotalTime()));
+ profile_node->Set(NanNew<String>("selfTime"), NanNew<Integer>(node->GetSelfTime()));
+ profile_node->Set(NanNew<String>("totalSamplesCount"), NanNew<Integer>(node->GetTotalSamplesCount()));
+ profile_node->Set(NanNew<String>("selfSamplesCount"), NanNew<Integer>(node->GetSelfSamplesCount()));
+#endif
+ profile_node->Set(NanNew<String>("children"), children);
+
+ return NanEscapeScope(profile_node);
+ }
+}
View
@@ -0,0 +1,15 @@
+#ifndef NODE_PROFILE_NODE_
+#define NODE_PROFILE_NODE_
+
+#include "v8-profiler.h"
+#include "nan.h"
+
+namespace nodex {
+
+class ProfileNode {
+ public:
+ static v8::Handle<v8::Value> New(const v8::CpuProfileNode* node);
+};
+
+}
+#endif // NODE_PROFILE_NODE_
Oops, something went wrong.

0 comments on commit 77b814d

Please sign in to comment.