MCPcopy Create free account
hub / github.com/Snapchat/Valdi / build

Method build

valdi/src/valdi/runtime/JavaScript/JavaScriptHeapDumpBuilder.cpp:591–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591BytesView JavaScriptHeapDumpBuilder::build() {
592 SC_ASSERT(_nodes.size() == _nodeById.size());
593
594 auto output = makeShared<ByteBuffer>();
595 JSONWriter writer(*output);
596
597 writer.writeBeginObject();
598
599 writer.writeProperty("snapshot");
600 writeSnapshot(_nodes.size(), _edges.size(), writer);
601 writer.writeComma();
602 writer.writeNewLine();
603
604 writer.writeProperty("nodes");
605 writer.writeArray(_nodes, [&](const JavaScriptHeapDumpBuilder::Node& node) {
606 /**
607 0 type The type of node. See Node types, below.
608 1 name The name of the node. This is a number that's the index in the top-level strings array. To find
609 the actual name, use the index number to look up the string in the top-level strings array.
610 2 id The node's unique ID.
611 3 self_size The node's size in bytes.
612 4 edge_count The number of edges connected to this node.
613 5 trace_node_id The ID of the trace node
614 6 detachedness Whether this node can be reached from the window global object. 0 means the node is not
615 detached; the node can be reached from the window global object. 1 means the node is detached; the node can't
616 be reached from the window global object.
617 */
618 writer.writeInt(node.type);
619 writer.writeComma();
620 writer.writeInt(node.name);
621 writer.writeComma();
622 writer.writeInt(node.id);
623 writer.writeComma();
624 writer.writeInt(node.selfSize);
625 writer.writeComma();
626 writer.writeInt(node.edgeCount);
627 writer.writeComma();
628 writer.writeInt(static_cast<int32_t>(0));
629 writer.writeComma();
630 writer.writeInt(static_cast<int32_t>(0));
631 });
632 writer.writeComma();
633 writer.writeNewLine();
634
635 writer.writeProperty("edges");
636 writer.writeArray(_edges, [&](const JavaScriptHeapDumpBuilder::Edge& edge) {
637 /**
638 0 type The type of edge. See Edge types to find out what are the possible types.
639 1 name_or_index This can be a number or a string. If it's a number, it corresponds to the index in the
640 top-level strings array, where the name of the edge can be found. 2 to_node The index within the nodes
641 array that this edge is connected to.
642 */
643 const auto& indexedNode = _nodeById[edge.nodeId - 1];
644 // We should have visited the node and resolved its index
645 SC_ASSERT(indexedNode.nodeIndex.has_value());
646
647 writer.writeInt(edge.type);
648 writer.writeComma();

Calls 14

writeSnapshotFunction · 0.85
writeBeginObjectMethod · 0.80
writePropertyMethod · 0.80
writeCommaMethod · 0.80
writeNewLineMethod · 0.80
writeArrayMethod · 0.80
writeIntMethod · 0.80
writeEndObjectMethod · 0.80
valueMethod · 0.65
sizeMethod · 0.45
has_valueMethod · 0.45
writeStringMethod · 0.45