info.py revision 1329:1e7bd1684f64
16657Snate@binkert.orgfrom __future__ import division 26657Snate@binkert.orgimport operator, re, types 36657Snate@binkert.org 46657Snate@binkert.orgsource = None 56657Snate@binkert.orgdisplay_run = 0 66657Snate@binkert.orgglobal globalTicks 76657Snate@binkert.orgglobalTicks = None 86657Snate@binkert.org 96657Snate@binkert.orgdef issequence(t): 106657Snate@binkert.org return isinstance(t, types.TupleType) or isinstance(t, types.ListType) 116657Snate@binkert.org 126657Snate@binkert.orgdef total(f): 136657Snate@binkert.org if isinstance(f, FormulaStat): 146657Snate@binkert.org v = f.value 156657Snate@binkert.org else: 166657Snate@binkert.org v = f 176657Snate@binkert.org 186657Snate@binkert.org f = FormulaStat() 196657Snate@binkert.org if issequence(v): 206657Snate@binkert.org f.value = reduce(operator.add, v) 216657Snate@binkert.org else: 226657Snate@binkert.org f.value = v 236657Snate@binkert.org 246657Snate@binkert.org return f 256657Snate@binkert.org 266657Snate@binkert.orgdef unaryop(op, f): 276657Snate@binkert.org if isinstance(f, FormulaStat): 286999Snate@binkert.org v = f.value 296657Snate@binkert.org else: 306657Snate@binkert.org v = f 316657Snate@binkert.org 326657Snate@binkert.org if issequence(v): 336657Snate@binkert.org return map(op, v) 346657Snate@binkert.org else: 356657Snate@binkert.org return op(v) 366657Snate@binkert.org 376657Snate@binkert.orgdef zerodiv(lv, rv): 386657Snate@binkert.org if rv == 0.0: 396657Snate@binkert.org return 0.0 406657Snate@binkert.org else: 416657Snate@binkert.org return operator.truediv(lv, rv) 426657Snate@binkert.org 436657Snate@binkert.orgdef wrapop(op, lv, rv): 446657Snate@binkert.org if isinstance(lv, str): 456657Snate@binkert.org return lv 466657Snate@binkert.org 476657Snate@binkert.org if isinstance(rv, str): 486657Snate@binkert.org return rv 496657Snate@binkert.org 506657Snate@binkert.org return op(lv, rv) 516657Snate@binkert.org 526657Snate@binkert.orgdef same(lrun, rrun): 536657Snate@binkert.org for lx,rx in zip(lrun.keys(),rrun.keys()): 546882SBrad.Beckmann@amd.com if lx != rx: 556657Snate@binkert.org print 'lx != rx' 566657Snate@binkert.org print lx, rx 576657Snate@binkert.org print lrun.keys() 586657Snate@binkert.org print rrun.keys() 596657Snate@binkert.org return False 606657Snate@binkert.org for ly,ry in zip(lrun[lx].keys(),rrun[rx].keys()): 616657Snate@binkert.org if ly != ry: 626657Snate@binkert.org print 'ly != ry' 636657Snate@binkert.org print ly, ry 646657Snate@binkert.org print lrun[lx].keys() 656657Snate@binkert.org print rrun[rx].keys() 666657Snate@binkert.org return False 676657Snate@binkert.org return True 686657Snate@binkert.org 696657Snate@binkert.org 706657Snate@binkert.orgdef binaryop(op, lf, rf): 716657Snate@binkert.org result = {} 726657Snate@binkert.org 736657Snate@binkert.org if isinstance(lf, FormulaStat) and isinstance(rf, FormulaStat): 746657Snate@binkert.org lv = lf.value 756657Snate@binkert.org rv = rf.value 766657Snate@binkert.org 776657Snate@binkert.org theruns = [] 786657Snate@binkert.org for r in lv.keys(): 796657Snate@binkert.org if rv.has_key(r): 806657Snate@binkert.org if same(lv[r], rv[r]): 816657Snate@binkert.org theruns.append(r) 826657Snate@binkert.org else: 836657Snate@binkert.org raise AttributeError 846657Snate@binkert.org 856657Snate@binkert.org for run in theruns: 866657Snate@binkert.org result[run] = {} 876657Snate@binkert.org for x in lv[run].keys(): 886657Snate@binkert.org result[run][x] = {} 896657Snate@binkert.org for y in lv[run][x].keys(): 906657Snate@binkert.org result[run][x][y] = wrapop(op, lv[run][x][y], 916657Snate@binkert.org rv[run][x][y]) 926657Snate@binkert.org elif isinstance(lf, FormulaStat): 936657Snate@binkert.org lv = lf.value 946657Snate@binkert.org for run in lv.keys(): 956657Snate@binkert.org result[run] = {} 966657Snate@binkert.org for x in lv[run].keys(): 976657Snate@binkert.org result[run][x] = {} 986657Snate@binkert.org for y in lv[run][x].keys(): 996657Snate@binkert.org result[run][x][y] = wrapop(op, lv[run][x][y], rf) 1006657Snate@binkert.org elif isinstance(rf, FormulaStat): 1016657Snate@binkert.org rv = rf.value 1026657Snate@binkert.org for run in rv.keys(): 1038086SBrad.Beckmann@amd.com result[run] = {} 1048086SBrad.Beckmann@amd.com for x in rv[run].keys(): 1058086SBrad.Beckmann@amd.com result[run][x] = {} 1066657Snate@binkert.org for y in rv[run][x].keys(): 1076657Snate@binkert.org result[run][x][y] = wrapop(op, lf, rv[run][x][y]) 1086657Snate@binkert.org 1096657Snate@binkert.org return result 1109298Snilay@cs.wisc.edu 1116657Snate@binkert.orgdef sums(x, y): 1126657Snate@binkert.org if issequence(x): 1136657Snate@binkert.org return map(lambda x, y: x + y, x, y) 1146657Snate@binkert.org else: 1156657Snate@binkert.org return x + y 1166657Snate@binkert.org 1176657Snate@binkert.orgdef alltrue(list): 1186657Snate@binkert.org return reduce(lambda x, y: x and y, list) 1196657Snate@binkert.org 1206657Snate@binkert.orgdef allfalse(list): 1216657Snate@binkert.org return not reduce(lambda x, y: x or y, list) 1226657Snate@binkert.org 1236657Snate@binkert.orgdef enumerate(list): 1246657Snate@binkert.org return map(None, range(len(list)), list) 1256657Snate@binkert.org 1266657Snate@binkert.orgdef cmp(a, b): 1276657Snate@binkert.org if a < b: 1286657Snate@binkert.org return -1 1296657Snate@binkert.org elif a == b: 1306657Snate@binkert.org return 0 1316657Snate@binkert.org else: 1326657Snate@binkert.org return 1 1336657Snate@binkert.org 1346657Snate@binkert.orgclass Statistic(object): 1356657Snate@binkert.org 1366657Snate@binkert.org def __init__(self, data): 1376657Snate@binkert.org self.__dict__.update(data.__dict__) 1386657Snate@binkert.org if not self.__dict__.has_key('value'): 1396657Snate@binkert.org self.__dict__['value'] = None 1406657Snate@binkert.org if not self.__dict__.has_key('bins'): 1416657Snate@binkert.org self.__dict__['bins'] = None 1426657Snate@binkert.org if not self.__dict__.has_key('ticks'): 1436657Snate@binkert.org self.__dict__['ticks'] = None 1446657Snate@binkert.org if 'vc' not in self.__dict__: 1456657Snate@binkert.org self.vc = {} 1466657Snate@binkert.org 1479298Snilay@cs.wisc.edu def __getattribute__(self, attr): 1486657Snate@binkert.org if attr == 'ticks': 1496657Snate@binkert.org if self.__dict__['ticks'] != globalTicks: 1506657Snate@binkert.org self.__dict__['value'] = None 1516657Snate@binkert.org self.__dict__['ticks'] = globalTicks 1526657Snate@binkert.org return self.__dict__['ticks'] 1536657Snate@binkert.org if attr == 'value': 1546657Snate@binkert.org if self.__dict__['ticks'] != globalTicks: 1556657Snate@binkert.org if self.__dict__['ticks'] != None and \ 1566657Snate@binkert.org len(self.__dict__['ticks']) == 1: 1576657Snate@binkert.org self.vc[self.__dict__['ticks'][0]] = self.__dict__['value'] 1586657Snate@binkert.org self.__dict__['ticks'] = globalTicks 1596657Snate@binkert.org if len(globalTicks) == 1 and self.vc.has_key(globalTicks[0]): 1606657Snate@binkert.org self.__dict__['value'] = self.vc[globalTicks[0]] 1616657Snate@binkert.org else: 1626882SBrad.Beckmann@amd.com self.__dict__['value'] = None 1636882SBrad.Beckmann@amd.com if self.__dict__['value'] == None: 1646882SBrad.Beckmann@amd.com self.__dict__['value'] = self.getValue() 1658086SBrad.Beckmann@amd.com return self.__dict__['value'] 1668086SBrad.Beckmann@amd.com else: 1678086SBrad.Beckmann@amd.com return super(Statistic, self).__getattribute__(attr) 1689298Snilay@cs.wisc.edu 1696657Snate@binkert.org def __setattr__(self, attr, value): 1706657Snate@binkert.org if attr == 'bins' or attr == 'ticks': 1716657Snate@binkert.org if attr == 'bins': 1726657Snate@binkert.org if value is not None: 1736657Snate@binkert.org value = source.getBin(value) 1746657Snate@binkert.org #elif attr == 'ticks' and type(value) is str: 1756657Snate@binkert.org # value = [ int(x) for x in value.split() ] 1769298Snilay@cs.wisc.edu 1779298Snilay@cs.wisc.edu self.__dict__[attr] = value 1789298Snilay@cs.wisc.edu self.__dict__['value'] = None 1799298Snilay@cs.wisc.edu self.vc = {} 1809298Snilay@cs.wisc.edu else: 1819298Snilay@cs.wisc.edu super(Statistic, self).__setattr__(attr, value) 1829298Snilay@cs.wisc.edu 1839298Snilay@cs.wisc.edu def getValue(self): 1849298Snilay@cs.wisc.edu raise AttributeError, 'getValue() must be defined' 1859298Snilay@cs.wisc.edu 1869298Snilay@cs.wisc.edu def zero(self): 1879298Snilay@cs.wisc.edu return False 1886657Snate@binkert.org 1896657Snate@binkert.org def __ne__(self, other): 1906657Snate@binkert.org return not (self == other) 1916657Snate@binkert.org 1926657Snate@binkert.org def __str__(self): 1936657Snate@binkert.org return '%f' % (float(self)) 1946657Snate@binkert.org 1956657Snate@binkert.orgclass FormulaStat(object): 1966657Snate@binkert.org def __add__(self, other): 1976657Snate@binkert.org f = FormulaStat() 1986657Snate@binkert.org f.value = binaryop(operator.add, self, other) 1999219Spower.jg@gmail.com return f 2006657Snate@binkert.org def __sub__(self, other): 2016657Snate@binkert.org f = FormulaStat() 2026657Snate@binkert.org f.value = binaryop(operator.sub, self, other) 2036657Snate@binkert.org return f 2046657Snate@binkert.org def __mul__(self, other): 2056657Snate@binkert.org f = FormulaStat() 2066657Snate@binkert.org f.value = binaryop(operator.mul, self, other) 2076657Snate@binkert.org return f 2086657Snate@binkert.org def __truediv__(self, other): 2096657Snate@binkert.org f = FormulaStat() 2106657Snate@binkert.org f.value = binaryop(zerodiv, self, other) 2116657Snate@binkert.org return f 2126999Snate@binkert.org def __mod__(self, other): 2136657Snate@binkert.org f = FormulaStat() 2146657Snate@binkert.org f.value = binaryop(operator.mod, self, other) 2156657Snate@binkert.org return f 2166657Snate@binkert.org def __radd__(self, other): 2176657Snate@binkert.org f = FormulaStat() 2186657Snate@binkert.org f.value = binaryop(operator.add, other, self) 2196657Snate@binkert.org return f 2207007Snate@binkert.org def __rsub__(self, other): 2217007Snate@binkert.org f = FormulaStat() 2226657Snate@binkert.org f.value = binaryop(operator.sub, other, self) 2237002Snate@binkert.org return f 2247002Snate@binkert.org def __rmul__(self, other): 2256657Snate@binkert.org f = FormulaStat() 2266657Snate@binkert.org f.value = binaryop(operator.mul, other, self) 2276657Snate@binkert.org return f 2286657Snate@binkert.org def __rtruediv__(self, other): 2296657Snate@binkert.org f = FormulaStat() 2306657Snate@binkert.org f.value = binaryop(zerodiv, other, self) 2316657Snate@binkert.org return f 2326657Snate@binkert.org def __rmod__(self, other): 2336657Snate@binkert.org f = FormulaStat() 2346657Snate@binkert.org f.value = binaryop(operator.mod, other, self) 2356657Snate@binkert.org return f 2366657Snate@binkert.org def __neg__(self): 2376657Snate@binkert.org f = FormulaStat() 2387007Snate@binkert.org f.value = unaryop(operator.neg, self) 2397007Snate@binkert.org return f 2406657Snate@binkert.org def __getitem__(self, idx): 2416657Snate@binkert.org f = FormulaStat() 2427007Snate@binkert.org f.value = {} 2436657Snate@binkert.org for key in self.value.keys(): 2446657Snate@binkert.org f.value[key] = {} 2456657Snate@binkert.org f.value[key][0] = {} 2466657Snate@binkert.org f.value[key][0][0] = self.value[key][idx][0] 2476657Snate@binkert.org return f 2486657Snate@binkert.org 2496657Snate@binkert.org def __float__(self): 2506657Snate@binkert.org if isinstance(self.value, FormulaStat): 2516657Snate@binkert.org return float(self.value) 2526657Snate@binkert.org if not self.value.has_key(display_run): 2536657Snate@binkert.org return (1e300*1e300) 2546657Snate@binkert.org if len(self.value[display_run]) == 1: 2556657Snate@binkert.org return self.value[display_run][0][0] 2566657Snate@binkert.org else: 2576657Snate@binkert.org #print self.value[display_run] 2586657Snate@binkert.org return self.value[display_run][4][0] 2596657Snate@binkert.org #raise ValueError 2606657Snate@binkert.org 2616657Snate@binkert.org def display(self): 2627453Snate@binkert.org import display 2637453Snate@binkert.org d = display.VectorDisplay() 2647453Snate@binkert.org d.flags = 0 2657453Snate@binkert.org d.precision = 1 2667453Snate@binkert.org d.name = 'formula' 2677453Snate@binkert.org d.desc = 'formula' 2687453Snate@binkert.org val = self.value[display_run] 2697453Snate@binkert.org d.value = [ val[x][0] for x in val.keys() ] 2707453Snate@binkert.org d.display() 2717453Snate@binkert.org 2727453Snate@binkert.org 2737453Snate@binkert.orgclass Scalar(Statistic,FormulaStat): 2747453Snate@binkert.org def getValue(self): 2757453Snate@binkert.org return source.data(self, self.bins, self.ticks) 2767453Snate@binkert.org 2777453Snate@binkert.org def display(self): 2787453Snate@binkert.org import display 2796657Snate@binkert.org p = display.Print() 2806657Snate@binkert.org p.name = self.name 2816657Snate@binkert.org p.desc = self.desc 2826657Snate@binkert.org p.value = float(self) 2836657Snate@binkert.org p.flags = self.flags 2846657Snate@binkert.org p.precision = self.precision 2856657Snate@binkert.org if display.all or (self.flags & flags.printable): 2866657Snate@binkert.org p.display() 2876657Snate@binkert.org 2886657Snate@binkert.org def comparable(self, other): 2896657Snate@binkert.org return self.name == other.name 2906657Snate@binkert.org 2916657Snate@binkert.org def __eq__(self, other): 2926657Snate@binkert.org return self.value == other.value 2936657Snate@binkert.org 2946657Snate@binkert.org def __isub__(self, other): 2956657Snate@binkert.org self.value -= other.value 2966657Snate@binkert.org return self 2976657Snate@binkert.org 2986657Snate@binkert.org def __iadd__(self, other): 2996657Snate@binkert.org self.value += other.value 3006657Snate@binkert.org return self 3017453Snate@binkert.org 3027453Snate@binkert.org def __itruediv__(self, other): 3037453Snate@binkert.org if not other: 3047007Snate@binkert.org return self 3057007Snate@binkert.org self.value /= other 3066657Snate@binkert.org return self 3076657Snate@binkert.org 3086657Snate@binkert.orgclass Vector(Statistic,FormulaStat): 3097453Snate@binkert.org def getValue(self): 3107007Snate@binkert.org return source.data(self, self.bins); 3117007Snate@binkert.org 3127453Snate@binkert.org def display(self): 3137007Snate@binkert.org import display 3146657Snate@binkert.org if not display.all and not (self.flags & flags.printable): 3156657Snate@binkert.org return 3166657Snate@binkert.org 3176657Snate@binkert.org d = display.VectorDisplay() 3186657Snate@binkert.org d.__dict__.update(self.__dict__) 3196657Snate@binkert.org d.display() 3206657Snate@binkert.org 3216657Snate@binkert.org def comparable(self, other): 3226657Snate@binkert.org return self.name == other.name and \ 3236657Snate@binkert.org len(self.value) == len(other.value) 3247007Snate@binkert.org 3257007Snate@binkert.org def __eq__(self, other): 3267007Snate@binkert.org if issequence(self.value) != issequence(other.value): 3277007Snate@binkert.org return false 3287007Snate@binkert.org 3296657Snate@binkert.org if issequence(self.value): 3306657Snate@binkert.org if len(self.value) != len(other.value): 3316657Snate@binkert.org return False 3326657Snate@binkert.org else: 3336657Snate@binkert.org for v1,v2 in zip(self.value, other.value): 3346657Snate@binkert.org if v1 != v2: 3356657Snate@binkert.org return False 3366657Snate@binkert.org return True 3376657Snate@binkert.org else: 3387007Snate@binkert.org return self.value == other.value 3397007Snate@binkert.org 3407007Snate@binkert.org def __isub__(self, other): 3417007Snate@binkert.org self.value = binaryop(operator.sub, self.value, other.value) 3427007Snate@binkert.org return self 3436657Snate@binkert.org 3446657Snate@binkert.org def __iadd__(self, other): 3456657Snate@binkert.org self.value = binaryop(operator.add, self.value, other.value) 3466657Snate@binkert.org return self 3476657Snate@binkert.org 3486657Snate@binkert.org def __itruediv__(self, other): 3496657Snate@binkert.org if not other: 3507007Snate@binkert.org return self 3517007Snate@binkert.org if issequence(self.value): 3527007Snate@binkert.org for i in xrange(len(self.value)): 3537007Snate@binkert.org self.value[i] /= other 3547007Snate@binkert.org else: 3556657Snate@binkert.org self.value /= other 3566657Snate@binkert.org return self 3577002Snate@binkert.org 3586657Snate@binkert.orgclass Formula(Vector): 3596657Snate@binkert.org def getValue(self): 3606657Snate@binkert.org formula = re.sub(':', '__', self.formula) 3616657Snate@binkert.org x = eval(formula, source.stattop) 3626657Snate@binkert.org return x.value 3636657Snate@binkert.org 3646657Snate@binkert.org def comparable(self, other): 3656657Snate@binkert.org return self.name == other.name and \ 3666657Snate@binkert.org compare(self.dist, other.dist) 3676657Snate@binkert.org 3686657Snate@binkert.org def __eq__(self, other): 3696657Snate@binkert.org return self.value == other.value 3706657Snate@binkert.org 3716657Snate@binkert.org def __isub__(self, other): 3726657Snate@binkert.org return self 3736657Snate@binkert.org 3746657Snate@binkert.org def __iadd__(self, other): 3756657Snate@binkert.org return self 3766657Snate@binkert.org 3776657Snate@binkert.org def __itruediv__(self, other): 3786657Snate@binkert.org if not other: 3797007Snate@binkert.org return self 3806657Snate@binkert.org return self 3817007Snate@binkert.org 3826657Snate@binkert.orgclass SimpleDist(object): 3839298Snilay@cs.wisc.edu def __init__(self, sums, squares, samples): 3849298Snilay@cs.wisc.edu self.sums = sums 3859298Snilay@cs.wisc.edu self.squares = squares 3869298Snilay@cs.wisc.edu self.samples = samples 3879298Snilay@cs.wisc.edu 3889298Snilay@cs.wisc.edu def getValue(self): 3896657Snate@binkert.org return 0.0 3906657Snate@binkert.org 3916657Snate@binkert.org def display(self, name, desc, flags, precision): 3926657Snate@binkert.org import display 3937055Snate@binkert.org p = display.Print() 3947007Snate@binkert.org p.flags = flags 3956657Snate@binkert.org p.precision = precision 3966657Snate@binkert.org 3977002Snate@binkert.org if self.samples > 0: 3986657Snate@binkert.org p.name = name + ".mean" 3996657Snate@binkert.org p.value = self.sums / self.samples 4006657Snate@binkert.org p.display() 4017007Snate@binkert.org 4026657Snate@binkert.org p.name = name + ".stdev" 4036657Snate@binkert.org if self.samples > 1: 4046657Snate@binkert.org var = (self.samples * self.squares - self.sums ** 2) \ 4056657Snate@binkert.org / (self.samples * (self.samples - 1)) 4066657Snate@binkert.org if var >= 0: 4076999Snate@binkert.org p.value = math.sqrt(var) 4086657Snate@binkert.org else: 4096657Snate@binkert.org p.value = 'NaN' 4106657Snate@binkert.org else: 4116657Snate@binkert.org p.value = 0.0 4126657Snate@binkert.org p.display() 4136657Snate@binkert.org 4146657Snate@binkert.org p.name = name + ".samples" 4157002Snate@binkert.org p.value = self.samples 4167002Snate@binkert.org p.display() 4176657Snate@binkert.org 4187002Snate@binkert.org def comparable(self, other): 4197002Snate@binkert.org return True 4206657Snate@binkert.org 4216657Snate@binkert.org def __eq__(self, other): 4226657Snate@binkert.org return self.sums == other.sums and self.squares == other.squares and \ 4236657Snate@binkert.org self.samples == other.samples 4247007Snate@binkert.org 4257007Snate@binkert.org def __isub__(self, other): 4266657Snate@binkert.org self.sums -= other.sums 4276657Snate@binkert.org self.squares -= other.squares 4286657Snate@binkert.org self.samples -= other.samples 4296657Snate@binkert.org return self 4306657Snate@binkert.org 4316657Snate@binkert.org def __iadd__(self, other): 4326657Snate@binkert.org self.sums += other.sums 4336657Snate@binkert.org self.squares += other.squares 4346657Snate@binkert.org self.samples += other.samples 4356657Snate@binkert.org return self 4369206Snilay@cs.wisc.edu 4376657Snate@binkert.org def __itruediv__(self, other): 4386657Snate@binkert.org if not other: 4396657Snate@binkert.org return self 4406657Snate@binkert.org self.sums /= other 4416657Snate@binkert.org self.squares /= other 4426657Snate@binkert.org self.samples /= other 4436657Snate@binkert.org return self 4449298Snilay@cs.wisc.edu 4459298Snilay@cs.wisc.educlass FullDist(SimpleDist): 4469298Snilay@cs.wisc.edu def __init__(self, sums, squares, samples, minval, maxval, 4479298Snilay@cs.wisc.edu under, vec, over, min, max, bsize, size): 4486657Snate@binkert.org self.sums = sums 4496657Snate@binkert.org self.squares = squares 4506657Snate@binkert.org self.samples = samples 4516999Snate@binkert.org self.minval = minval 4526657Snate@binkert.org self.maxval = maxval 4536657Snate@binkert.org self.under = under 4546657Snate@binkert.org self.vec = vec 4556657Snate@binkert.org self.over = over 4566657Snate@binkert.org self.min = min 4577007Snate@binkert.org self.max = max 4587007Snate@binkert.org self.bsize = bsize 4597007Snate@binkert.org self.size = size 4606657Snate@binkert.org 4617002Snate@binkert.org def getValue(self): 4627002Snate@binkert.org return 0.0 4637002Snate@binkert.org 4648086SBrad.Beckmann@amd.com def display(self, name, desc, flags, precision): 4658086SBrad.Beckmann@amd.com import display 4668086SBrad.Beckmann@amd.com p = display.Print() 4678086SBrad.Beckmann@amd.com p.flags = flags 4688602Snilay@cs.wisc.edu p.precision = precision 4698602Snilay@cs.wisc.edu 4708602Snilay@cs.wisc.edu p.name = name + '.min_val' 4718602Snilay@cs.wisc.edu p.value = self.minval 4728602Snilay@cs.wisc.edu p.display() 4738602Snilay@cs.wisc.edu 4748086SBrad.Beckmann@amd.com p.name = name + '.max_val' 4756657Snate@binkert.org p.value = self.maxval 4767007Snate@binkert.org p.display() 4776657Snate@binkert.org 4786657Snate@binkert.org p.name = name + '.underflow' 4796657Snate@binkert.org p.value = self.under 4806657Snate@binkert.org p.display() 4816657Snate@binkert.org 4826657Snate@binkert.org i = self.min 4836657Snate@binkert.org for val in self.vec[:-1]: 4846657Snate@binkert.org p.name = name + '[%d:%d]' % (i, i + self.bsize - 1) 4856657Snate@binkert.org p.value = val 4866657Snate@binkert.org p.display() 4876657Snate@binkert.org i += self.bsize 4886862Sdrh5@cs.wisc.edu 4896862Sdrh5@cs.wisc.edu p.name = name + '[%d:%d]' % (i, self.max) 4906862Sdrh5@cs.wisc.edu p.value = self.vec[-1] 4916862Sdrh5@cs.wisc.edu p.display() 4926657Snate@binkert.org 4936657Snate@binkert.org 4946657Snate@binkert.org p.name = name + '.overflow' 4956657Snate@binkert.org p.value = self.over 4966657Snate@binkert.org p.display() 4977007Snate@binkert.org 4987007Snate@binkert.org SimpleDist.display(self, name, desc, flags, precision) 4997002Snate@binkert.org 5007007Snate@binkert.org def comparable(self, other): 5017007Snate@binkert.org return self.min == other.min and self.max == other.max and \ 5027002Snate@binkert.org self.bsize == other.bsize and self.size == other.size 5037007Snate@binkert.org 5047007Snate@binkert.org def __eq__(self, other): 5056657Snate@binkert.org return self.sums == other.sums and self.squares == other.squares and \ 5066657Snate@binkert.org self.samples == other.samples 5076657Snate@binkert.org 5086657Snate@binkert.org def __isub__(self, other): 5096657Snate@binkert.org self.sums -= other.sums 5106657Snate@binkert.org self.squares -= other.squares 5116657Snate@binkert.org self.samples -= other.samples 5126657Snate@binkert.org 5136657Snate@binkert.org if other.samples: 5146657Snate@binkert.org self.minval = min(self.minval, other.minval) 5156657Snate@binkert.org self.maxval = max(self.maxval, other.maxval) 5166657Snate@binkert.org self.under -= under 5176657Snate@binkert.org self.vec = map(lambda x,y: x - y, self.vec, other.vec) 5188602Snilay@cs.wisc.edu self.over -= over 5198602Snilay@cs.wisc.edu return self 5208602Snilay@cs.wisc.edu 5218602Snilay@cs.wisc.edu def __iadd__(self, other): 5228602Snilay@cs.wisc.edu if not self.samples and other.samples: 5238602Snilay@cs.wisc.edu self = other 5248602Snilay@cs.wisc.edu return self 5258602Snilay@cs.wisc.edu 5268602Snilay@cs.wisc.edu self.sums += other.sums 5278602Snilay@cs.wisc.edu self.squares += other.squares 5288602Snilay@cs.wisc.edu self.samples += other.samples 5298602Snilay@cs.wisc.edu 5308602Snilay@cs.wisc.edu if other.samples: 5318602Snilay@cs.wisc.edu self.minval = min(self.minval, other.minval) 5328602Snilay@cs.wisc.edu self.maxval = max(self.maxval, other.maxval) 5338602Snilay@cs.wisc.edu self.under += other.under 5348602Snilay@cs.wisc.edu self.vec = map(lambda x,y: x + y, self.vec, other.vec) 5358602Snilay@cs.wisc.edu self.over += other.over 5368602Snilay@cs.wisc.edu return self 5378602Snilay@cs.wisc.edu 5388602Snilay@cs.wisc.edu def __itruediv__(self, other): 5398602Snilay@cs.wisc.edu if not other: 5408602Snilay@cs.wisc.edu return self 5416657Snate@binkert.org self.sums /= other 5428086SBrad.Beckmann@amd.com self.squares /= other 5438086SBrad.Beckmann@amd.com self.samples /= other 5448086SBrad.Beckmann@amd.com 5458086SBrad.Beckmann@amd.com if self.samples: 5468086SBrad.Beckmann@amd.com self.under /= other 5478086SBrad.Beckmann@amd.com for i in xrange(len(self.vec)): 5488086SBrad.Beckmann@amd.com self.vec[i] /= other 5498086SBrad.Beckmann@amd.com self.over /= other 5506657Snate@binkert.org return self 5516657Snate@binkert.org 5527002Snate@binkert.orgclass Dist(Statistic): 5536657Snate@binkert.org def getValue(self): 5547007Snate@binkert.org return 0.0 5556657Snate@binkert.org 5566657Snate@binkert.org def display(self): 5576657Snate@binkert.org import display 5586657Snate@binkert.org if not display.all and not (self.flags & flags.printable): 5596657Snate@binkert.org return 5606999Snate@binkert.org 5616657Snate@binkert.org self.dist.display(self.name, self.desc, self.flags, self.precision) 5626657Snate@binkert.org 5636657Snate@binkert.org def comparable(self, other): 5646657Snate@binkert.org return self.name == other.name and \ 5656657Snate@binkert.org self.dist.compareable(other.dist) 5666657Snate@binkert.org 5677832Snate@binkert.org def __eq__(self, other): 5687002Snate@binkert.org return self.dist == other.dist 5697002Snate@binkert.org 5707002Snate@binkert.org def __isub__(self, other): 5717805Snilay@cs.wisc.edu self.dist -= other.dist 5726657Snate@binkert.org return self 5736657Snate@binkert.org 5747002Snate@binkert.org def __iadd__(self, other): 5757002Snate@binkert.org self.dist += other.dist 5766657Snate@binkert.org return self 5776657Snate@binkert.org 5788086SBrad.Beckmann@amd.com def __itruediv__(self, other): 5798086SBrad.Beckmann@amd.com if not other: 5808086SBrad.Beckmann@amd.com return self 5818086SBrad.Beckmann@amd.com self.dist /= other 5828086SBrad.Beckmann@amd.com return self 5838086SBrad.Beckmann@amd.com 5848086SBrad.Beckmann@amd.comclass VectorDist(Statistic): 5858086SBrad.Beckmann@amd.com def getValue(self): 5868086SBrad.Beckmann@amd.com return 0.0 5878086SBrad.Beckmann@amd.com 5888086SBrad.Beckmann@amd.com def display(self): 5898086SBrad.Beckmann@amd.com import display 5908086SBrad.Beckmann@amd.com if not display.all and not (self.flags & flags.printable): 5918086SBrad.Beckmann@amd.com return 5928086SBrad.Beckmann@amd.com 5938086SBrad.Beckmann@amd.com if isinstance(self.dist, SimpleDist): 5948086SBrad.Beckmann@amd.com return 5958086SBrad.Beckmann@amd.com 5968086SBrad.Beckmann@amd.com for dist,sn,sd,i in map(None, self.dist, self.subnames, self.subdescs, 5978086SBrad.Beckmann@amd.com range(len(self.dist))): 5988086SBrad.Beckmann@amd.com if len(sn) > 0: 5996657Snate@binkert.org name = '%s.%s' % (self.name, sn) 6006657Snate@binkert.org else: 6016657Snate@binkert.org name = '%s[%d]' % (self.name, i) 6028602Snilay@cs.wisc.edu 6036657Snate@binkert.org if len(sd) > 0: 6046657Snate@binkert.org desc = sd 6057007Snate@binkert.org else: 6067007Snate@binkert.org desc = self.desc 6077007Snate@binkert.org 6086657Snate@binkert.org dist.display(name, desc, self.flags, self.precision) 6096657Snate@binkert.org 6106657Snate@binkert.org if (self.flags & flags.total) or 1: 6116657Snate@binkert.org if isinstance(self.dist[0], SimpleDist): 6126657Snate@binkert.org disttotal = SimpleDist( \ 6136657Snate@binkert.org reduce(sums, [d.sums for d in self.dist]), 6147007Snate@binkert.org reduce(sums, [d.squares for d in self.dist]), 6157007Snate@binkert.org reduce(sums, [d.samples for d in self.dist])) 6167007Snate@binkert.org else: 6176657Snate@binkert.org disttotal = FullDist( \ 6186657Snate@binkert.org reduce(sums, [d.sums for d in self.dist]), 6196657Snate@binkert.org reduce(sums, [d.squares for d in self.dist]), 6206657Snate@binkert.org reduce(sums, [d.samples for d in self.dist]), 6216657Snate@binkert.org min([d.minval for d in self.dist]), 6226657Snate@binkert.org max([d.maxval for d in self.dist]), 6236657Snate@binkert.org reduce(sums, [d.under for d in self.dist]), 6246657Snate@binkert.org reduce(sums, [d.vec for d in self.dist]), 6256657Snate@binkert.org reduce(sums, [d.over for d in self.dist]), 6266657Snate@binkert.org dist[0].min, 6276657Snate@binkert.org dist[0].max, 6286657Snate@binkert.org dist[0].bsize, 6296657Snate@binkert.org dist[0].size) 6306657Snate@binkert.org 6317805Snilay@cs.wisc.edu name = '%s.total' % (self.name) 6326657Snate@binkert.org desc = self.desc 6336657Snate@binkert.org disttotal.display(name, desc, self.flags, self.precision) 6346657Snate@binkert.org 6357007Snate@binkert.org def comparable(self, other): 6367007Snate@binkert.org return self.name == other.name and \ 6377007Snate@binkert.org alltrue(map(lambda x, y : x.comparable(y), 6386657Snate@binkert.org self.dist, 6396657Snate@binkert.org other.dist)) 6406657Snate@binkert.org 6416657Snate@binkert.org def __eq__(self, other): 6427007Snate@binkert.org return alltrue(map(lambda x, y : x == y, self.dist, other.dist)) 6436657Snate@binkert.org 6446657Snate@binkert.org def __isub__(self, other): 6456657Snate@binkert.org if issequence(self.dist) and issequence(other.dist): 6466657Snate@binkert.org for sd,od in zip(self.dist, other.dist): 6477007Snate@binkert.org sd -= od 6486657Snate@binkert.org else: 6496657Snate@binkert.org self.dist -= other.dist 6506657Snate@binkert.org return self 6516657Snate@binkert.org 6527805Snilay@cs.wisc.edu def __iadd__(self, other): 6536657Snate@binkert.org if issequence(self.dist) and issequence(other.dist): 6546657Snate@binkert.org for sd,od in zip(self.dist, other.dist): 6556657Snate@binkert.org sd += od 6567007Snate@binkert.org else: 6577007Snate@binkert.org self.dist += other.dist 6587007Snate@binkert.org return self 6597007Snate@binkert.org 6606657Snate@binkert.org def __itruediv__(self, other): 6616657Snate@binkert.org if not other: 6626657Snate@binkert.org return self 6636657Snate@binkert.org if issequence(self.dist): 6646657Snate@binkert.org for dist in self.dist: 6656657Snate@binkert.org dist /= other 6666657Snate@binkert.org else: 6676657Snate@binkert.org self.dist /= other 6686657Snate@binkert.org return self 6697007Snate@binkert.org 6707007Snate@binkert.orgclass Vector2d(Statistic): 6716657Snate@binkert.org def getValue(self): 6726657Snate@binkert.org return 0.0 6736657Snate@binkert.org 6746657Snate@binkert.org def display(self): 6757007Snate@binkert.org import display 6767007Snate@binkert.org if not display.all and not (self.flags & flags.printable): 6776657Snate@binkert.org return 6786657Snate@binkert.org 6796657Snate@binkert.org d = display.VectorDisplay() 6806657Snate@binkert.org d.__dict__.update(self.__dict__) 6816657Snate@binkert.org 6826657Snate@binkert.org if self.__dict__.has_key('ysubnames'): 6836657Snate@binkert.org ysubnames = list(self.ysubnames) 6846657Snate@binkert.org slack = self.x - len(ysubnames) 6856657Snate@binkert.org if slack > 0: 6866657Snate@binkert.org ysubnames.extend(['']*slack) 6876657Snate@binkert.org else: 6886657Snate@binkert.org ysubnames = range(self.x) 6896657Snate@binkert.org 6906657Snate@binkert.org for x,sname in enumerate(ysubnames): 6916657Snate@binkert.org o = x * self.y 6926657Snate@binkert.org d.value = self.value[o:o+self.y] 6936657Snate@binkert.org d.name = '%s[%s]' % (self.name, sname) 6947805Snilay@cs.wisc.edu d.display() 6956657Snate@binkert.org 6966657Snate@binkert.org if self.flags & flags.total: 6976657Snate@binkert.org d.value = [] 6986657Snate@binkert.org for y in range(self.y): 6996657Snate@binkert.org xtot = 0.0 7007007Snate@binkert.org for x in range(self.x): 7016657Snate@binkert.org xtot += self.value[y + x * self.x] 7027007Snate@binkert.org d.value.append(xtot) 7037007Snate@binkert.org 7046657Snate@binkert.org d.name = self.name + '.total' 7056657Snate@binkert.org d.display() 7066657Snate@binkert.org 7076657Snate@binkert.org def comparable(self, other): 7086657Snate@binkert.org return self.name == other.name and self.x == other.x and \ 7096657Snate@binkert.org self.y == other.y 7106657Snate@binkert.org 7116657Snate@binkert.org def __eq__(self, other): 7126657Snate@binkert.org return True 7136657Snate@binkert.org 7146657Snate@binkert.org def __isub__(self, other): 7156657Snate@binkert.org return self 7166657Snate@binkert.org 7176657Snate@binkert.org def __iadd__(self, other): 7187805Snilay@cs.wisc.edu return self 7196657Snate@binkert.org 7206657Snate@binkert.org def __itruediv__(self, other): 7216657Snate@binkert.org if not other: 7226657Snate@binkert.org return self 7236657Snate@binkert.org return self 7246657Snate@binkert.org 7256657Snate@binkert.orgdef NewStat(data): 7266657Snate@binkert.org stat = None 7277007Snate@binkert.org if data.type == 'SCALAR': 7287007Snate@binkert.org stat = Scalar(data) 7296657Snate@binkert.org elif data.type == 'VECTOR': 7306657Snate@binkert.org stat = Vector(data) 7316657Snate@binkert.org elif data.type == 'DIST': 7326657Snate@binkert.org stat = Dist(data) 7336657Snate@binkert.org elif data.type == 'VECTORDIST': 7346657Snate@binkert.org stat = VectorDist(data) 7356657Snate@binkert.org elif data.type == 'VECTOR2D': 7366657Snate@binkert.org stat = Vector2d(data) 7376657Snate@binkert.org elif data.type == 'FORMULA': 7386657Snate@binkert.org stat = Formula(data) 7396657Snate@binkert.org 7406657Snate@binkert.org return stat 7416657Snate@binkert.org 7426657Snate@binkert.org