MCPcopy Create free account
hub / github.com/GNOME/gjs / parse_roots

Function parse_roots

tools/heapgraph.py:137–176  ·  view source on GitHub ↗

Parse the roots portion of a garbage collector heap.

(fobj)

Source from the content-addressed store, hash-verified

135###############################################################################
136
137def 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
179def parse_graph(fobj):

Callers 1

parse_heapFunction · 0.85

Calls 3

matchMethod · 0.80
groupMethod · 0.65
writeMethod · 0.45

Tested by

no test coverage detected