import sys
import os
import re
+import argparse
def percentage(a, b):
return 100.0 * a / b
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']:
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)
profile.add(name, prediction, count, hits)
-profile.dump()
+profile.dump(args.sorting)