Skip to content

Commit 4dbf9fa

Browse files
author
Zachary Turner
committed
[deps script] Sort cycles by the difficulty of breaking.
When passing --discover-cycles and --show-counts, it displays the number of dependencies between each hop of the cycle, and sorts by the sum. Dependencies at the top of the list should be the easiest to break. llvm-svn: 298455
1 parent 513cb7a commit 4dbf9fa

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lldb/scripts/analyze-project-deps.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import argparse
2+
import itertools
23
import os
34
import re
5+
import sys
46

57
from use_lldb_suite import lldb_root
68

@@ -22,7 +24,7 @@
2224
include_regex = re.compile('#include \"((lldb|Plugins|clang)(.*/)+).*\"')
2325

2426
def is_sublist(small, big):
25-
it = iter(big)
27+
it = iter(big)
2628
return all(c in it for c in small)
2729

2830
def normalize_host(str):
@@ -102,9 +104,7 @@ def expand(path_queue, path_lengths, cycles, src_map):
102104
continue
103105

104106
next_len = path_lengths.pop(0) + 1
105-
106107
last_component = cur_path[-1]
107-
108108
for item in src_map[last_component]:
109109
if item.startswith("clang"):
110110
continue
@@ -143,6 +143,19 @@ def expand(path_queue, path_lengths, cycles, src_map):
143143
for dep in sorted_deps:
144144
print "\t{}".format(dep[0])
145145

146+
def iter_cycles(cycles):
147+
global src_map
148+
for cycle in cycles:
149+
cycle.append(cycle[0])
150+
zipper = list(zip(cycle[0:-1], cycle[1:]))
151+
result = [(x, src_map[x][y], y) for (x,y) in zipper]
152+
total = 0
153+
smallest = result[0][1]
154+
for (first, value, last) in result:
155+
total += value
156+
smallest = min(smallest, value)
157+
yield (total, smallest, result)
158+
146159
if args.discover_cycles:
147160
print "Analyzing cycles..."
148161

@@ -151,8 +164,18 @@ def expand(path_queue, path_lengths, cycles, src_map):
151164
average = sum([len(x)+1 for x in cycles]) / len(cycles)
152165

153166
print "Found {} cycles. Average cycle length = {}.".format(len(cycles), average)
154-
for cycle in cycles:
155-
cycle.append(cycle[0])
156-
print " -> ".join(cycle)
157-
167+
if args.show_counts:
168+
counted = list(iter_cycles(cycles))
169+
counted.sort(lambda A, B: cmp(A[0], B[0]))
170+
for (total, smallest, cycle) in counted:
171+
sys.stdout.write("{} deps to break: ".format(total))
172+
sys.stdout.write(cycle[0][0])
173+
for (first, count, last) in cycle:
174+
sys.stdout.write(" [{}->] {}".format(count, last))
175+
sys.stdout.write("\n")
176+
else:
177+
for cycle in cycles:
178+
cycle.append(cycle[0])
179+
print " -> ".join(cycle)
180+
sys.stdout.flush()
158181
pass

0 commit comments

Comments
 (0)