Adam Nemet | b7278af | 2017-03-01 21:35:00 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | |
| 3 | from __future__ import print_function |
| 4 | |
| 5 | desc = '''Generate statistics about optimization records from the YAML files |
| 6 | generated with -fsave-optimization-record and -fdiagnostics-show-hotness. |
| 7 | |
| 8 | The tools requires PyYAML and Pygments Python packages.''' |
| 9 | |
| 10 | import optrecord |
| 11 | import argparse |
| 12 | import operator |
| 13 | from collections import defaultdict |
| 14 | from multiprocessing import cpu_count, Pool |
| 15 | |
| 16 | if __name__ == '__main__': |
| 17 | parser = argparse.ArgumentParser(description=desc) |
| 18 | parser.add_argument('yaml_files', nargs='+') |
| 19 | parser.add_argument( |
| 20 | '--jobs', |
| 21 | '-j', |
| 22 | default=cpu_count(), |
| 23 | type=int, |
Brian Gesiak | 701386d | 2017-06-10 21:33:27 +0000 | [diff] [blame] | 24 | help='Max job count (defaults to %(default)s, the current CPU count)') |
Adam Nemet | b7278af | 2017-03-01 21:35:00 +0000 | [diff] [blame] | 25 | args = parser.parse_args() |
| 26 | |
| 27 | if len(args.yaml_files) == 0: |
| 28 | parser.print_help() |
| 29 | sys.exit(1) |
| 30 | |
| 31 | if args.jobs == 1: |
| 32 | pmap = map |
| 33 | else: |
| 34 | pool = Pool(processes=args.jobs) |
| 35 | pmap = pool.map |
| 36 | |
| 37 | all_remarks, file_remarks, _ = optrecord.gather_results(pmap, args.yaml_files) |
| 38 | |
| 39 | bypass = defaultdict(int) |
| 40 | byname = defaultdict(int) |
| 41 | for r in all_remarks.itervalues(): |
| 42 | bypass[r.Pass] += 1 |
| 43 | byname[r.Pass + "/" + r.Name] += 1 |
| 44 | |
| 45 | total = len(all_remarks) |
| 46 | print("{:24s} {:10d}\n".format("Total number of remarks", total)) |
| 47 | |
| 48 | print("Top 10 remarks by pass:") |
| 49 | for (passname, count) in sorted(bypass.items(), key=operator.itemgetter(1), |
| 50 | reverse=True)[:10]: |
| 51 | print(" {:30s} {:2.0f}%". format(passname, count * 100. / total)) |
| 52 | |
| 53 | print("\nTop 10 remarks:") |
| 54 | for (name, count) in sorted(byname.items(), key=operator.itemgetter(1), |
| 55 | reverse=True)[:10]: |
| 56 | print(" {:30s} {:2.0f}%". format(name, count * 100. / total)) |