Skip to content
Browse files

Merges 3.6.2 branch

  • Loading branch information...
1 parent 7d29839 commit 307276f34e5dbf5f1d2cd6f536916768db17f46c @c4milo committed
Showing with 212 additions and 262 deletions.
  1. +7 −7 graph_edge.cc
  2. +10 −42 graph_node.cc
  3. +0 −3 graph_node.h
  4. +0 −74 graph_path.cc
  5. +0 −27 graph_path.h
  6. +3 −3 package.json
  7. +10 −1 profile.cc
  8. +2 −1 profile.h
  9. +22 −7 profiler.cc
  10. +45 −17 snapshot.cc
  11. +5 −2 snapshot.h
  12. +0 −50 snapshot_diff.cc
  13. +0 −25 snapshot_diff.h
  14. +108 −3 v8-profiler.js
View
14 graph_edge.cc
@@ -23,22 +23,22 @@ Handle<Value> GraphEdge::GetType(Local<String> property, const AccessorInfo& inf
int32_t type = static_cast<int32_t>(static_cast<HeapGraphEdge*>(ptr)->GetType());
Local<String> t;
switch(type) {
- case 0: //HeapGraphEdge::kContextVariable :
+ case HeapGraphEdge::kContextVariable :
t = String::New("ContextVariable");
break;
- case 1: //HeapGraphEdge::kElement :
+ case HeapGraphEdge::kElement :
t = String::New("Element");
break;
- case 2: //HeapGraphEdge::kProperty :
+ case HeapGraphEdge::kProperty :
t = String::New("Property");
break;
- case 3: //HeapGraphEdge::kInternal :
+ case HeapGraphEdge::kInternal :
t = String::New("Internal");
break;
- case 4: //HeapGraphEdge::kHidden :
+ case HeapGraphEdge::kHidden :
t = String::New("Hidden");
break;
- case 5: //HeapGraphEdge::kShortcut :
+ case HeapGraphEdge::kShortcut :
t = String::New("Shortcut");
break;
default:
@@ -88,4 +88,4 @@ Handle<Value> GraphEdge::New(const HeapGraphEdge* edge) {
return scope.Close(obj);
}
}
-}
+}
View
52 graph_node.cc
@@ -1,6 +1,5 @@
#include "graph_node.h"
#include "graph_edge.h"
-#include "graph_path.h"
using namespace v8;
@@ -15,16 +14,13 @@ void GraphNode::Initialize() {
node_template_->SetAccessor(String::New("name"), GraphNode::GetName);
node_template_->SetAccessor(String::New("id"), GraphNode::GetId);
node_template_->SetAccessor(String::New("ptr"), GraphNode::GetPtr);
- node_template_->SetAccessor(String::New("instancesCount"), GraphNode::GetInstancesCount);
node_template_->SetAccessor(String::New("childrenCount"), GraphNode::GetChildrenCount);
node_template_->SetAccessor(String::New("retainersCount"), GraphNode::GetRetainersCount);
node_template_->SetAccessor(String::New("size"), GraphNode::GetSize);
- node_template_->SetAccessor(String::New("retainingPathsCount"), GraphNode::GetRetainingPathsCount);
node_template_->SetAccessor(String::New("dominatorNode"), GraphNode::GetDominator);
node_template_->Set(String::New("getChild"), FunctionTemplate::New(GraphNode::GetChild));
node_template_->Set(String::New("retainedSize"), FunctionTemplate::New(GraphNode::GetRetainedSize));
node_template_->Set(String::New("getRetainer"), FunctionTemplate::New(GraphNode::GetRetainer));
- node_template_->Set(String::New("getRetainingPath"), FunctionTemplate::New(GraphNode::GetRetainingPath));
}
Handle<Value> GraphNode::GetType(Local<String> property, const AccessorInfo& info) {
@@ -34,27 +30,29 @@ Handle<Value> GraphNode::GetType(Local<String> property, const AccessorInfo& inf
int32_t type = static_cast<int32_t>(static_cast<HeapGraphNode*>(ptr)->GetType());
Local<String> t;
switch(type) {
- case 1: //HeapGraphNode::kArray :
+ case HeapGraphNode::kArray :
t = String::New("Array");
break;
- case 2: //HeapGraphNode::kString :
+ case HeapGraphNode::kString :
t = String::New("String");
break;
- case 3: //HeapGraphNode::kObject :
+ case HeapGraphNode::kObject :
t = String::New("Object");
break;
- case 4: //HeapGraphNode::kCode :
+ case HeapGraphNode::kCode :
t = String::New("Code");
break;
- case 5: //HeapGraphNode::kClosure :
+ case HeapGraphNode::kClosure :
t = String::New("Closure");
break;
- case 6: //HeapGraphNode::kRegExp :
+ case HeapGraphNode::kRegExp :
t = String::New("RegExp");
break;
- case 7: //HeapGraphNode::kHeapNumber :
+ case HeapGraphNode::kHeapNumber :
t = String::New("HeapNumber");
break;
+ case HeapGraphNode::kNative :
+ t = String::New("Native");
default:
t = String::New("Hidden");
break;
@@ -86,14 +84,6 @@ Handle<Value> GraphNode::GetPtr(Local<String> property, const AccessorInfo& info
return scope.Close(Integer::NewFromUnsigned(id));
}
-Handle<Value> GraphNode::GetInstancesCount(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- int32_t count = static_cast<HeapGraphNode*>(ptr)->GetInstancesCount();
- return scope.Close(Integer::New(count));
-}
-
Handle<Value> GraphNode::GetChildrenCount(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
@@ -158,28 +148,6 @@ Handle<Value> GraphNode::GetRetainer(const Arguments& args) {
return scope.Close(GraphEdge::New(edge));
}
-Handle<Value> GraphNode::GetRetainingPathsCount(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- int32_t count = static_cast<HeapGraphNode*>(ptr)->GetRetainingPathsCount();
- return scope.Close(Integer::New(count));
-}
-
-Handle<Value> GraphNode::GetRetainingPath(const Arguments& args) {
- HandleScope scope;
- if (args.Length() < 1) {
- return ThrowException(Exception::Error(String::New("No index specified")));
- } else if (!args[0]->IsInt32()) {
- return ThrowException(Exception::Error(String::New("Argument must be integer")));
- }
- int32_t index = args[0]->Int32Value();
- Handle<Object> self = args.This();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphPath* path = static_cast<HeapGraphNode*>(ptr)->GetRetainingPath(index);
- return scope.Close(GraphPath::New(path));
-}
-
Handle<Value> GraphNode::GetDominator(Local<String> property, const AccessorInfo& info) {
HandleScope scope;
Local<Object> self = info.Holder();
@@ -204,4 +172,4 @@ Handle<Value> GraphNode::New(const HeapGraphNode* node) {
return scope.Close(obj);
}
}
-}
+}
View
3 graph_node.h
@@ -18,15 +18,12 @@ class GraphNode {
static Handle<Value> GetName(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetId(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetPtr(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetInstancesCount(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetChildrenCount(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetRetainersCount(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetSize(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetChild(const Arguments& args);
static Handle<Value> GetRetainedSize(const Arguments& args);
static Handle<Value> GetRetainer(const Arguments& args);
- static Handle<Value> GetRetainingPathsCount(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetRetainingPath(const Arguments& args);
static Handle<Value> GetDominator(Local<String> property, const AccessorInfo& info);
static void Initialize();
static Persistent<ObjectTemplate> node_template_;
View
74 graph_path.cc
@@ -1,74 +0,0 @@
-#include "graph_path.h"
-#include "graph_node.h"
-#include "graph_edge.h"
-
-using namespace v8;
-
-namespace nodex {
-
-Persistent<ObjectTemplate> GraphPath::path_template_;
-
-void GraphPath::Initialize() {
- path_template_ = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
- path_template_->SetInternalFieldCount(1);
- path_template_->SetAccessor(String::New("edgesCount"), GraphPath::GetEdgesCount);
- path_template_->SetAccessor(String::New("from"), GraphPath::GetFromNode);
- path_template_->SetAccessor(String::New("to"), GraphPath::GetToNode);
- path_template_->Set(String::New("getEdge"), FunctionTemplate::New(GraphPath::GetEdge));
-}
-
-Handle<Value> GraphPath::GetEdgesCount(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- int32_t count = static_cast<HeapGraphPath*>(ptr)->GetEdgesCount();
- return scope.Close(Integer::New(count));
-}
-
-Handle<Value> GraphPath::GetEdge(const Arguments& args) {
- HandleScope scope;
- if (args.Length() < 1) {
- return ThrowException(Exception::Error(String::New("No index specified")));
- } else if (!args[0]->IsInt32()) {
- return ThrowException(Exception::Error(String::New("Argument must be integer")));
- }
- int32_t index = args[0]->Int32Value();
- Handle<Object> self = args.This();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphEdge* edge = static_cast<HeapGraphPath*>(ptr)->GetEdge(index);
- return scope.Close(GraphEdge::New(edge));
-}
-
-Handle<Value> GraphPath::GetFromNode(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphNode* node = static_cast<HeapGraphPath*>(ptr)->GetFromNode();
- return scope.Close(GraphNode::New(node));
-}
-
-Handle<Value> GraphPath::GetToNode(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphNode* node = static_cast<HeapGraphPath*>(ptr)->GetToNode();
- return scope.Close(GraphNode::New(node));
-}
-
-Handle<Value> GraphPath::New(const HeapGraphPath* path) {
- HandleScope scope;
-
- if (path_template_.IsEmpty()) {
- GraphPath::Initialize();
- }
-
- if(!path) {
- return Undefined();
- }
- else {
- Local<Object> obj = path_template_->NewInstance();
- obj->SetPointerInInternalField(0, const_cast<HeapGraphPath*>(path));
- return scope.Close(obj);
- }
-}
-}
View
27 graph_path.h
@@ -1,27 +0,0 @@
-
-
-#ifndef NODE_GRAPH_PATH_
-#define NODE_GRAPH_PATH_
-
-#include <v8.h>
-#include <v8-profiler.h>
-
-using namespace v8;
-
-namespace nodex {
-
-class GraphPath {
- public:
- static Handle<Value> New(const HeapGraphPath* path);
-
- private:
- static Handle<Value> GetEdgesCount(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetToNode(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetFromNode(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetEdge(const Arguments& args);
- static void Initialize();
- static Persistent<ObjectTemplate> path_template_;
-};
-
-}
-#endif // NODE_GRAPH_PATH_
View
6 package.json
@@ -1,10 +1,10 @@
{
"name": "v8-profiler",
- "version": "0.0.2",
+ "version": "3.6.2beta",
"description": "node bindings for the v8 profiler",
"homepage": "http://github.com/dannycoates/v8-profiler",
"author": "Danny Coates <dannycoates@gmail.com>",
"keywords": ["profiler", "inspector"],
- "engines" : { "node": ">=0.3.1" },
+ "engines" : { "node": ">=0.6" },
"main" : "v8-profiler"
-}
+}
View
11 profile.cc
@@ -14,6 +14,7 @@ void Profile::Initialize() {
profile_template_->SetAccessor(String::New("uid"), Profile::GetUid);
profile_template_->SetAccessor(String::New("topRoot"), Profile::GetTopRoot);
profile_template_->SetAccessor(String::New("bottomRoot"), Profile::GetBottomRoot);
+ profile_template_->Set(String::New("delete"), FunctionTemplate::New(Profile::Delete));
}
Handle<Value> Profile::GetUid(Local<String> property, const AccessorInfo& info) {
@@ -50,6 +51,14 @@ Handle<Value> Profile::GetBottomRoot(Local<String> property, const AccessorInfo&
return scope.Close(ProfileNode::New(node));
}
+Handle<Value> Profile::Delete(const Arguments& args) {
+ HandleScope scope;
+ Handle<Object> self = args.This();
+ void* ptr = self->GetPointerFromInternalField(0);
+ static_cast<CpuProfile*>(ptr)->Delete();
+ return Undefined();
+}
+
Handle<Value> Profile::New(const CpuProfile* profile) {
HandleScope scope;
@@ -66,4 +75,4 @@ Handle<Value> Profile::New(const CpuProfile* profile) {
return scope.Close(obj);
}
}
-}
+}
View
3 profile.h
@@ -19,9 +19,10 @@ class Profile {
static Handle<Value> GetTitle(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetTopRoot(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetBottomRoot(Local<String> property, const AccessorInfo& info);
+ static Handle<Value> Delete(const Arguments& args);
static void Initialize();
static Persistent<ObjectTemplate> profile_template_;
};
}
-#endif // NODE_PROFILE_
+#endif // NODE_PROFILE_
View
29 profiler.cc
@@ -12,7 +12,7 @@ static Handle<Value> TakeSnapshot(const Arguments& args) {
HandleScope scope;
Local<String> title = String::New("");
int32_t len = args.Length();
- HeapSnapshot::Type mode = HeapSnapshot::kAggregated;
+ HeapSnapshot::Type mode = HeapSnapshot::kFull;
if (len > 0) {
title = args[0]->ToString();
}
@@ -50,21 +50,27 @@ static Handle<Value> GetSnapshotsCount(const Arguments& args) {
return scope.Close(Integer::New(HeapProfiler::GetSnapshotsCount()));
}
-Handle<Value> StartProfiling(const Arguments& args) {
+static Handle<Value> DeleteAllSnapshots(const Arguments& args) {
+ HandleScope scope;
+ HeapProfiler::DeleteAllSnapshots();
+ return Undefined();
+}
+
+static Handle<Value> StartProfiling(const Arguments& args) {
HandleScope scope;
Local<String> title = args.Length() > 0 ? args[0]->ToString() : String::New("");
v8::CpuProfiler::StartProfiling(title);
return Undefined();
}
-Handle<Value> StopProfiling(const Arguments& args) {
+static Handle<Value> StopProfiling(const Arguments& args) {
HandleScope scope;
Local<String> title = args.Length() > 0 ? args[0]->ToString() : String::New("");
const CpuProfile* profile = v8::CpuProfiler::StopProfiling(title);
return scope.Close(Profile::New(profile));
}
-Handle<Value> GetProfile(const Arguments& args) {
+static Handle<Value> GetProfile(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1) {
return ThrowException(Exception::Error(String::New("No index specified")));
@@ -76,7 +82,7 @@ Handle<Value> GetProfile(const Arguments& args) {
return scope.Close(Profile::New(profile));
}
-Handle<Value> FindProfile(const Arguments& args) {
+static Handle<Value> FindProfile(const Arguments& args) {
HandleScope scope;
if (args.Length() < 1) {
return ThrowException(Exception::Error(String::New("No index specified")));
@@ -88,11 +94,17 @@ Handle<Value> FindProfile(const Arguments& args) {
return scope.Close(Profile::New(profile));
}
-Handle<Value> GetProfilesCount(const Arguments& args) {
+static Handle<Value> GetProfilesCount(const Arguments& args) {
HandleScope scope;
return scope.Close(Integer::New(v8::CpuProfiler::GetProfilesCount()));
}
+static Handle<Value> DeleteAllProfiles(const Arguments& args) {
+ HandleScope scope;
+ v8::CpuProfiler::DeleteAllProfiles();
+ return Undefined();
+}
+
extern "C" void init(Handle<Object> target) {
HandleScope scope;
@@ -100,10 +112,13 @@ extern "C" void init(Handle<Object> target) {
NODE_SET_METHOD(target, "getSnapshot", GetSnapshot);
NODE_SET_METHOD(target, "findSnapshot", FindSnapshot);
NODE_SET_METHOD(target, "snapshotCount", GetSnapshotsCount);
+ NODE_SET_METHOD(target, "deleteAllSnapshots", DeleteAllSnapshots);
+ //TODO DefineWrapperClass
NODE_SET_METHOD(target, "startProfiling", StartProfiling);
NODE_SET_METHOD(target, "stopProfiling", StopProfiling);
NODE_SET_METHOD(target, "getProfile", GetProfile);
NODE_SET_METHOD(target, "findProfile", FindProfile);
NODE_SET_METHOD(target, "getProfilesCount", GetProfilesCount);
-}
+ NODE_SET_METHOD(target, "deleteAllProfiles", DeleteAllProfiles);
+}
View
62 snapshot.cc
@@ -1,5 +1,4 @@
#include "snapshot.h"
-#include "snapshot_diff.h"
#include "graph_node.h"
using namespace v8;
@@ -15,7 +14,11 @@ void Snapshot::Initialize() {
snapshot_template_->SetAccessor(String::New("uid"), Snapshot::GetUid);
snapshot_template_->SetAccessor(String::New("root"), Snapshot::GetRoot);
snapshot_template_->SetAccessor(String::New("type"), Snapshot::GetType);
- snapshot_template_->Set(String::New("compareWith"), FunctionTemplate::New(Snapshot::CompareWith));
+ snapshot_template_->SetAccessor(String::New("nodesCount"), Snapshot::GetNodesCount);
+ snapshot_template_->Set(String::New("getNodeById"), FunctionTemplate::New(Snapshot::GetNodeById));
+ snapshot_template_->Set(String::New("getNode"), FunctionTemplate::New(Snapshot::GetNode));
+ snapshot_template_->Set(String::New("delete"), FunctionTemplate::New(Snapshot::Delete));
+ //TODO: serialize
}
Handle<Value> Snapshot::GetUid(Local<String> property, const AccessorInfo& info) {
@@ -53,9 +56,6 @@ Handle<Value> Snapshot::GetType(Local<String> property, const AccessorInfo& info
case HeapSnapshot::kFull :
t = String::New("Full");
break;
- case HeapSnapshot::kAggregated :
- t = String::New("Aggregated");
- break;
default:
t = String::New("Unknown");
break;
@@ -63,20 +63,48 @@ Handle<Value> Snapshot::GetType(Local<String> property, const AccessorInfo& info
return scope.Close(t);
}
-Handle<Value> Snapshot::CompareWith(const Arguments& args) {
- HandleScope scope;
- if (args.Length() < 1) {
+Handle<Value> Snapshot::GetNodesCount(Local<String> property, const AccessorInfo& info) {
+ HandleScope scope;
+ Local<Object> self = info.Holder();
+ void* ptr = self->GetPointerFromInternalField(0);
+ Local<Integer> count = Integer::New(static_cast<HeapSnapshot*>(ptr)->GetNodesCount());
+ return scope.Close(count);
+}
+
+Handle<Value> Snapshot::GetNodeById(const Arguments& args) {
+ HandleScope scope;
+ if (args.Length() < 1) {
return ThrowException(Exception::Error(String::New("No index specified")));
+ } else if (!args[0]->IsUint32()) {
+ return ThrowException(Exception::Error(String::New("Argument must be integer")));
}
- Handle<Object> other = args[0]->ToObject();
+ uint64_t id = static_cast<uint64_t>(args[0]->Uint32Value());
Handle<Object> self = args.This();
-
- void* ptr = self->GetPointerFromInternalField(0);
-
- void* optr = other->GetPointerFromInternalField(0);
-
- const HeapSnapshotsDiff* diff = static_cast<HeapSnapshot*>(ptr)->CompareWith(static_cast<HeapSnapshot*>(optr));
- return scope.Close(SnapshotDiff::New(diff));
+ void* ptr = self->GetPointerFromInternalField(0);
+ const HeapGraphNode* node = static_cast<HeapSnapshot*>(ptr)->GetNodeById(id);
+ return scope.Close(GraphNode::New(node));
+}
+
+Handle<Value> Snapshot::GetNode(const Arguments& args) {
+ HandleScope scope;
+ if (args.Length() < 1) {
+ return ThrowException(Exception::Error(String::New("No index specified")));
+ } else if (!args[0]->IsInt32()) {
+ return ThrowException(Exception::Error(String::New("Argument must be integer")));
+ }
+ int32_t index = args[0]->Int32Value();
+ Handle<Object> self = args.This();
+ void* ptr = self->GetPointerFromInternalField(0);
+ const HeapGraphNode* node = static_cast<HeapSnapshot*>(ptr)->GetNode(index);
+ return scope.Close(GraphNode::New(node));
+}
+
+Handle<Value> Snapshot::Delete(const Arguments& args) {
+ HandleScope scope;
+ Handle<Object> self = args.This();
+ void* ptr = self->GetPointerFromInternalField(0);
+ static_cast<HeapSnapshot*>(ptr)->Delete();
+ return Undefined();
}
Handle<Value> Snapshot::New(const HeapSnapshot* snapshot) {
@@ -95,4 +123,4 @@ Handle<Value> Snapshot::New(const HeapSnapshot* snapshot) {
return scope.Close(obj);
}
}
-}
+}
View
7 snapshot.h
@@ -19,10 +19,13 @@ class Snapshot {
static Handle<Value> GetTitle(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetRoot(Local<String> property, const AccessorInfo& info);
static Handle<Value> GetType(Local<String> property, const AccessorInfo& info);
- static Handle<Value> CompareWith(const Arguments& args);
+ static Handle<Value> GetNodesCount(Local<String> property, const AccessorInfo& info);
+ static Handle<Value> GetNodeById(const Arguments& args);
+ static Handle<Value> GetNode(const Arguments& args);
+ static Handle<Value> Delete(const Arguments& args);
static void Initialize();
static Persistent<ObjectTemplate> snapshot_template_;
};
}
-#endif // NODE_SNAPSHOT_
+#endif // NODE_SNAPSHOT_
View
50 snapshot_diff.cc
@@ -1,50 +0,0 @@
-#include "snapshot_diff.h"
-#include "graph_node.h"
-
-using namespace v8;
-
-namespace nodex {
-
-Persistent<ObjectTemplate> SnapshotDiff::diff_template_;
-
-void SnapshotDiff::Initialize() {
- diff_template_ = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
- diff_template_->SetInternalFieldCount(1);
- diff_template_->SetAccessor(String::New("additions"), SnapshotDiff::GetAdditions);
- diff_template_->SetAccessor(String::New("deletions"), SnapshotDiff::GetDeletions);
-}
-
-Handle<Value> SnapshotDiff::GetAdditions(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphNode* node = static_cast<HeapSnapshotsDiff*>(ptr)->GetAdditionsRoot();
- return scope.Close(GraphNode::New(node));
-}
-
-Handle<Value> SnapshotDiff::GetDeletions(Local<String> property, const AccessorInfo& info) {
- HandleScope scope;
- Local<Object> self = info.Holder();
- void* ptr = self->GetPointerFromInternalField(0);
- const HeapGraphNode* node = static_cast<HeapSnapshotsDiff*>(ptr)->GetDeletionsRoot();
- return scope.Close(GraphNode::New(node));
-}
-
-Handle<Value> SnapshotDiff::New(const HeapSnapshotsDiff* diff) {
- HandleScope scope;
-
- if (diff_template_.IsEmpty()) {
- SnapshotDiff::Initialize();
- }
-
- if(!diff) {
- return Undefined();
- }
- else {
- Local<Object> obj = diff_template_->NewInstance();
- obj->SetPointerInInternalField(0, const_cast<HeapSnapshotsDiff*>(diff));
- return scope.Close(obj);
- }
-}
-
-}
View
25 snapshot_diff.h
@@ -1,25 +0,0 @@
-
-
-#ifndef NODE_SNAPSHOT_DIFF_
-#define NODE_SNAPSHOT_DIFF_
-
-#include <v8.h>
-#include <v8-profiler.h>
-
-using namespace v8;
-
-namespace nodex {
-
-class SnapshotDiff {
- public:
- static Handle<Value> New(const HeapSnapshotsDiff* diff);
-
- private:
- static Handle<Value> GetAdditions(Local<String> property, const AccessorInfo& info);
- static Handle<Value> GetDeletions(Local<String> property, const AccessorInfo& info);
- static void Initialize();
- static Persistent<ObjectTemplate> diff_template_;
-};
-
-}
-#endif // NODE_SNAPSHOT_DIFF_
View
111 v8-profiler.js
@@ -1,7 +1,102 @@
-var binding = require("./build/default/profiler");
+var binding = require("./build/Release/profiler");
function Snapshot() {}
+Snapshot.prototype.compare = function (other) {
+ var my_objects = this.nodeCounts(),
+ their_objects = other.nodeCounts(),
+ diff = {}, i, k, my_val, their_val;
+ all_keys = Object.keys(my_objects).concat(Object.keys(their_objects)); //has dupes, oh well
+ for (i = 0; i < all_keys.length; i++) {
+ k = all_keys[i];
+ my_val = my_objects[k] || 0;
+ their_val = their_objects[k] || 0;
+ diff[k] = their_val - my_val;
+ }
+ return diff;
+}
+
+Snapshot.prototype.hotPath = function() {
+ var path = [], node = this.root, c, i = 0;
+ c = this.children(node);
+ while (c.length > 0 && i < 1000) {
+ node = c[0].to;
+ c = this.children(node);
+ path.push(node);
+ i++;
+ }
+ return path;
+}
+
+Snapshot.prototype.children = function(node) {
+ var i, children = [];
+ for(i = 0; i < node.childrenCount; i++) {
+ children[i] = node.getChild(i);
+ }
+ children.sort(function (a, b){
+ return b.to.retainedSize() - a.to.retainedSize();
+ });
+ return children;
+}
+
+Snapshot.prototype.topDominatorIds = function() {
+ var doms = {}, arr;
+ this.allNodes().forEach(function(node){
+ var dom = node.dominatorNode || { id: "none"};
+ if (doms[dom.id]) {
+ doms[dom.id] += 1;
+ }
+ else {
+ doms[dom.id] = 1;
+ }
+ });
+ arr = Object.keys(doms).map(function(d){
+ return {id: d, count: doms[d]};
+ });
+ arr.sort(function(a, b) {
+ return b.count - a.count;
+ });
+ return arr;
+}
+
+Snapshot.prototype.topDominators = function() {
+ var self = this;
+ return this.topDominatorIds().map(function(d){
+ return self.getNodeById(+d.id);
+ });
+}
+
+Snapshot.prototype.allNodes = function() {
+ var n = this.nodesCount, i, nodes = [];
+ for (i = 0; i < n; i++) {
+ nodes[i] = this.getNode(i);
+ }
+ return nodes;
+}
+
+Snapshot.prototype.nodeCounts = function() {
+ var objects = {};
+ this.allNodes().forEach(function(n){
+ if(n.type === "Object") {
+ if (objects[n.name]) {
+ objects[n.name] += 1;
+ }
+ else {
+ objects[n.name] = 1;
+ }
+ }
+ else {
+ if (objects[n.type]) {
+ objects[n.type] += 1;
+ }
+ else {
+ objects[n.type] = 1;
+ }
+ }
+ });
+ return objects;
+}
+
//adapted from WebCore/bindings/v8/ScriptHeapSnapshot.cpp
Snapshot.prototype.stringify = function() {
var root = this.root, i, j, count_i, count_j, node,
@@ -24,7 +119,7 @@ Snapshot.prototype.stringify = function() {
};
}
// FIXME: the children portion is too slow and bloats the results
- /*
+ //*
else {
entry = {
constructorName: node.name
@@ -94,6 +189,11 @@ exports.snapshotCount = function() {
return heapCache.length;
}
+exports.deleteAllSnapshots = function () {
+ heapCache = [];
+ binding.deleteAllSnapshots();
+}
+
var cpuCache = [];
exports.startProfiling = function(name) {
@@ -119,4 +219,9 @@ exports.profileCount = function() {
return cpuCache.length;
}
-process.profiler = exports;
+exports.deleteAllProfiles = function() {
+ cpuCache = [];
+ binding.deleteAllProfiles();
+}
+
+process.profiler = exports;

0 comments on commit 307276f

Please sign in to comment.
Something went wrong with that request. Please try again.