Skip to content

Instantly share code, notes, and snippets.

@bmeck bmeck/segfault.cc Secret
Created Jul 10, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.