2017-03-01 22:35:00 +01:00
|
|
|
#!/usr/bin/env python2.7
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
desc = '''Generate statistics about optimization records from the YAML files
|
|
|
|
generated with -fsave-optimization-record and -fdiagnostics-show-hotness.
|
|
|
|
|
|
|
|
The tools requires PyYAML and Pygments Python packages.'''
|
|
|
|
|
|
|
|
import optrecord
|
|
|
|
import argparse
|
|
|
|
import operator
|
|
|
|
from collections import defaultdict
|
|
|
|
from multiprocessing import cpu_count, Pool
|
|
|
|
|
2017-07-20 00:04:58 +02:00
|
|
|
try:
|
|
|
|
from guppy import hpy
|
|
|
|
hp = hpy()
|
|
|
|
except ImportError:
|
|
|
|
print("Memory consumption not shown because guppy is not installed")
|
|
|
|
hp = None
|
|
|
|
|
2017-03-01 22:35:00 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description=desc)
|
2017-07-17 20:00:41 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'yaml_dirs_or_files',
|
|
|
|
nargs='+',
|
|
|
|
help='List of optimization record files or directories searched '
|
|
|
|
'for optimization record files.')
|
2017-03-01 22:35:00 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'--jobs',
|
|
|
|
'-j',
|
2018-01-05 23:05:13 +01:00
|
|
|
default=None,
|
2017-03-01 22:35:00 +01:00
|
|
|
type=int,
|
2017-06-10 23:33:27 +02:00
|
|
|
help='Max job count (defaults to %(default)s, the current CPU count)')
|
2017-06-29 20:56:25 +02:00
|
|
|
parser.add_argument(
|
|
|
|
'--no-progress-indicator',
|
|
|
|
'-n',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Do not display any indicator of how many YAML files were read.')
|
2017-03-01 22:35:00 +01:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2017-06-29 20:56:25 +02:00
|
|
|
print_progress = not args.no_progress_indicator
|
2017-07-17 20:00:41 +02:00
|
|
|
|
2017-09-29 07:20:53 +02:00
|
|
|
files = optrecord.find_opt_files(*args.yaml_dirs_or_files)
|
2017-07-17 20:00:41 +02:00
|
|
|
if not files:
|
|
|
|
parser.error("No *.opt.yaml files found")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-06-29 20:56:25 +02:00
|
|
|
all_remarks, file_remarks, _ = optrecord.gather_results(
|
2017-07-17 20:00:41 +02:00
|
|
|
files, args.jobs, print_progress)
|
2017-06-29 20:56:25 +02:00
|
|
|
if print_progress:
|
|
|
|
print('\n')
|
2017-03-01 22:35:00 +01:00
|
|
|
|
|
|
|
bypass = defaultdict(int)
|
|
|
|
byname = defaultdict(int)
|
2017-06-26 18:51:24 +02:00
|
|
|
for r in optrecord.itervalues(all_remarks):
|
2017-03-01 22:35:00 +01:00
|
|
|
bypass[r.Pass] += 1
|
|
|
|
byname[r.Pass + "/" + r.Name] += 1
|
|
|
|
|
|
|
|
total = len(all_remarks)
|
2017-07-20 00:04:58 +02:00
|
|
|
print("{:24s} {:10d}".format("Total number of remarks", total))
|
|
|
|
if hp:
|
|
|
|
h = hp.heap()
|
|
|
|
print("{:24s} {:10d}".format("Memory per remark",
|
|
|
|
h.size / len(all_remarks)))
|
|
|
|
print('\n')
|
2017-03-01 22:35:00 +01:00
|
|
|
|
|
|
|
print("Top 10 remarks by pass:")
|
|
|
|
for (passname, count) in sorted(bypass.items(), key=operator.itemgetter(1),
|
|
|
|
reverse=True)[:10]:
|
|
|
|
print(" {:30s} {:2.0f}%". format(passname, count * 100. / total))
|
|
|
|
|
|
|
|
print("\nTop 10 remarks:")
|
|
|
|
for (name, count) in sorted(byname.items(), key=operator.itemgetter(1),
|
|
|
|
reverse=True)[:10]:
|
|
|
|
print(" {:30s} {:2.0f}%". format(name, count * 100. / total))
|