diff options
author | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-06-09 11:38:23 +0000 |
---|---|---|
committer | marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-06-09 11:38:23 +0000 |
commit | 2a364b3894bb9638b70c0fc3d39601f3afb8972f (patch) | |
tree | 35fec44c87149fecd4daea60a7015ed6cfeb503e /contrib | |
parent | 3f76cceb6e57244bef5d666a9057eab4f9abb92e (diff) | |
download | gcc-2a364b3894bb9638b70c0fc3d39601f3afb8972f.tar.gz |
Add sorting support to analyze_brprob script
* analyze_brprob.py: Add new argument --sorting.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@237256 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/ChangeLog | 4 | ||||
-rwxr-xr-x | contrib/analyze_brprob.py | 26 |
2 files changed, 23 insertions, 7 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog index 6c80c1edbe3..8017e48d9a1 100644 --- a/contrib/ChangeLog +++ b/contrib/ChangeLog @@ -1,5 +1,9 @@ 2016-06-09 Martin Liska <mliska@suse.cz> + * analyze_brprob.py: Add new argument --sorting. + +2016-06-09 Martin Liska <mliska@suse.cz> + * analyze_brprob.py: Cover new dump output format. 2016-06-07 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 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) |