MCPcopy Index your code
hub / github.com/nodejs/node / createJSHeapSnapshot

Function createJSHeapSnapshot

test/common/heap.js:22–63  ·  view source on GitHub ↗
(stream = getHeapSnapshot())

Source from the content-addressed store, hash-verified

20const { getHeapSnapshot } = require('v8');
21
22function createJSHeapSnapshot(stream = getHeapSnapshot()) {
23 stream.pause();
24 stream.read(0);
25 const dump = JSON.parse(stream.read(stream.readableLength));
26 const meta = dump.snapshot.meta;
27
28 const nodes =
29 readHeapInfo(dump.nodes, meta.node_fields, meta.node_types, dump.strings);
30 const edges =
31 readHeapInfo(dump.edges, meta.edge_fields, meta.edge_types, dump.strings);
32
33 for (const node of nodes) {
34 node.incomingEdges = [];
35 node.outgoingEdges = [];
36 }
37
38 let fromNodeIndex = 0;
39 let edgeIndex = 0;
40 for (const { type, name_or_index, to_node } of edges) {
41 while (edgeIndex === nodes[fromNodeIndex].edge_count) {
42 edgeIndex = 0;
43 fromNodeIndex++;
44 }
45 const toNode = nodes[to_node / meta.node_fields.length];
46 const fromNode = nodes[fromNodeIndex];
47 const edge = {
48 type,
49 to: toNode,
50 from: fromNode,
51 name: typeof name_or_index === 'string' ? name_or_index : null,
52 };
53 toNode.incomingEdges.push(edge);
54 fromNode.outgoingEdges.push(edge);
55 edgeIndex++;
56 }
57
58 for (const node of nodes) {
59 assert.strictEqual(node.edge_count, node.outgoingEdges.length,
60 `${node.edge_count} !== ${node.outgoingEdges.length}`);
61 }
62 return nodes;
63}
64
65function readHeapInfo(raw, fields, types, strings) {
66 const items = [];

Callers 4

constructorMethod · 0.85
validateByRetainingPathFunction · 0.85

Calls 6

getHeapSnapshotFunction · 0.85
readHeapInfoFunction · 0.85
pauseMethod · 0.65
parseMethod · 0.65
readMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…