about summary refs log tree commit diff
path: root/pkgs/build-support/references-by-popularity/closure-graph.py
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2019-03-05 16:29:20 -0500
committerGraham Christensen <graham@grahamc.com>2019-03-05 16:32:06 -0500
commit54826e7471fb5c8ccfff47fd0389f7a89ec3b67d (patch)
treea31935f28348c58b478b713151376c1d5f0944cf /pkgs/build-support/references-by-popularity/closure-graph.py
parenteef63417d46c2b093ecce0bf07411a2ae0bbbb1e (diff)
references-by-popularity: create debug output
Diffstat (limited to 'pkgs/build-support/references-by-popularity/closure-graph.py')
-rw-r--r--pkgs/build-support/references-by-popularity/closure-graph.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/pkgs/build-support/references-by-popularity/closure-graph.py b/pkgs/build-support/references-by-popularity/closure-graph.py
index d67a5dfcf140d..145ba1bc9b3fb 100644
--- a/pkgs/build-support/references-by-popularity/closure-graph.py
+++ b/pkgs/build-support/references-by-popularity/closure-graph.py
@@ -117,6 +117,17 @@ import unittest
 from pprint import pprint
 from collections import defaultdict
 
+
+def debug(msg, *args, **kwargs):
+    if False:
+        print(
+            "DEBUG: {}".format(
+                msg.format(*args, **kwargs)
+            ),
+            file=sys.stderr
+        )
+
+
 # Find paths in the original dataset which are never referenced by
 # any other paths
 def find_roots(closures):
@@ -330,6 +341,7 @@ class TestMakeLookup(unittest.TestCase):
 def make_graph_segment_from_root(root, lookup):
     children = {}
     for ref in lookup[root]:
+        debug("Making graph segments on {}".format(ref))
         children[ref] = make_graph_segment_from_root(ref, lookup)
     return children
 
@@ -384,6 +396,7 @@ class TestMakeGraphSegmentFromRoot(unittest.TestCase):
 def graph_popularity_contest(full_graph):
     popularity = defaultdict(int)
     for path, subgraph in full_graph.items():
+        debug("Calculating popularity under {}".format(path))
         popularity[path] += 1
         subcontest = graph_popularity_contest(subgraph)
         for subpath, subpopularity in subcontest.items():
@@ -474,6 +487,7 @@ def main():
     filename = sys.argv[1]
     key = sys.argv[2]
 
+    debug("Loading from {}", filename)
     with open(filename) as f:
         data = json.load(f)
 
@@ -497,14 +511,21 @@ def main():
     # ]
     graph = data[key]
 
+    debug("Finding roots from {}", key)
     roots = find_roots(graph);
+    debug("Making lookup for {}", key)
     lookup = make_lookup(graph)
 
     full_graph = {}
     for root in roots:
+        debug("Making full graph for {}", root)
         full_graph[root] = make_graph_segment_from_root(root, lookup)
 
-    ordered = order_by_popularity(graph_popularity_contest(full_graph))
+    debug("Running contest")
+    contest = graph_popularity_contest(full_graph)
+    debug("Ordering by popularity")
+    ordered = order_by_popularity(contest)
+    debug("Checking for missing paths")
     missing = []
     for path in all_paths(graph):
         if path not in ordered: