From: Martin Liska Date: Thu, 9 Jun 2016 11:38:23 +0000 (+0200) Subject: Add sorting support to analyze_brprob script X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0d73e4800df6451f57e67f87c6d602c47e2a0f50;p=gcc.git Add sorting support to analyze_brprob script * analyze_brprob.py: Add new argument --sorting. From-SVN: r237256 --- diff --git a/contrib/ChangeLog b/contrib/ChangeLog index 6c80c1edbe3..8017e48d9a1 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,3 +1,7 @@ +2016-06-09 Martin Liska + + * analyze_brprob.py: Add new argument --sorting. + 2016-06-09 Martin Liska * analyze_brprob.py: Cover new dump output format. diff --git a/contrib/analyze_brprob.py b/contrib/analyze_brprob.py index 9416eed3b44..9808c46de16 100755 --- a/contrib/analyze_brprob.py +++ b/contrib/analyze_brprob.py @@ -65,6 +65,7 @@ import sys import os import re +import argparse def percentage(a, b): return 100.0 * a / b @@ -77,6 +78,9 @@ class Summary: self.hits = 0 self.fits = 0 + def get_hitrate(self): + return self.hits / self.count + def count_formatted(self): v = self.count for unit in ['','K','M','G','T','P','E','Z']: @@ -108,22 +112,30 @@ class Profile: def count_max(self): return max([v.count for k, v in self.heuristics.items()]) - def dump(self): + def dump(self, sorting): + sorter = lambda x: x[1].branches + if sorting == 'hitrate': + sorter = lambda x: x[1].get_hitrate() + elif sorting == 'coverage': + sorter = lambda x: x[1].count + print('%-36s %8s %6s %-16s %14s %8s %6s' % ('HEURISTICS', 'BRANCHES', '(REL)', 'HITRATE', 'COVERAGE', 'COVERAGE', '(REL)')) - for (k, v) in sorted(self.heuristics.items(), key = lambda x: x[1].branches): + for (k, v) in sorted(self.heuristics.items(), key = sorter): print('%-36s %8i %5.1f%% %6.2f%% / %6.2f%% %14i %8s %5.1f%%' % (k, v.branches, percentage(v.branches, self.branches_max ()), percentage(v.hits, v.count), percentage(v.fits, v.count), v.count, v.count_formatted(), percentage(v.count, self.count_max()) )) -if len(sys.argv) != 2: - print('Usage: ./analyze_brprob.py dump_file') - exit(1) +parser = argparse.ArgumentParser() +parser.add_argument('dump_file', metavar = 'dump_file', help = 'IPA profile dump file') +parser.add_argument('-s', '--sorting', dest = 'sorting', choices = ['branches', 'hitrate', 'coverage'], default = 'branches') + +args = parser.parse_args() profile = Profile(sys.argv[1]) r = re.compile(' (.*) heuristics( of edge [0-9]*->[0-9]*)?( \\(.*\\))?: (.*)%.*exec ([0-9]*) hit ([0-9]*)') -for l in open(profile.filename).readlines(): +for l in open(args.dump_file).readlines(): m = r.match(l) if m != None and m.group(3) == None: name = m.group(1) @@ -133,4 +145,4 @@ for l in open(profile.filename).readlines(): profile.add(name, prediction, count, hits) -profile.dump() +profile.dump(args.sorting)