Heap profiler: add an ability to iterate over snapshot's nodes.
This is a preparation for removing aggregated heap snapshots. W/o this API, counting object instances in a snapshot is very hard. R=sgjesse@chromium.org BUG=1481 TEST=cctest/test-heap-profiler/NodesIteration Review URL: http://codereview.chromium.org/7204040 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8342 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
5c63dd26fc
commit
bf9b2f8c2c
@ -346,6 +346,12 @@ class V8EXPORT HeapSnapshot {
|
||||
/** Returns a node by its id. */
|
||||
const HeapGraphNode* GetNodeById(uint64_t id) const;
|
||||
|
||||
/** Returns total nodes count in the snapshot. */
|
||||
int GetNodesCount() const;
|
||||
|
||||
/** Returns a node by index. */
|
||||
const HeapGraphNode* GetNode(int index) const;
|
||||
|
||||
/**
|
||||
* Deletes the snapshot and removes it from HeapProfiler's list.
|
||||
* All pointers to nodes, edges and paths previously returned become
|
||||
|
23
src/api.cc
23
src/api.cc
@ -5886,6 +5886,29 @@ const HeapGraphNode* HeapSnapshot::GetNodeById(uint64_t id) const {
|
||||
}
|
||||
|
||||
|
||||
int HeapSnapshot::GetNodesCount() const {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
i::Isolate* isolate = i::Isolate::Current();
|
||||
IsDeadCheck(isolate, "v8::HeapSnapshot::GetNodesCount");
|
||||
return ToInternal(this)->entries()->length();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
const HeapGraphNode* HeapSnapshot::GetNode(int index) const {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
i::Isolate* isolate = i::Isolate::Current();
|
||||
IsDeadCheck(isolate, "v8::HeapSnapshot::GetNode");
|
||||
return reinterpret_cast<const HeapGraphNode*>(
|
||||
ToInternal(this)->entries()->at(index));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void HeapSnapshot::Serialize(OutputStream* stream,
|
||||
HeapSnapshot::SerializationFormat format) const {
|
||||
#ifdef ENABLE_LOGGING_AND_PROFILING
|
||||
|
@ -1372,4 +1372,22 @@ TEST(DocumentURLWithException) {
|
||||
reinterpret_cast<const i::HeapEntry*>(global))->name());
|
||||
}
|
||||
|
||||
|
||||
TEST(NodesIteration) {
|
||||
v8::HandleScope scope;
|
||||
LocalContext env;
|
||||
const v8::HeapSnapshot* snapshot =
|
||||
v8::HeapProfiler::TakeSnapshot(v8::String::New("iteration"));
|
||||
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
|
||||
CHECK_NE(NULL, global);
|
||||
// Verify that we can find this object by iteration.
|
||||
const int nodes_count = snapshot->GetNodesCount();
|
||||
int count = 0;
|
||||
for (int i = 0; i < nodes_count; ++i) {
|
||||
if (snapshot->GetNode(i) == global)
|
||||
++count;
|
||||
}
|
||||
CHECK_EQ(1, count);
|
||||
}
|
||||
|
||||
#endif // ENABLE_LOGGING_AND_PROFILING
|
||||
|
Loading…
Reference in New Issue
Block a user