brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · 716143b Raw
85 lines · python
1#!/usr/bin/env python2 3from __future__ import print_function4 5desc = """Generate statistics about optimization records from the YAML files6generated with -fsave-optimization-record and -fdiagnostics-show-hotness.7 8The tools requires PyYAML and Pygments Python packages."""9 10import optrecord11import argparse12import operator13from collections import defaultdict14from multiprocessing import cpu_count, Pool15 16try:17    from guppy import hpy18 19    hp = hpy()20except ImportError:21    print("Memory consumption not shown because guppy is not installed")22    hp = None23 24if __name__ == "__main__":25    parser = argparse.ArgumentParser(description=desc)26    parser.add_argument(27        "yaml_dirs_or_files",28        nargs="+",29        help="List of optimization record files or directories searched "30        "for optimization record files.",31    )32    parser.add_argument(33        "--jobs",34        "-j",35        default=None,36        type=int,37        help="Max job count (defaults to %(default)s, the current CPU count)",38    )39    parser.add_argument(40        "--no-progress-indicator",41        "-n",42        action="store_true",43        default=False,44        help="Do not display any indicator of how many YAML files were read.",45    )46    args = parser.parse_args()47 48    print_progress = not args.no_progress_indicator49 50    files = optrecord.find_opt_files(*args.yaml_dirs_or_files)51    if not files:52        parser.error("No *.opt.yaml files found")53        sys.exit(1)54 55    all_remarks, file_remarks, _ = optrecord.gather_results(56        files, args.jobs, print_progress57    )58    if print_progress:59        print("\n")60 61    bypass = defaultdict(int)62    byname = defaultdict(int)63    for r in optrecord.itervalues(all_remarks):64        bypass[r.Pass] += 165        byname[r.Pass + "/" + r.Name] += 166 67    total = len(all_remarks)68    print("{:24s} {:10d}".format("Total number of remarks", total))69    if hp:70        h = hp.heap()71        print("{:24s} {:10d}".format("Memory per remark", h.size / len(all_remarks)))72    print("\n")73 74    print("Top 10 remarks by pass:")75    for (passname, count) in sorted(76        bypass.items(), key=operator.itemgetter(1), reverse=True77    )[:10]:78        print("  {:30s} {:2.0f}%".format(passname, count * 100.0 / total))79 80    print("\nTop 10 remarks:")81    for (name, count) in sorted(82        byname.items(), key=operator.itemgetter(1), reverse=True83    )[:10]:84        print("  {:30s} {:2.0f}%".format(name, count * 100.0 / total))85