Add sorting support to analyze_brprob script
* analyze_brprob.py: Add new argument --sorting. From-SVN: r237256
This commit is contained in:
parent
e49efc14a1
commit
0d73e4800d
2 changed files with 23 additions and 7 deletions
|
@ -1,3 +1,7 @@
|
|||
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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue