forked from OSchip/llvm-project
[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
This commit is contained in:
parent
513cb7a87d
commit
4dbf9fa0d4
|
@ -1,6 +1,8 @@
|
|||
import argparse
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from use_lldb_suite import lldb_root
|
||||
|
||||
|
@ -22,7 +24,7 @@ src_map = {}
|
|||
include_regex = re.compile('#include \"((lldb|Plugins|clang)(.*/)+).*\"')
|
||||
|
||||
def is_sublist(small, big):
|
||||
it = iter(big)
|
||||
it = iter(big)
|
||||
return all(c in it for c in small)
|
||||
|
||||
def normalize_host(str):
|
||||
|
@ -102,9 +104,7 @@ def expand(path_queue, path_lengths, cycles, src_map):
|
|||
continue
|
||||
|
||||
next_len = path_lengths.pop(0) + 1
|
||||
|
||||
last_component = cur_path[-1]
|
||||
|
||||
for item in src_map[last_component]:
|
||||
if item.startswith("clang"):
|
||||
continue
|
||||
|
@ -143,6 +143,19 @@ for (path, deps) in items:
|
|||
for dep in sorted_deps:
|
||||
print "\t{}".format(dep[0])
|
||||
|
||||
def iter_cycles(cycles):
|
||||
global src_map
|
||||
for cycle in cycles:
|
||||
cycle.append(cycle[0])
|
||||
zipper = list(zip(cycle[0:-1], cycle[1:]))
|
||||
result = [(x, src_map[x][y], y) for (x,y) in zipper]
|
||||
total = 0
|
||||
smallest = result[0][1]
|
||||
for (first, value, last) in result:
|
||||
total += value
|
||||
smallest = min(smallest, value)
|
||||
yield (total, smallest, result)
|
||||
|
||||
if args.discover_cycles:
|
||||
print "Analyzing cycles..."
|
||||
|
||||
|
@ -151,8 +164,18 @@ if args.discover_cycles:
|
|||
average = sum([len(x)+1 for x in cycles]) / len(cycles)
|
||||
|
||||
print "Found {} cycles. Average cycle length = {}.".format(len(cycles), average)
|
||||
for cycle in cycles:
|
||||
cycle.append(cycle[0])
|
||||
print " -> ".join(cycle)
|
||||
|
||||
if args.show_counts:
|
||||
counted = list(iter_cycles(cycles))
|
||||
counted.sort(lambda A, B: cmp(A[0], B[0]))
|
||||
for (total, smallest, cycle) in counted:
|
||||
sys.stdout.write("{} deps to break: ".format(total))
|
||||
sys.stdout.write(cycle[0][0])
|
||||
for (first, count, last) in cycle:
|
||||
sys.stdout.write(" [{}->] {}".format(count, last))
|
||||
sys.stdout.write("\n")
|
||||
else:
|
||||
for cycle in cycles:
|
||||
cycle.append(cycle[0])
|
||||
print " -> ".join(cycle)
|
||||
sys.stdout.flush()
|
||||
pass
|
Loading…
Reference in New Issue