1# Copyright (c) 2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Nathan Binkert 28
| 1# Copyright (c) 2005 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Nathan Binkert 28
|
29class StatOutput(object): 30 def __init__(self, name, jobfile, info, stat=None, binstats=None): 31 self.name = name
| 29from chart import ChartOptions 30 31class StatOutput(ChartOptions): 32 def __init__(self, jobfile, info, stat=None, binstats=None): 33 super(StatOutput, self).__init__()
|
32 self.jobfile = jobfile 33 self.stat = stat 34 self.binstats = None
| 34 self.jobfile = jobfile 35 self.stat = stat 36 self.binstats = None
|
35 self.label = self.name
| |
36 self.invert = False 37 self.info = info 38
| 37 self.invert = False 38 self.info = info 39
|
39 def printdata(self, bin = None, printmode = 'G'):
| 40 def printdata(self, name, bin = None, printmode = 'G'):
|
40 import info 41 42 if bin:
| 41 import info 42 43 if bin:
|
43 print '%s %s stats' % (self.name, bin)
| 44 print '%s %s stats' % (name, bin)
|
44 45 if self.binstats: 46 for stat in self.binstats: 47 stat.bins = bin 48 49 if printmode == 'G': 50 valformat = '%g' 51 elif printmode != 'F' and value > 1e6: 52 valformat = '%0.5e' 53 else: 54 valformat = '%f' 55 56 for job in self.jobfile.jobs(): 57 value = self.info.get(job, self.stat) 58 if value is None: 59 return 60 61 if not isinstance(value, list): 62 value = [ value ] 63 64 if self.invert: 65 for i,val in enumerate(value): 66 if val != 0.0: 67 value[i] = 1 / val 68 69 valstring = ', '.join([ valformat % val for val in value ]) 70 print '%-50s %s' % (job.name + ':', valstring) 71
| 45 46 if self.binstats: 47 for stat in self.binstats: 48 stat.bins = bin 49 50 if printmode == 'G': 51 valformat = '%g' 52 elif printmode != 'F' and value > 1e6: 53 valformat = '%0.5e' 54 else: 55 valformat = '%f' 56 57 for job in self.jobfile.jobs(): 58 value = self.info.get(job, self.stat) 59 if value is None: 60 return 61 62 if not isinstance(value, list): 63 value = [ value ] 64 65 if self.invert: 66 for i,val in enumerate(value): 67 if val != 0.0: 68 value[i] = 1 / val 69 70 valstring = ', '.join([ valformat % val for val in value ]) 71 print '%-50s %s' % (job.name + ':', valstring) 72
|
72 def display(self, binned = False, printmode = 'G'):
| 73 def display(self, name, binned = False, printmode = 'G'):
|
73 if binned and self.binstats:
| 74 if binned and self.binstats:
|
74 self.printdata('kernel', printmode) 75 self.printdata('idle', printmode) 76 self.printdata('user', printmode) 77 self.printdata('interrupt', printmode)
| 75 self.printdata(name, 'kernel', printmode) 76 self.printdata(name, 'idle', printmode) 77 self.printdata(name, 'user', printmode) 78 self.printdata(name, 'interrupt', printmode)
|
78
| 79
|
79 print '%s total stats' % self.name 80 self.printdata(printmode=printmode)
| 80 print '%s total stats' % name 81 self.printdata(name, printmode=printmode)
|
81
| 82
|
82 def graph(self, graphdir):
| 83 def graph(self, name, graphdir, proxy=None):
|
83 from os.path import expanduser, isdir, join as joinpath 84 from barchart import BarChart 85 from matplotlib.numerix import Float, array, zeros
| 84 from os.path import expanduser, isdir, join as joinpath 85 from barchart import BarChart 86 from matplotlib.numerix import Float, array, zeros
|
86 import os, re
| 87 import os, re, urllib 88 from jobfile import crossproduct
|
87 88 confgroups = self.jobfile.groups() 89 ngroups = len(confgroups) 90 skiplist = [ False ] * ngroups
| 89 90 confgroups = self.jobfile.groups() 91 ngroups = len(confgroups) 92 skiplist = [ False ] * ngroups
|
91 groupopts = None 92 baropts = None
| 93 groupopts = [] 94 baropts = []
|
93 groups = [] 94 for i,group in enumerate(confgroups): 95 if group.flags.graph_group:
| 95 groups = [] 96 for i,group in enumerate(confgroups): 97 if group.flags.graph_group:
|
96 if groupopts is not None: 97 raise AttributeError, \ 98 'Two groups selected for graph group' 99 groupopts = group.subopts()
| 98 groupopts.append(group.subopts())
|
100 skiplist[i] = True 101 elif group.flags.graph_bars:
| 99 skiplist[i] = True 100 elif group.flags.graph_bars:
|
102 if baropts is not None: 103 raise AttributeError, \ 104 'Two groups selected for graph bars' 105 baropts = group.subopts()
| 101 baropts.append(group.subopts())
|
106 skiplist[i] = True 107 else: 108 groups.append(group) 109
| 102 skiplist[i] = True 103 else: 104 groups.append(group) 105
|
110 if groupopts is None:
| 106 if not groupopts:
|
111 raise AttributeError, 'No group selected for graph group' 112
| 107 raise AttributeError, 'No group selected for graph group' 108
|
113 if baropts is None:
| 109 if not baropts:
|
114 raise AttributeError, 'No group selected for graph bars' 115
| 110 raise AttributeError, 'No group selected for graph bars' 111
|
| 112 groupopts = [ group for group in crossproduct(groupopts) ] 113 baropts = [ bar for bar in crossproduct(baropts) ] 114
|
116 directory = expanduser(graphdir) 117 if not isdir(directory): 118 os.mkdir(directory)
| 115 directory = expanduser(graphdir) 116 if not isdir(directory): 117 os.mkdir(directory)
|
119 html = file(joinpath(directory, '%s.html' % self.name), 'w')
| 118 html = file(joinpath(directory, '%s.html' % name), 'w')
|
120 print >>html, '<html>'
| 119 print >>html, '<html>'
|
121 print >>html, '<title>Graphs for %s</title>' % self.name
| 120 print >>html, 'Graphs for %s' % name
|
122 print >>html, '<body>'
| 121 print >>html, '<body>'
|
| 122 html.flush()
|
123 124 for options in self.jobfile.options(groups):
| 123 124 for options in self.jobfile.options(groups):
|
| 125 chart = BarChart(self) 126
|
125 data = zeros((len(groupopts), len(baropts)), Float) 126 data = [ [ None ] * len(baropts) for i in xrange(len(groupopts)) ] 127 enabled = False 128 stacked = 0 129 for g,gopt in enumerate(groupopts): 130 for b,bopt in enumerate(baropts):
| 127 data = zeros((len(groupopts), len(baropts)), Float) 128 data = [ [ None ] * len(baropts) for i in xrange(len(groupopts)) ] 129 enabled = False 130 stacked = 0 131 for g,gopt in enumerate(groupopts): 132 for b,bopt in enumerate(baropts):
|
131 job = self.jobfile.job(options + [ gopt, bopt ])
| 133 job = self.jobfile.job(options + gopt + bopt)
|
132 if not job: 133 continue 134
| 134 if not job: 135 continue 136
|
| 137 if proxy: 138 import db 139 proxy.dict['system'] = self.info[job.system]
|
135 val = self.info.get(job, self.stat)
| 140 val = self.info.get(job, self.stat)
|
| 141 if val is None: 142 print 'stat "%s" for job "%s" not found' % \ 143 (self.stat, job) 144
|
136 if isinstance(val, (list, tuple)): 137 if len(val) == 1: 138 val = val[0] 139 else: 140 stacked = len(val) 141 142 data[g][b] = val 143 144 if stacked == 0: 145 for i in xrange(len(groupopts)): 146 for j in xrange(len(baropts)): 147 if data[i][j] is None: 148 data[i][j] = 0.0 149 else: 150 for i in xrange(len(groupopts)): 151 for j in xrange(len(baropts)): 152 val = data[i][j] 153 if val is None:
| 145 if isinstance(val, (list, tuple)): 146 if len(val) == 1: 147 val = val[0] 148 else: 149 stacked = len(val) 150 151 data[g][b] = val 152 153 if stacked == 0: 154 for i in xrange(len(groupopts)): 155 for j in xrange(len(baropts)): 156 if data[i][j] is None: 157 data[i][j] = 0.0 158 else: 159 for i in xrange(len(groupopts)): 160 for j in xrange(len(baropts)): 161 val = data[i][j] 162 if val is None:
|
154 data[i][j] = [] * stacked
| 163 data[i][j] = [ 0.0 ] * stacked
|
155 elif len(val) != stacked: 156 raise ValueError, "some stats stacked, some not" 157 158 data = array(data) 159 if data.sum() == 0: 160 continue 161
| 164 elif len(val) != stacked: 165 raise ValueError, "some stats stacked, some not" 166 167 data = array(data) 168 if data.sum() == 0: 169 continue 170
|
162 bar_descs = [ opt.desc for opt in baropts ] 163 group_descs = [ opt.desc for opt in groupopts ] 164 if stacked: 165 try: 166 legend = self.info.rcategories 167 except: 168 legend = [ str(i) for i in xrange(stacked) ] 169 else: 170 legend = bar_descs
| 171 x = data.shape[0] 172 y = data.shape[1] 173 xkeep = [ i for i in xrange(x) if data[i].sum() != 0 ] 174 ykeep = [ i for i in xrange(y) if data[:,i].sum() != 0 ] 175 data = data.take(xkeep, axis=0) 176 data = data.take(ykeep, axis=1) 177 chart.data = data
|
171
| 178
|
172 chart = BarChart(data=data, xlabel='Benchmark', ylabel=self.label, 173 legend=legend, xticks=group_descs)
| 179 gopts = [ groupopts[i] for i in xkeep ] 180 bopts = [ baropts[i] for i in ykeep ] 181 182 bdescs = [ ' '.join([o.desc for o in opt]) for opt in bopts] 183 gdescs = [ ' '.join([o.desc for o in opt]) for opt in gopts] 184 185 if chart.legend is None: 186 if stacked: 187 try: 188 chart.legend = self.info.rcategories 189 except: 190 chart.legend = [ str(i) for i in xrange(stacked) ] 191 else: 192 chart.legend = bdescs 193 194 if chart.xticks is None: 195 chart.xticks = gdescs
|
174 chart.graph() 175 176 names = [ opt.name for opt in options ] 177 descs = [ opt.desc for opt in options ] 178
| 196 chart.graph() 197 198 names = [ opt.name for opt in options ] 199 descs = [ opt.desc for opt in options ] 200
|
179 filename = '%s-%s.png' % (self.name, ':'.join(names))
| 201 if names[0] == 'run': 202 names = names[1:] 203 descs = descs[1:] 204 205 basename = '%s-%s' % (name, ':'.join(names))
|
180 desc = ' '.join(descs)
| 206 desc = ' '.join(descs)
|
181 filepath = joinpath(directory, filename) 182 chart.savefig(filepath) 183 filename = re.sub(':', '%3A', filename) 184 print >>html, '''%s<br><img src="%s"><br>''' % (desc, filename)
| |
185
| 207
|
| 208 pngname = '%s.png' % basename 209 psname = '%s.eps' % re.sub(':', '-', basename) 210 epsname = '%s.ps' % re.sub(':', '-', basename) 211 chart.savefig(joinpath(directory, pngname)) 212 chart.savefig(joinpath(directory, epsname)) 213 chart.savefig(joinpath(directory, psname)) 214 html_name = urllib.quote(pngname) 215 print >>html, '''%s<br><img src="%s"><br>''' % (desc, html_name) 216 html.flush() 217
|
186 print >>html, '</body>' 187 print >>html, '</html>' 188 html.close()
| 218 print >>html, '</body>' 219 print >>html, '</html>' 220 html.close()
|