Author: zturner Date: Tue Mar 21 17:46:46 2017 New Revision: 298455 URL: http://llvm.org/viewvc/llvm-project?rev=298455&view=rev Log: [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. Modified: lldb/trunk/scripts/analyze-project-deps.py Modified: lldb/trunk/scripts/analyze-project-deps.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/analyze-project-deps.py?rev=298455&r1=298454&r2=298455&view=diff ============================================================================== --- lldb/trunk/scripts/analyze-project-deps.py (original) +++ lldb/trunk/scripts/analyze-project-deps.py Tue Mar 21 17:46:46 2017 @@ -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, cyc 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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits