Hello.

This is a small followup, where I would like to add new argument to 
analyze_brprob.py
script file. With the patch, one can sort predictors by e.g. hitrate:


Example CPU2006
HEURISTICS                           BRANCHES  (REL)  HITRATE                
COVERAGE COVERAGE  (REL)
loop iv compare                            33   0.1%  20.27% /  86.24%       
30630826   30.63M   0.0%
no prediction                           10406  19.5%  33.41% /  84.76%   
139755242456  139.76G  14.1%
early return (on trees)                  6328  11.9%  54.20% /  86.48%    
33569991740   33.57G   3.4%
guessed loop iterations                   112   0.2%  62.06% /  64.49%      
958458522  958.46M   0.1%
fail alloc                                595   1.1%  62.18% / 100.00%          
  595   595.00   0.0%
opcode values positive (on trees)        4266   8.0%  64.30% /  91.28%    
16931889792   16.93G   1.7%
opcode values nonequal (on trees)        6600  12.4%  66.23% /  80.60%    
71483051282   71.48G   7.2%
continue                                  507   0.9%  66.66% /  82.85%    
10086808016   10.09G   1.0%
call                                    11351  21.3%  67.16% /  92.24%    
34680666103   34.68G   3.5%
loop iterations                          2689   5.0%  67.99% /  67.99%   
408309517405  408.31G  41.3%
DS theory                               26385  49.4%  68.62% /  85.44%   
146974369890  146.97G  14.9%
const return                              271   0.5%  69.39% /  87.09%      
301566712  301.57M   0.0%
pointer (on trees)                       6230  11.7%  69.59% /  87.18%    
16667735314   16.67G   1.7%
combined                                53398 100.0%  70.31% /  80.36%   
989164856862  989.16G 100.0%
goto                                       78   0.1%  70.36% /  96.96%      
951041538  951.04M   0.1%
first match                             16607  31.1%  78.00% /  78.42%   
702435244516  702.44G  71.0%
extra loop exit                           141   0.3%  82.80% /  88.17%     
1696946942    1.70G   0.2%
null return                               393   0.7%  91.47% /  93.08%     
3268678197    3.27G   0.3%
loop exit                                9909  18.6%  91.80% /  92.81%   
282927773783  282.93G  28.6%
guess loop iv compare                     178   0.3%  97.81% /  97.85%     
4375086453    4.38G   0.4%
negative return                           277   0.5%  97.94% /  99.23%     
1062119028    1.06G   0.1%
noreturn call                            2372   4.4% 100.00% / 100.00%     
8356562323    8.36G   0.8%
overflow                                 1282   2.4% 100.00% / 100.00%      
175074177  175.07M   0.0%
zero-sized array                          677   1.3% 100.00% / 100.00%      
112723803  112.72M   0.0%
unconditional jump                        103   0.2% 100.00% / 100.00%         
491001  491.00K   0.0%

Martin
>From fc40cf57a5b822558d32182b9937ba6dafd62377 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Thu, 2 Jun 2016 13:15:08 +0200
Subject: [PATCH 3/4] Add sorting support to analyze_brprob script

contrib/ChangeLog:

2016-06-08  Martin Liska  <mli...@suse.cz>

	* analyze_brprob.py: Add new argument --sorting.
---
 contrib/analyze_brprob.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/contrib/analyze_brprob.py b/contrib/analyze_brprob.py
index 9416eed..9808c46 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)
-- 
2.8.3

Reply via email to