[gjs: 9/11] heapgraph: Add root edges outside of search function



commit a8c6daadf81bc310d70a6f3856ca645c8c09a47e
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 10 18:53:40 2019 -0700

    heapgraph: Add root edges outside of search function
    
    The search function is called once for each selected target, and as far
    as I can see the root edges only need to be added once since they don't
    depend on which target is being searched for.

 tools/heapgraph.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)
---
diff --git a/tools/heapgraph.py b/tools/heapgraph.py
index 5a809a9e..b7c20d7b 100755
--- a/tools/heapgraph.py
+++ b/tools/heapgraph.py
@@ -484,17 +484,6 @@ def find_roots_bfs(args, edges, graph, target):
         if wme.keyDelegate != '0x0':
             weakData.setdefault(wme.keyDelegate, set([])).add(wme)
 
-    # Unlike JavaScript objects, GObjects can be "rooted" by their refcount so
-    # we have to use a fake root (repetitively)
-    startObject = 'FAKE START OBJECT'
-    rootEdges = set([])
-
-    for addr, isBlack in graph.roots.items():
-        if isBlack or not args.no_gray_roots:
-            rootEdges.add(addr)
-
-    #FIXME:
-    edges[startObject] = rootEdges
     distances[startObject] = (-1, None)
     workList.append(startObject)
 
@@ -679,6 +668,15 @@ if __name__ == "__main__":
     elif args.count:
         sys.exit(-1);
 
+    # Unlike JavaScript objects, GObjects can be "rooted" by their refcount so
+    # we have to use a fake root (repetitively)
+    rootEdges = set([])
+    for addr, isBlack in graph.roots.items():
+        if isBlack or not args.no_gray_roots:
+            rootEdges.add(addr)
+    startObject = 'FAKE START OBJECT'
+    edges[startObject] = rootEdges
+
     for addr in targets:
         if addr in edges and addr not in diff_addrs:
             find_roots_bfs(args, edges, graph, addr)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]