[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / tools / opt-viewer / opt-stats.py
blob716143b31a8908b1831746b5b868fd0efd49a286
1 #!/usr/bin/env python
3 from __future__ import print_function
5 desc = """Generate statistics about optimization records from the YAML files
6 generated with -fsave-optimization-record and -fdiagnostics-show-hotness.
8 The tools requires PyYAML and Pygments Python packages."""
10 import optrecord
11 import argparse
12 import operator
13 from collections import defaultdict
14 from multiprocessing import cpu_count, Pool
16 try:
17 from guppy import hpy
19 hp = hpy()
20 except ImportError:
21 print("Memory consumption not shown because guppy is not installed")
22 hp = None
24 if __name__ == "__main__":
25 parser = argparse.ArgumentParser(description=desc)
26 parser.add_argument(
27 "yaml_dirs_or_files",
28 nargs="+",
29 help="List of optimization record files or directories searched "
30 "for optimization record files.",
32 parser.add_argument(
33 "--jobs",
34 "-j",
35 default=None,
36 type=int,
37 help="Max job count (defaults to %(default)s, the current CPU count)",
39 parser.add_argument(
40 "--no-progress-indicator",
41 "-n",
42 action="store_true",
43 default=False,
44 help="Do not display any indicator of how many YAML files were read.",
46 args = parser.parse_args()
48 print_progress = not args.no_progress_indicator
50 files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
51 if not files:
52 parser.error("No *.opt.yaml files found")
53 sys.exit(1)
55 all_remarks, file_remarks, _ = optrecord.gather_results(
56 files, args.jobs, print_progress
58 if print_progress:
59 print("\n")
61 bypass = defaultdict(int)
62 byname = defaultdict(int)
63 for r in optrecord.itervalues(all_remarks):
64 bypass[r.Pass] += 1
65 byname[r.Pass + "/" + r.Name] += 1
67 total = len(all_remarks)
68 print("{:24s} {:10d}".format("Total number of remarks", total))
69 if hp:
70 h = hp.heap()
71 print("{:24s} {:10d}".format("Memory per remark", h.size / len(all_remarks)))
72 print("\n")
74 print("Top 10 remarks by pass:")
75 for (passname, count) in sorted(
76 bypass.items(), key=operator.itemgetter(1), reverse=True
77 )[:10]:
78 print(" {:30s} {:2.0f}%".format(passname, count * 100.0 / total))
80 print("\nTop 10 remarks:")
81 for (name, count) in sorted(
82 byname.items(), key=operator.itemgetter(1), reverse=True
83 )[:10]:
84 print(" {:30s} {:2.0f}%".format(name, count * 100.0 / total))