annotate tools/opt-viewer/opt-stats.py @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
1 #!/usr/bin/env python
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 from __future__ import print_function
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 desc = '''Generate statistics about optimization records from the YAML files
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 generated with -fsave-optimization-record and -fdiagnostics-show-hotness.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 The tools requires PyYAML and Pygments Python packages.'''
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 import optrecord
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 import argparse
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 import operator
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 from collections import defaultdict
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 from multiprocessing import cpu_count, Pool
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 try:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 from guppy import hpy
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 hp = hpy()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 except ImportError:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 print("Memory consumption not shown because guppy is not installed")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 hp = None
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 if __name__ == '__main__':
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 parser = argparse.ArgumentParser(description=desc)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 parser.add_argument(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 'yaml_dirs_or_files',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 nargs='+',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 help='List of optimization record files or directories searched '
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 'for optimization record files.')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 parser.add_argument(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 '--jobs',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 '-j',
134
3a76565eade5 update 5.0.1
mir3636
parents: 121
diff changeset
33 default=None,
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 type=int,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 help='Max job count (defaults to %(default)s, the current CPU count)')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 parser.add_argument(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 '--no-progress-indicator',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 '-n',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 action='store_true',
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 default=False,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 help='Do not display any indicator of how many YAML files were read.')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 args = parser.parse_args()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 print_progress = not args.no_progress_indicator
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 if not files:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 parser.error("No *.opt.yaml files found")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 sys.exit(1)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 all_remarks, file_remarks, _ = optrecord.gather_results(
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 files, args.jobs, print_progress)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 if print_progress:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 print('\n')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 bypass = defaultdict(int)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 byname = defaultdict(int)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 for r in optrecord.itervalues(all_remarks):
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 bypass[r.Pass] += 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 byname[r.Pass + "/" + r.Name] += 1
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 total = len(all_remarks)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 print("{:24s} {:10d}".format("Total number of remarks", total))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 if hp:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 h = hp.heap()
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 print("{:24s} {:10d}".format("Memory per remark",
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 h.size / len(all_remarks)))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 print('\n')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 print("Top 10 remarks by pass:")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 for (passname, count) in sorted(bypass.items(), key=operator.itemgetter(1),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 reverse=True)[:10]:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 print(" {:30s} {:2.0f}%". format(passname, count * 100. / total))
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 print("\nTop 10 remarks:")
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 for (name, count) in sorted(byname.items(), key=operator.itemgetter(1),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 reverse=True)[:10]:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 print(" {:30s} {:2.0f}%". format(name, count * 100. / total))