Parse the roots portion of a garbage collector heap.
(fobj)
| 135 | ############################################################################### |
| 136 | |
| 137 | def parse_roots(fobj): |
| 138 | """Parse the roots portion of a garbage collector heap.""" |
| 139 | |
| 140 | roots = {} |
| 141 | root_labels = {} |
| 142 | weakMapEntries = [] |
| 143 | |
| 144 | for line in fobj: |
| 145 | node = node_regex.match(line) |
| 146 | |
| 147 | if node: |
| 148 | addr = node.group(1) |
| 149 | color = node.group(2) |
| 150 | label = node.group(3) |
| 151 | |
| 152 | # Only overwrite an existing root with a black root. |
| 153 | if addr not in roots or color == 'B': |
| 154 | roots[addr] = (color == 'B') |
| 155 | # It would be classier to save all the root labels, though then |
| 156 | # we have to worry about gray vs black. |
| 157 | root_labels[addr] = label |
| 158 | else: |
| 159 | wme = wme_regex.match(line) |
| 160 | |
| 161 | if wme: |
| 162 | weakMapEntries.append(WeakMapEntry(weakMap=wme.group(1), |
| 163 | key=wme.group(2), |
| 164 | keyDelegate=wme.group(3), |
| 165 | value=wme.group(4))) |
| 166 | # Skip comments, arenas, realms and zones |
| 167 | elif line[0] == '#': |
| 168 | continue |
| 169 | # Marks the end of the roots section |
| 170 | elif line[:10] == '==========': |
| 171 | break |
| 172 | else: |
| 173 | sys.stderr.write('Error: unknown line {}\n'.format(line)) |
| 174 | exit(-1) |
| 175 | |
| 176 | return [roots, root_labels, weakMapEntries] |
| 177 | |
| 178 | |
| 179 | def parse_graph(fobj): |
no test coverage detected