blob: 03de23bdb2757c9a256cd87df125c1bd59fce261 [file] [log] [blame]
Adam Nemetb7278af2017-03-01 21:35:00 +00001#!/usr/bin/env python2.7
2
3from __future__ import print_function
4
5desc = '''Generate statistics about optimization records from the YAML files
6generated with -fsave-optimization-record and -fdiagnostics-show-hotness.
7
8The tools requires PyYAML and Pygments Python packages.'''
9
10import optrecord
11import argparse
12import operator
13from collections import defaultdict
14from multiprocessing import cpu_count, Pool
15
Adam Nemet37d18f12017-07-19 22:04:58 +000016try:
17 from guppy import hpy
18 hp = hpy()
19except ImportError:
20 print("Memory consumption not shown because guppy is not installed")
21 hp = None
22
Adam Nemetb7278af2017-03-01 21:35:00 +000023if __name__ == '__main__':
24 parser = argparse.ArgumentParser(description=desc)
Adam Nemet659d7db2017-07-17 18:00:41 +000025 parser.add_argument(
26 'yaml_dirs_or_files',
27 nargs='+',
28 help='List of optimization record files or directories searched '
29 'for optimization record files.')
Adam Nemetb7278af2017-03-01 21:35:00 +000030 parser.add_argument(
31 '--jobs',
32 '-j',
Zachary Turner7f5fb672018-01-05 22:05:13 +000033 default=None,
Adam Nemetb7278af2017-03-01 21:35:00 +000034 type=int,
Brian Gesiak701386d2017-06-10 21:33:27 +000035 help='Max job count (defaults to %(default)s, the current CPU count)')
Brian Gesiak5e0a9462017-06-29 18:56:25 +000036 parser.add_argument(
37 '--no-progress-indicator',
38 '-n',
39 action='store_true',
40 default=False,
41 help='Do not display any indicator of how many YAML files were read.')
Adam Nemetb7278af2017-03-01 21:35:00 +000042 args = parser.parse_args()
43
Brian Gesiak5e0a9462017-06-29 18:56:25 +000044 print_progress = not args.no_progress_indicator
Adam Nemet659d7db2017-07-17 18:00:41 +000045
Adam Nemet9d57dc62017-09-29 05:20:53 +000046 files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
Adam Nemet659d7db2017-07-17 18:00:41 +000047 if not files:
48 parser.error("No *.opt.yaml files found")
49 sys.exit(1)
50
Brian Gesiak5e0a9462017-06-29 18:56:25 +000051 all_remarks, file_remarks, _ = optrecord.gather_results(
Adam Nemet659d7db2017-07-17 18:00:41 +000052 files, args.jobs, print_progress)
Brian Gesiak5e0a9462017-06-29 18:56:25 +000053 if print_progress:
54 print('\n')
Adam Nemetb7278af2017-03-01 21:35:00 +000055
56 bypass = defaultdict(int)
57 byname = defaultdict(int)
Brian Gesiak9b4e8972017-06-26 16:51:24 +000058 for r in optrecord.itervalues(all_remarks):
Adam Nemetb7278af2017-03-01 21:35:00 +000059 bypass[r.Pass] += 1
60 byname[r.Pass + "/" + r.Name] += 1
61
62 total = len(all_remarks)
Adam Nemet37d18f12017-07-19 22:04:58 +000063 print("{:24s} {:10d}".format("Total number of remarks", total))
64 if hp:
65 h = hp.heap()
66 print("{:24s} {:10d}".format("Memory per remark",
67 h.size / len(all_remarks)))
68 print('\n')
Adam Nemetb7278af2017-03-01 21:35:00 +000069
70 print("Top 10 remarks by pass:")
71 for (passname, count) in sorted(bypass.items(), key=operator.itemgetter(1),
72 reverse=True)[:10]:
73 print(" {:30s} {:2.0f}%". format(passname, count * 100. / total))
74
75 print("\nTop 10 remarks:")
76 for (name, count) in sorted(byname.items(), key=operator.itemgetter(1),
77 reverse=True)[:10]:
78 print(" {:30s} {:2.0f}%". format(name, count * 100. / total))