blob: f4ee3a7d44e63958dffc6ed7add97e5797a66f7c [file] [log] [blame]
Serge Guelton6da47be2019-01-03 15:44:24 +00001#!/usr/bin/env python
Adam Nemetaa64e902017-03-01 21:35:00 +00002
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 Nemet8de34302017-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 Nemetaa64e902017-03-01 21:35:00 +000023if __name__ == '__main__':
24 parser = argparse.ArgumentParser(description=desc)
Adam Nemetef314682017-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 Nemetaa64e902017-03-01 21:35:00 +000030 parser.add_argument(
31 '--jobs',
32 '-j',
Zachary Turner135e9422018-01-05 22:05:13 +000033 default=None,
Adam Nemetaa64e902017-03-01 21:35:00 +000034 type=int,
Brian Gesiak23ff0952017-06-10 21:33:27 +000035 help='Max job count (defaults to %(default)s, the current CPU count)')
Brian Gesiakfb669912017-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 Nemetaa64e902017-03-01 21:35:00 +000042 args = parser.parse_args()
43
Brian Gesiakfb669912017-06-29 18:56:25 +000044 print_progress = not args.no_progress_indicator
Adam Nemetef314682017-07-17 18:00:41 +000045
Adam Nemet41247e12017-09-29 05:20:53 +000046 files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
Adam Nemetef314682017-07-17 18:00:41 +000047 if not files:
48 parser.error("No *.opt.yaml files found")
49 sys.exit(1)
50
Brian Gesiakfb669912017-06-29 18:56:25 +000051 all_remarks, file_remarks, _ = optrecord.gather_results(
Adam Nemetef314682017-07-17 18:00:41 +000052 files, args.jobs, print_progress)
Brian Gesiakfb669912017-06-29 18:56:25 +000053 if print_progress:
54 print('\n')
Adam Nemetaa64e902017-03-01 21:35:00 +000055
56 bypass = defaultdict(int)
57 byname = defaultdict(int)
Brian Gesiak8ae15db2017-06-26 16:51:24 +000058 for r in optrecord.itervalues(all_remarks):
Adam Nemetaa64e902017-03-01 21:35:00 +000059 bypass[r.Pass] += 1
60 byname[r.Pass + "/" + r.Name] += 1
61
62 total = len(all_remarks)
Adam Nemet8de34302017-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 Nemetaa64e902017-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))