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

Function main

deps/v8/tools/heap-snapshot-processor.py:46–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44
45
46def main():
47 if len(sys.argv) != 2:
48 print("Usage: python3 heap-snapshot-processor.py snapshot.heapsnapshot")
49 exit(1)
50
51 f = open(sys.argv[1])
52 data = json.load(f)
53
54 # Documentation of the format (caveat: documentation for name_or_index is
55 # wrong):
56 # https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/memory-problems/heap-snapshot-schema
57 snapshot = data['snapshot']
58 meta = snapshot['meta']
59
60 node_fields = meta['node_fields']
61 node_field_count = len(node_fields)
62 node_type_ix = node_fields.index('type')
63 node_name_ix = node_fields.index('name')
64 node_id_ix = node_fields.index('id')
65 node_edge_count_ix = node_fields.index('edge_count')
66
67 node_types = meta['node_types']
68 node_type_strings = node_types[node_type_ix]
69
70 edge_fields = meta['edge_fields']
71 edge_field_count = len(edge_fields)
72 edge_type_ix = edge_fields.index('type')
73 edge_name_or_index_ix = edge_fields.index('name_or_index')
74 edge_to_node_ix = edge_fields.index('to_node')
75
76 edge_types = meta['edge_types']
77 edge_type_strings = edge_types[edge_type_ix]
78
79 nodes = data['nodes']
80 edges = data['edges']
81 strings = data['strings']
82
83 node_objects = dict()
84
85 for node_ix in range(0, len(nodes), node_field_count):
86 node_data = nodes[node_ix:(node_ix + node_field_count)]
87 node_type = node_type_strings[node_data[node_type_ix]]
88 node_name = strings[node_data[node_name_ix]]
89 node_id = node_data[node_id_ix]
90 node = Node(node_id, node_type, node_name)
91 node_objects[node_id] = node
92
93 edge_ix = 0
94 for node_ix in range(0, len(nodes), node_field_count):
95 node_data = nodes[node_ix:(node_ix + node_field_count)]
96 edge_count = node_data[node_edge_count_ix]
97 from_node_id = node_data[node_id_ix]
98 from_node = node_objects[from_node_id]
99
100 for e in range(edge_count):
101 edge_data = edges[edge_ix:(edge_ix + edge_field_count)]
102 edge_type = edge_type_strings[edge_data[edge_type_ix]]
103

Callers 1

Calls 11

strFunction · 0.85
process_nodesFunction · 0.85
printFunction · 0.70
NodeClass · 0.70
EdgeClass · 0.70
exitFunction · 0.50
openFunction · 0.50
rangeFunction · 0.50
loadMethod · 0.45
indexMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…