-
-
Save bmeck/a031d5b5a2646ba0eb31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long dump( | |
FileOutputStream* fninfo_stream, | |
const HeapProfiler* profiler, | |
const HeapGraphNode* node, | |
unsigned int visited_count = 0, | |
unsigned int seen_closures = false, | |
std::set<SnapshotObjectId>* visited = NULL, | |
StringSet* strings = new StringSet | |
) { | |
bool cleanup = visited == NULL; | |
if (cleanup) { | |
visited = new std::set<SnapshotObjectId>(); | |
} | |
SnapshotObjectId id = node->GetId(); | |
//if (node->GetName()->IsString()==false) printf("TYPE OF NAME %s\n", strForValueType(node->GetName())); | |
const char* node_name = *String::Utf8Value(node->GetName()); | |
std::set<SnapshotObjectId>::iterator pos = visited->find(id); | |
if (pos != visited->end()) { | |
return visited_count; | |
} | |
visited->insert(id); | |
visited_count++; | |
HeapGraphNode::Type node_type = node->GetType(); | |
if (node_type == HeapGraphNode::Type::kClosure) { | |
if (seen_closures) { | |
fninfo_stream->WriteAsciiChunk(",\n", 2); | |
} | |
dumpHeapGraphNode(fninfo_stream, profiler, node, strings); | |
seen_closures = true; | |
} | |
for (unsigned int i = 0; i < node->GetChildrenCount(); i++) { | |
const HeapGraphEdge* edge = node->GetChild(i); // this causes a segfault? | |
const String::Utf8Value utf8(edge->GetName()); | |
const char* name = *utf8; | |
const HeapGraphNode* child = edge->GetToNode(); | |
visited_count = dump(fninfo_stream, profiler, child, visited_count, seen_closures, visited, strings); | |
} | |
// fprintf(stderr, "<<\n"); | |
if (cleanup) { | |
free(visited); | |
} | |
return visited_count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment