()
| 44 | |
| 45 | |
| 46 | def 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 |
no test coverage detected
searching dependent graphs…