diff options
author | Zachary Turner <zturner@google.com> | 2017-03-21 22:46:46 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-03-21 22:46:46 +0000 |
commit | 4dbf9fa0d4b036e5ab0ff8dea12a46f896feb831 (patch) | |
tree | ef1f9aa4ea9885702f523429824488a47efef04d | |
parent | 513cb7a87d3181eb70cd22acc8a9911b90a48099 (diff) | |
download | bcm5719-llvm-4dbf9fa0d4b036e5ab0ff8dea12a46f896feb831.tar.gz bcm5719-llvm-4dbf9fa0d4b036e5ab0ff8dea12a46f896feb831.zip |
[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
-rw-r--r-- | lldb/scripts/analyze-project-deps.py | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lldb/scripts/analyze-project-deps.py b/lldb/scripts/analyze-project-deps.py index 1f7b5f393b9..2320100e4d1 100644 --- a/lldb/scripts/analyze-project-deps.py +++ b/lldb/scripts/analyze-project-deps.py @@ -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
\ No newline at end of file |