info.py revision 1369:40c6c8864896
16657Snate@binkert.orgfrom __future__ import division
26657Snate@binkert.orgimport operator, re, types
310972Sdavid.hashe@amd.com
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):
286657Snate@binkert.org        v = f.value
2913672Sandreas.sandberg@arm.com    else:
306657Snate@binkert.org        v = f
316657Snate@binkert.org
326657Snate@binkert.org    if issequence(v):
336657Snate@binkert.org        return map(op, v)
348189SLisa.Hsu@amd.com    else:
356657Snate@binkert.org        return op(v)
369499Snilay@cs.wisc.edu
379499Snilay@cs.wisc.edudef zerodiv(lv, rv):
3811308Santhony.gutierrez@amd.com    if rv == 0.0:
399364Snilay@cs.wisc.edu        return 0.0
407055Snate@binkert.org    else:
416882SBrad.Beckmann@amd.com        return operator.truediv(lv, rv)
426882SBrad.Beckmann@amd.com
438191SLisa.Hsu@amd.comdef wrapop(op, lv, rv):
446882SBrad.Beckmann@amd.com    if isinstance(lv, str):
4511308Santhony.gutierrez@amd.com        return lv
4611308Santhony.gutierrez@amd.com
476882SBrad.Beckmann@amd.com    if isinstance(rv, str):
4811308Santhony.gutierrez@amd.com        return rv
499102SNuwan.Jayasena@amd.com
5011084Snilay@cs.wisc.edu    return op(lv, rv)
519366Snilay@cs.wisc.edu
529499Snilay@cs.wisc.edudef same(lrun, rrun):
539499Snilay@cs.wisc.edu    for lx,rx in zip(lrun.keys(),rrun.keys()):
549499Snilay@cs.wisc.edu        if lx != rx:
556882SBrad.Beckmann@amd.com            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
6010311Snilay@cs.wisc.edu        for ly,ry in zip(lrun[lx].keys(),rrun[rx].keys()):
6110311Snilay@cs.wisc.edu            if ly != ry:
6210311Snilay@cs.wisc.edu                print 'ly != ry'
6310311Snilay@cs.wisc.edu                print ly, ry
646657Snate@binkert.org                print lrun[lx].keys()
6510311Snilay@cs.wisc.edu                print rrun[rx].keys()
669366Snilay@cs.wisc.edu                return False
677839Snilay@cs.wisc.edu    return True
686657Snate@binkert.org
696882SBrad.Beckmann@amd.com
7010308Snilay@cs.wisc.edudef binaryop(op, lf, rf):
7110308Snilay@cs.wisc.edu    result = {}
726882SBrad.Beckmann@amd.com
7310308Snilay@cs.wisc.edu    if isinstance(lf, FormulaStat) and isinstance(rf, FormulaStat):
7410308Snilay@cs.wisc.edu        lv = lf.value
7510308Snilay@cs.wisc.edu        rv = rf.value
7610308Snilay@cs.wisc.edu
7710308Snilay@cs.wisc.edu        theruns = []
789366Snilay@cs.wisc.edu        for r in lv.keys():
799366Snilay@cs.wisc.edu            if rv.has_key(r):
806657Snate@binkert.org                if same(lv[r], rv[r]):
8113672Sandreas.sandberg@arm.com                    theruns.append(r)
8213672Sandreas.sandberg@arm.com                else:
8313672Sandreas.sandberg@arm.com                    raise AttributeError
8413672Sandreas.sandberg@arm.com
856657Snate@binkert.org        for run in theruns:
866657Snate@binkert.org            result[run] = {}
876657Snate@binkert.org            for x in lv[run].keys():
8810311Snilay@cs.wisc.edu                result[run][x] = {}
8910311Snilay@cs.wisc.edu                for y in lv[run][x].keys():
9010311Snilay@cs.wisc.edu                    result[run][x][y] = wrapop(op, lv[run][x][y],
9110311Snilay@cs.wisc.edu                                               rv[run][x][y])
926657Snate@binkert.org    elif isinstance(lf, FormulaStat):
937839Snilay@cs.wisc.edu        lv = lf.value
947839Snilay@cs.wisc.edu        for run in lv.keys():
9510972Sdavid.hashe@amd.com            result[run] = {}
9610972Sdavid.hashe@amd.com            for x in lv[run].keys():
9710972Sdavid.hashe@amd.com                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():
1036657Snate@binkert.org            result[run] = {}
1046657Snate@binkert.org            for x in rv[run].keys():
1056657Snate@binkert.org                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
1106657Snate@binkert.org
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
1166779SBrad.Beckmann@amd.com
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
12610972Sdavid.hashe@amd.comdef cmp(a, b):
12710972Sdavid.hashe@amd.com    if a < b:
12810972Sdavid.hashe@amd.com        return -1
1299104Shestness@cs.utexas.edu    elif a == b:
1309104Shestness@cs.utexas.edu        return 0
1319104Shestness@cs.utexas.edu    else:
1329104Shestness@cs.utexas.edu        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 = {}
14610307Snilay@cs.wisc.edu
1476657Snate@binkert.org    def __getattribute__(self, attr):
1486657Snate@binkert.org        if attr == 'ticks':
1497839Snilay@cs.wisc.edu            if self.__dict__['ticks'] != globalTicks:
1507839Snilay@cs.wisc.edu                self.__dict__['value'] = None
1517839Snilay@cs.wisc.edu                self.__dict__['ticks'] = globalTicks
1527839Snilay@cs.wisc.edu            return self.__dict__['ticks']
1537839Snilay@cs.wisc.edu        if attr == 'value':
1547839Snilay@cs.wisc.edu            if self.__dict__['ticks'] != globalTicks:
1557839Snilay@cs.wisc.edu                if self.__dict__['ticks'] != None and \
1567839Snilay@cs.wisc.edu                                    len(self.__dict__['ticks']) == 1:
1577839Snilay@cs.wisc.edu                    self.vc[self.__dict__['ticks'][0]] = self.__dict__['value']
1587839Snilay@cs.wisc.edu                self.__dict__['ticks'] = globalTicks
15910968Sdavid.hashe@amd.com                if len(globalTicks) == 1 and self.vc.has_key(globalTicks[0]):
16010968Sdavid.hashe@amd.com                    self.__dict__['value'] = self.vc[globalTicks[0]]
16110968Sdavid.hashe@amd.com                else:
16210968Sdavid.hashe@amd.com                    self.__dict__['value'] = None
16310968Sdavid.hashe@amd.com            if self.__dict__['value'] == None:
16410968Sdavid.hashe@amd.com                self.__dict__['value'] = self.getValue()
16510968Sdavid.hashe@amd.com            return self.__dict__['value']
1667839Snilay@cs.wisc.edu        else:
1676657Snate@binkert.org            return super(Statistic, self).__getattribute__(attr)
1686657Snate@binkert.org
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() ]
1766657Snate@binkert.org
1776657Snate@binkert.org            self.__dict__[attr] = value
1786657Snate@binkert.org            self.__dict__['value'] = None
1796657Snate@binkert.org            self.vc = {}
1806657Snate@binkert.org        else:
1816657Snate@binkert.org            super(Statistic, self).__setattr__(attr, value)
1826657Snate@binkert.org
1836657Snate@binkert.org    def getValue(self):
1846657Snate@binkert.org        raise AttributeError, 'getValue() must be defined'
1856657Snate@binkert.org
1866657Snate@binkert.org    def zero(self):
1876657Snate@binkert.org        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):
19710963Sdavid.hashe@amd.com        f = FormulaStat()
19810963Sdavid.hashe@amd.com        f.value = binaryop(operator.add, self, other)
19910963Sdavid.hashe@amd.com        return f
20010963Sdavid.hashe@amd.com    def __sub__(self, other):
20110963Sdavid.hashe@amd.com        f = FormulaStat()
20210963Sdavid.hashe@amd.com        f.value = binaryop(operator.sub, self, other)
20311095Snilay@cs.wisc.edu        return f
20410963Sdavid.hashe@amd.com    def __mul__(self, other):
20510963Sdavid.hashe@amd.com        f = FormulaStat()
20610963Sdavid.hashe@amd.com        f.value = binaryop(operator.mul, self, other)
20710963Sdavid.hashe@amd.com        return f
20810963Sdavid.hashe@amd.com    def __truediv__(self, other):
20910963Sdavid.hashe@amd.com        f = FormulaStat()
21010963Sdavid.hashe@amd.com        f.value = binaryop(zerodiv, self, other)
21110963Sdavid.hashe@amd.com        return f
2129219Spower.jg@gmail.com    def __mod__(self, other):
2136877Ssteve.reinhardt@amd.com        f = FormulaStat()
2146657Snate@binkert.org        f.value = binaryop(operator.mod, self, other)
2159219Spower.jg@gmail.com        return f
2166657Snate@binkert.org    def __radd__(self, other):
2179219Spower.jg@gmail.com        f = FormulaStat()
2186657Snate@binkert.org        f.value = binaryop(operator.add, other, self)
2196877Ssteve.reinhardt@amd.com        return f
2206999Snate@binkert.org    def __rsub__(self, other):
2216877Ssteve.reinhardt@amd.com        f = FormulaStat()
22210308Snilay@cs.wisc.edu        f.value = binaryop(operator.sub, other, self)
2236877Ssteve.reinhardt@amd.com        return f
2246877Ssteve.reinhardt@amd.com    def __rmul__(self, other):
22510308Snilay@cs.wisc.edu        f = FormulaStat()
2266877Ssteve.reinhardt@amd.com        f.value = binaryop(operator.mul, other, self)
2276877Ssteve.reinhardt@amd.com        return f
2286877Ssteve.reinhardt@amd.com    def __rtruediv__(self, other):
22913665Sandreas.sandberg@arm.com        f = FormulaStat()
2306877Ssteve.reinhardt@amd.com        f.value = binaryop(zerodiv, other, self)
2316877Ssteve.reinhardt@amd.com        return f
2326877Ssteve.reinhardt@amd.com    def __rmod__(self, other):
23314184Sgabeblack@google.com        f = FormulaStat()
2346877Ssteve.reinhardt@amd.com        f.value = binaryop(operator.mod, other, self)
2356877Ssteve.reinhardt@amd.com        return f
2366877Ssteve.reinhardt@amd.com    def __neg__(self):
2376877Ssteve.reinhardt@amd.com        f = FormulaStat()
23810308Snilay@cs.wisc.edu        f.value = unaryop(operator.neg, self)
23910308Snilay@cs.wisc.edu        return f
24010308Snilay@cs.wisc.edu    def __getitem__(self, idx):
24110308Snilay@cs.wisc.edu        f = FormulaStat()
24213675Sandreas.sandberg@arm.com        f.value = {}
2436882SBrad.Beckmann@amd.com        for key in self.value.keys():
24410308Snilay@cs.wisc.edu            f.value[key] = {}
24510308Snilay@cs.wisc.edu            f.value[key][0] = {}
2466882SBrad.Beckmann@amd.com            f.value[key][0][0] = self.value[key][idx][0]
2476882SBrad.Beckmann@amd.com        return f
2486882SBrad.Beckmann@amd.com
2496882SBrad.Beckmann@amd.com    def __float__(self):
25011021Sjthestness@gmail.com        if isinstance(self.value, FormulaStat):
2516877Ssteve.reinhardt@amd.com            return float(self.value)
2526877Ssteve.reinhardt@amd.com        if not self.value.has_key(display_run):
25310917Sbrandon.potter@amd.com            return (1e300*1e300)
2546877Ssteve.reinhardt@amd.com        if len(self.value[display_run]) == 1:
2556657Snate@binkert.org            return self.value[display_run][0][0]
2566657Snate@binkert.org        else:
2576999Snate@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):
2627007Snate@binkert.org        import display
2636657Snate@binkert.org        d = display.VectorDisplay()
2646657Snate@binkert.org        d.flags = 0
2656657Snate@binkert.org        d.precision = 1
2666657Snate@binkert.org        d.name = 'formula'
2676657Snate@binkert.org        d.desc = 'formula'
2687007Snate@binkert.org        val = self.value[display_run]
2697007Snate@binkert.org        d.value = [ val[x][0] for x in val.keys() ]
2706657Snate@binkert.org        d.display()
2717002Snate@binkert.org
2727002Snate@binkert.org
2737002Snate@binkert.orgclass Scalar(Statistic,FormulaStat):
2747002Snate@binkert.org    def getValue(self):
2758229Snate@binkert.org        return source.data(self, self.bins, self.ticks)
27614184Sgabeblack@google.com
27714184Sgabeblack@google.com    def display(self):
2788229Snate@binkert.org        import display
2798229Snate@binkert.org        p = display.Print()
28010972Sdavid.hashe@amd.com        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
2856793SBrad.Beckmann@amd.com        if display.all or (self.flags & flags.printable):
28614184Sgabeblack@google.com            p.display()
28710311Snilay@cs.wisc.edu
2886657Snate@binkert.org    def comparable(self, other):
2896657Snate@binkert.org        return self.name == other.name
2906657Snate@binkert.org
2917002Snate@binkert.org    def __eq__(self, other):
2926657Snate@binkert.org        return self.value == other.value
2937007Snate@binkert.org
2947007Snate@binkert.org    def __isub__(self, other):
2959271Snilay@cs.wisc.edu        self.value -= other.value
2966877Ssteve.reinhardt@amd.com        return self
2976877Ssteve.reinhardt@amd.com
2986657Snate@binkert.org    def __iadd__(self, other):
2996877Ssteve.reinhardt@amd.com        self.value += other.value
30010311Snilay@cs.wisc.edu        return self
30111084Snilay@cs.wisc.edu
30211084Snilay@cs.wisc.edu    def __itruediv__(self, other):
30311021Sjthestness@gmail.com        if not other:
3049745Snilay@cs.wisc.edu            return self
3057002Snate@binkert.org        self.value /= other
3066657Snate@binkert.org        return self
30710012Snilay@cs.wisc.edu
3089745Snilay@cs.wisc.educlass Vector(Statistic,FormulaStat):
3099745Snilay@cs.wisc.edu    def getValue(self):
3109745Snilay@cs.wisc.edu        return source.data(self, self.bins, self.ticks);
3118683Snilay@cs.wisc.edu
31211308Santhony.gutierrez@amd.com    def display(self):
31311309Sdavid.hashe@amd.com        import display
3147007Snate@binkert.org        if not display.all and not (self.flags & flags.printable):
31510524Snilay@cs.wisc.edu            return
3169302Snilay@cs.wisc.edu
3179745Snilay@cs.wisc.edu        d = display.VectorDisplay()
3189745Snilay@cs.wisc.edu        d.__dict__.update(self.__dict__)
31911061Snilay@cs.wisc.edu        d.display()
3209745Snilay@cs.wisc.edu
32111061Snilay@cs.wisc.edu    def comparable(self, other):
3229745Snilay@cs.wisc.edu        return self.name == other.name and \
3236657Snate@binkert.org               len(self.value) == len(other.value)
3246657Snate@binkert.org
3256657Snate@binkert.org    def __eq__(self, other):
3266657Snate@binkert.org        if issequence(self.value) != issequence(other.value):
3276657Snate@binkert.org            return False
3286657Snate@binkert.org
3296882SBrad.Beckmann@amd.com        if issequence(self.value):
3306882SBrad.Beckmann@amd.com            if len(self.value) != len(other.value):
3316882SBrad.Beckmann@amd.com                return False
3326882SBrad.Beckmann@amd.com            else:
3336657Snate@binkert.org                for v1,v2 in zip(self.value, other.value):
3346657Snate@binkert.org                    if v1 != v2:
3357007Snate@binkert.org                        return False
3367839Snilay@cs.wisc.edu                return True
3377839Snilay@cs.wisc.edu        else:
3387839Snilay@cs.wisc.edu            return self.value == other.value
3397839Snilay@cs.wisc.edu
3407839Snilay@cs.wisc.edu    def __isub__(self, other):
3417839Snilay@cs.wisc.edu        self.value = binaryop(operator.sub, self.value, other.value)
3427839Snilay@cs.wisc.edu        return self
3437839Snilay@cs.wisc.edu
3447839Snilay@cs.wisc.edu    def __iadd__(self, other):
3457839Snilay@cs.wisc.edu        self.value = binaryop(operator.add, self.value, other.value)
3467839Snilay@cs.wisc.edu        return self
3477839Snilay@cs.wisc.edu
34811025Snilay@cs.wisc.edu    def __itruediv__(self, other):
3497007Snate@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)):
3537839Snilay@cs.wisc.edu                self.value[i] /= other
3547839Snilay@cs.wisc.edu        else:
3557839Snilay@cs.wisc.edu            self.value /= other
3567839Snilay@cs.wisc.edu        return self
3577839Snilay@cs.wisc.edu
3587839Snilay@cs.wisc.educlass Formula(Vector):
3597839Snilay@cs.wisc.edu    def getValue(self):
3607839Snilay@cs.wisc.edu        formula = re.sub(':', '__', self.formula)
3617839Snilay@cs.wisc.edu        x = eval(formula, source.stattop)
3627839Snilay@cs.wisc.edu        return x.value
3637839Snilay@cs.wisc.edu
3647839Snilay@cs.wisc.edu    def comparable(self, other):
36511025Snilay@cs.wisc.edu        return self.name == other.name and \
3667007Snate@binkert.org               compare(self.dist, other.dist)
3679745Snilay@cs.wisc.edu
3689745Snilay@cs.wisc.edu    def __eq__(self, other):
3699745Snilay@cs.wisc.edu        return self.value == other.value
3709745Snilay@cs.wisc.edu
3719745Snilay@cs.wisc.edu    def __isub__(self, other):
3729745Snilay@cs.wisc.edu        return self
3736657Snate@binkert.org
3747007Snate@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:
3796657Snate@binkert.org            return self
3806657Snate@binkert.org        return self
3816657Snate@binkert.org
3826657Snate@binkert.orgclass SimpleDist(object):
3837839Snilay@cs.wisc.edu    def __init__(self, sums, squares, samples):
3847839Snilay@cs.wisc.edu        self.sums = sums
3857839Snilay@cs.wisc.edu        self.squares = squares
3867839Snilay@cs.wisc.edu        self.samples = samples
3877839Snilay@cs.wisc.edu
3887839Snilay@cs.wisc.edu    def getValue(self):
3897839Snilay@cs.wisc.edu        return 0.0
3907839Snilay@cs.wisc.edu
3917839Snilay@cs.wisc.edu    def display(self, name, desc, flags, precision):
3927839Snilay@cs.wisc.edu        import display
3937839Snilay@cs.wisc.edu        p = display.Print()
3947839Snilay@cs.wisc.edu        p.flags = flags
3957839Snilay@cs.wisc.edu        p.precision = precision
3967839Snilay@cs.wisc.edu
3977839Snilay@cs.wisc.edu        if self.samples > 0:
3987839Snilay@cs.wisc.edu            p.name = name + ".mean"
39910121Snilay@cs.wisc.edu            p.value = self.sums / self.samples
4006657Snate@binkert.org            p.display()
4016657Snate@binkert.org
4026657Snate@binkert.org            p.name = name + ".stdev"
4036657Snate@binkert.org            if self.samples > 1:
4047839Snilay@cs.wisc.edu                var = (self.samples * self.squares - self.sums ** 2) \
4057839Snilay@cs.wisc.edu                      / (self.samples * (self.samples - 1))
4067839Snilay@cs.wisc.edu                if var >= 0:
40710121Snilay@cs.wisc.edu                    p.value = math.sqrt(var)
40810121Snilay@cs.wisc.edu                else:
40911025Snilay@cs.wisc.edu                    p.value = 'NaN'
4107839Snilay@cs.wisc.edu            else:
4117839Snilay@cs.wisc.edu                p.value = 0.0
4127839Snilay@cs.wisc.edu            p.display()
41310121Snilay@cs.wisc.edu
41411025Snilay@cs.wisc.edu        p.name = name + ".samples"
4157839Snilay@cs.wisc.edu        p.value = self.samples
4167839Snilay@cs.wisc.edu        p.display()
4177839Snilay@cs.wisc.edu
41810121Snilay@cs.wisc.edu    def comparable(self, other):
41911025Snilay@cs.wisc.edu        return True
4207839Snilay@cs.wisc.edu
4217839Snilay@cs.wisc.edu    def __eq__(self, other):
4227839Snilay@cs.wisc.edu        return self.sums == other.sums and self.squares == other.squares and \
42311025Snilay@cs.wisc.edu               self.samples == other.samples
4246657Snate@binkert.org
4256657Snate@binkert.org    def __isub__(self, other):
4266657Snate@binkert.org        self.sums -= other.sums
4276657Snate@binkert.org        self.squares -= other.squares
4287007Snate@binkert.org        self.samples -= other.samples
4296657Snate@binkert.org        return self
4306657Snate@binkert.org
4319273Snilay@cs.wisc.edu    def __iadd__(self, other):
43210305Snilay@cs.wisc.edu        self.sums += other.sums
4336657Snate@binkert.org        self.squares += other.squares
4346657Snate@binkert.org        self.samples += other.samples
4356657Snate@binkert.org        return self
4367007Snate@binkert.org
4376657Snate@binkert.org    def __itruediv__(self, other):
4386657Snate@binkert.org        if not other:
4399219Spower.jg@gmail.com            return self
4406657Snate@binkert.org        self.sums /= other
4416657Snate@binkert.org        self.squares /= other
4426999Snate@binkert.org        self.samples /= other
4436657Snate@binkert.org        return self
4446657Snate@binkert.org
4456657Snate@binkert.orgclass FullDist(SimpleDist):
4466657Snate@binkert.org    def __init__(self, sums, squares, samples, minval, maxval,
4477007Snate@binkert.org                 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
4516657Snate@binkert.org        self.minval = minval
4526657Snate@binkert.org        self.maxval = maxval
4538946Sandreas.hansson@arm.com        self.under = under
4548946Sandreas.hansson@arm.com        self.vec = vec
4558946Sandreas.hansson@arm.com        self.over = over
4567832Snate@binkert.org        self.min = min
4577002Snate@binkert.org        self.max = max
4587002Snate@binkert.org        self.bsize = bsize
45910972Sdavid.hashe@amd.com        self.size = size
4607002Snate@binkert.org
4618641Snate@binkert.org    def getValue(self):
46214184Sgabeblack@google.com        return 0.0
46311704Santhony.gutierrez@amd.com
46410972Sdavid.hashe@amd.com    def display(self, name, desc, flags, precision):
46510972Sdavid.hashe@amd.com        import display
46610972Sdavid.hashe@amd.com        p = display.Print()
46710972Sdavid.hashe@amd.com        p.flags = flags
46810972Sdavid.hashe@amd.com        p.precision = precision
46911793Sbrandon.potter@amd.com
47014184Sgabeblack@google.com        p.name = name + '.min_val'
47114184Sgabeblack@google.com        p.value = self.minval
47214184Sgabeblack@google.com        p.display()
47314184Sgabeblack@google.com
47411108Sdavid.hashe@amd.com        p.name = name + '.max_val'
47510972Sdavid.hashe@amd.com        p.value = self.maxval
4769219Spower.jg@gmail.com        p.display()
4779219Spower.jg@gmail.com
4789219Spower.jg@gmail.com        p.name = name + '.underflow'
4799219Spower.jg@gmail.com        p.value = self.under
4809219Spower.jg@gmail.com        p.display()
4817002Snate@binkert.org
4827002Snate@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
4886793SBrad.Beckmann@amd.com
48914184Sgabeblack@google.com        p.name = name + '[%d:%d]' % (i, self.max)
4906657Snate@binkert.org        p.value = self.vec[-1]
4916657Snate@binkert.org        p.display()
49210121Snilay@cs.wisc.edu
49310121Snilay@cs.wisc.edu
4946657Snate@binkert.org        p.name = name + '.overflow'
4956877Ssteve.reinhardt@amd.com        p.value = self.over
4966877Ssteve.reinhardt@amd.com        p.display()
4976877Ssteve.reinhardt@amd.com
4986877Ssteve.reinhardt@amd.com        SimpleDist.display(self, name, desc, flags, precision)
4996877Ssteve.reinhardt@amd.com
5006877Ssteve.reinhardt@amd.com    def comparable(self, other):
5016657Snate@binkert.org        return self.min == other.min and self.max == other.max and \
5029745Snilay@cs.wisc.edu               self.bsize == other.bsize and self.size == other.size
5039745Snilay@cs.wisc.edu
5046657Snate@binkert.org    def __eq__(self, other):
5057007Snate@binkert.org        return self.sums == other.sums and self.squares == other.squares and \
5066657Snate@binkert.org               self.samples == other.samples
5079801Snilay@cs.wisc.edu
5089801Snilay@cs.wisc.edu    def __isub__(self, other):
5096657Snate@binkert.org        self.sums -= other.sums
5109801Snilay@cs.wisc.edu        self.squares -= other.squares
5119801Snilay@cs.wisc.edu        self.samples -= other.samples
5129801Snilay@cs.wisc.edu
5137007Snate@binkert.org        if other.samples:
5146657Snate@binkert.org            self.minval = min(self.minval, other.minval)
5156877Ssteve.reinhardt@amd.com            self.maxval = max(self.maxval, other.maxval)
5166877Ssteve.reinhardt@amd.com            self.under -= under
5176657Snate@binkert.org            self.vec = map(lambda x,y: x - y, self.vec, other.vec)
51810078Snilay@cs.wisc.edu            self.over -= over
51910078Snilay@cs.wisc.edu        return self
52010121Snilay@cs.wisc.edu
52110121Snilay@cs.wisc.edu    def __iadd__(self, other):
52210121Snilay@cs.wisc.edu        if not self.samples and other.samples:
5236657Snate@binkert.org            self = other
5246657Snate@binkert.org            return self
5256882SBrad.Beckmann@amd.com
5266882SBrad.Beckmann@amd.com        self.sums += other.sums
5276882SBrad.Beckmann@amd.com        self.squares += other.squares
52810121Snilay@cs.wisc.edu        self.samples += other.samples
52910121Snilay@cs.wisc.edu
5306882SBrad.Beckmann@amd.com        if other.samples:
5316877Ssteve.reinhardt@amd.com            self.minval = min(self.minval, other.minval)
5326882SBrad.Beckmann@amd.com            self.maxval = max(self.maxval, other.maxval)
53310308Snilay@cs.wisc.edu            self.under += other.under
5346882SBrad.Beckmann@amd.com            self.vec = map(lambda x,y: x + y, self.vec, other.vec)
53510308Snilay@cs.wisc.edu            self.over += other.over
53610311Snilay@cs.wisc.edu        return self
53711308Santhony.gutierrez@amd.com
53811308Santhony.gutierrez@amd.com    def __itruediv__(self, other):
53911308Santhony.gutierrez@amd.com        if not other:
54011308Santhony.gutierrez@amd.com            return self
54111308Santhony.gutierrez@amd.com        self.sums /= other
54211308Santhony.gutierrez@amd.com        self.squares /= other
54311308Santhony.gutierrez@amd.com        self.samples /= other
54411308Santhony.gutierrez@amd.com
54510917Sbrandon.potter@amd.com        if self.samples:
5469595Snilay@cs.wisc.edu            self.under /= other
5479745Snilay@cs.wisc.edu            for i in xrange(len(self.vec)):
5489745Snilay@cs.wisc.edu                self.vec[i] /= other
5499745Snilay@cs.wisc.edu            self.over /= other
5509745Snilay@cs.wisc.edu        return self
5519745Snilay@cs.wisc.edu
5529745Snilay@cs.wisc.educlass Dist(Statistic):
5539745Snilay@cs.wisc.edu    def getValue(self):
5549745Snilay@cs.wisc.edu        return 0.0
5559745Snilay@cs.wisc.edu
5569745Snilay@cs.wisc.edu    def display(self):
5579595Snilay@cs.wisc.edu        import display
5586657Snate@binkert.org        if not display.all and not (self.flags & flags.printable):
5596657Snate@binkert.org            return
5606657Snate@binkert.org
5616657Snate@binkert.org        self.dist.display(self.name, self.desc, self.flags, self.precision)
5627007Snate@binkert.org
56311021Sjthestness@gmail.com    def comparable(self, other):
56410311Snilay@cs.wisc.edu        return self.name == other.name and \
56510311Snilay@cs.wisc.edu               self.dist.compareable(other.dist)
56610311Snilay@cs.wisc.edu
56710311Snilay@cs.wisc.edu    def __eq__(self, other):
56810311Snilay@cs.wisc.edu        return self.dist == other.dist
56910311Snilay@cs.wisc.edu
57010311Snilay@cs.wisc.edu    def __isub__(self, other):
57110311Snilay@cs.wisc.edu        self.dist -= other.dist
57210311Snilay@cs.wisc.edu        return self
57310311Snilay@cs.wisc.edu
57410311Snilay@cs.wisc.edu    def __iadd__(self, other):
57510311Snilay@cs.wisc.edu        self.dist += other.dist
57610311Snilay@cs.wisc.edu        return self
57711084Snilay@cs.wisc.edu
57810311Snilay@cs.wisc.edu    def __itruediv__(self, other):
57910311Snilay@cs.wisc.edu        if not other:
58011021Sjthestness@gmail.com            return self
58111021Sjthestness@gmail.com        self.dist /= other
58210311Snilay@cs.wisc.edu        return self
58310311Snilay@cs.wisc.edu
58410311Snilay@cs.wisc.educlass VectorDist(Statistic):
58510311Snilay@cs.wisc.edu    def getValue(self):
58610311Snilay@cs.wisc.edu        return 0.0
58710311Snilay@cs.wisc.edu
58810311Snilay@cs.wisc.edu    def display(self):
58910311Snilay@cs.wisc.edu        import display
59010311Snilay@cs.wisc.edu        if not display.all and not (self.flags & flags.printable):
59110311Snilay@cs.wisc.edu            return
59210311Snilay@cs.wisc.edu
59311021Sjthestness@gmail.com        if isinstance(self.dist, SimpleDist):
59411021Sjthestness@gmail.com            return
59510311Snilay@cs.wisc.edu
59610311Snilay@cs.wisc.edu        for dist,sn,sd,i in map(None, self.dist, self.subnames, self.subdescs,
59710311Snilay@cs.wisc.edu                                range(len(self.dist))):
59810311Snilay@cs.wisc.edu            if len(sn) > 0:
59910311Snilay@cs.wisc.edu                name = '%s.%s' % (self.name, sn)
60010311Snilay@cs.wisc.edu            else:
60110311Snilay@cs.wisc.edu                name = '%s[%d]' % (self.name, i)
60210311Snilay@cs.wisc.edu
60310311Snilay@cs.wisc.edu            if len(sd) > 0:
60410311Snilay@cs.wisc.edu                desc = sd
6057007Snate@binkert.org            else:
6066657Snate@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:
61110311Snilay@cs.wisc.edu            if isinstance(self.dist[0], SimpleDist):
6126657Snate@binkert.org                disttotal = SimpleDist( \
6136657Snate@binkert.org                    reduce(sums, [d.sums for d in self.dist]),
61410305Snilay@cs.wisc.edu                    reduce(sums, [d.squares for d in self.dist]),
6156657Snate@binkert.org                    reduce(sums, [d.samples for d in self.dist]))
6166657Snate@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]),
62311084Snilay@cs.wisc.edu                    reduce(sums, [d.under for d in self.dist]),
62411084Snilay@cs.wisc.edu                    reduce(sums, [d.vec for d in self.dist]),
62511084Snilay@cs.wisc.edu                    reduce(sums, [d.over for d in self.dist]),
62611084Snilay@cs.wisc.edu                    dist[0].min,
62711084Snilay@cs.wisc.edu                    dist[0].max,
6286657Snate@binkert.org                    dist[0].bsize,
62911084Snilay@cs.wisc.edu                    dist[0].size)
6306657Snate@binkert.org
6316657Snate@binkert.org            name = '%s.total' % (self.name)
6326657Snate@binkert.org            desc = self.desc
6337007Snate@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 \
6376657Snate@binkert.org               alltrue(map(lambda x, y : x.comparable(y),
6389366Snilay@cs.wisc.edu                           self.dist,
6399366Snilay@cs.wisc.edu                           other.dist))
6409366Snilay@cs.wisc.edu
6419366Snilay@cs.wisc.edu    def __eq__(self, other):
6427566SBrad.Beckmann@amd.com        return alltrue(map(lambda x, y : x == y, self.dist, other.dist))
6437672Snate@binkert.org
6446657Snate@binkert.org    def __isub__(self, other):
6459465Snilay@cs.wisc.edu        if issequence(self.dist) and issequence(other.dist):
6466657Snate@binkert.org            for sd,od in zip(self.dist, other.dist):
6476657Snate@binkert.org                sd -= od
6486657Snate@binkert.org        else:
6497672Snate@binkert.org            self.dist -= other.dist
6506657Snate@binkert.org        return self
6516657Snate@binkert.org
6526657Snate@binkert.org    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
6566657Snate@binkert.org        else:
6576657Snate@binkert.org            self.dist += other.dist
6586657Snate@binkert.org        return self
6596657Snate@binkert.org
6606657Snate@binkert.org    def __itruediv__(self, other):
6619745Snilay@cs.wisc.edu        if not other:
6626657Snate@binkert.org            return self
6636657Snate@binkert.org        if issequence(self.dist):
6649496Snilay@cs.wisc.edu            for dist in self.dist:
6659496Snilay@cs.wisc.edu                dist /= other
66610012Snilay@cs.wisc.edu        else:
6679496Snilay@cs.wisc.edu            self.dist /= other
6689496Snilay@cs.wisc.edu        return self
6696657Snate@binkert.org
67010121Snilay@cs.wisc.educlass Vector2d(Statistic):
6716657Snate@binkert.org    def getValue(self):
6726657Snate@binkert.org        return 0.0
67310305Snilay@cs.wisc.edu
6746657Snate@binkert.org    def display(self):
67511021Sjthestness@gmail.com        import display
67611021Sjthestness@gmail.com        if not display.all and not (self.flags & flags.printable):
67711021Sjthestness@gmail.com            return
67811021Sjthestness@gmail.com
67911021Sjthestness@gmail.com        d = display.VectorDisplay()
6808683Snilay@cs.wisc.edu        d.__dict__.update(self.__dict__)
6818683Snilay@cs.wisc.edu
68210308Snilay@cs.wisc.edu        if self.__dict__.has_key('ysubnames'):
6838683Snilay@cs.wisc.edu            ysubnames = list(self.ysubnames)
68410308Snilay@cs.wisc.edu            slack = self.x - len(ysubnames)
6858683Snilay@cs.wisc.edu            if slack > 0:
68611309Sdavid.hashe@amd.com                ysubnames.extend(['']*slack)
68711309Sdavid.hashe@amd.com        else:
68811309Sdavid.hashe@amd.com            ysubnames = range(self.x)
68911309Sdavid.hashe@amd.com
69011309Sdavid.hashe@amd.com        for x,sname in enumerate(ysubnames):
69111309Sdavid.hashe@amd.com            o = x * self.y
69211308Santhony.gutierrez@amd.com            d.value = self.value[o:o+self.y]
69311308Santhony.gutierrez@amd.com            d.name = '%s[%s]' % (self.name, sname)
69411308Santhony.gutierrez@amd.com            d.display()
69511308Santhony.gutierrez@amd.com
69611308Santhony.gutierrez@amd.com        if self.flags & flags.total:
69711308Santhony.gutierrez@amd.com            d.value = []
69811308Santhony.gutierrez@amd.com            for y in range(self.y):
69911308Santhony.gutierrez@amd.com                xtot = 0.0
70011308Santhony.gutierrez@amd.com                for x in range(self.x):
70111308Santhony.gutierrez@amd.com                    xtot += self.value[y + x * self.x]
70211308Santhony.gutierrez@amd.com                d.value.append(xtot)
70311308Santhony.gutierrez@amd.com
70411308Santhony.gutierrez@amd.com            d.name = self.name + '.total'
70511308Santhony.gutierrez@amd.com            d.display()
70611308Santhony.gutierrez@amd.com
70711308Santhony.gutierrez@amd.com    def comparable(self, other):
70811308Santhony.gutierrez@amd.com        return self.name == other.name and self.x == other.x and \
70911308Santhony.gutierrez@amd.com               self.y == other.y
71011308Santhony.gutierrez@amd.com
71111308Santhony.gutierrez@amd.com    def __eq__(self, other):
71211308Santhony.gutierrez@amd.com        return True
71311308Santhony.gutierrez@amd.com
71411309Sdavid.hashe@amd.com    def __isub__(self, other):
71511309Sdavid.hashe@amd.com        return self
71611309Sdavid.hashe@amd.com
71711309Sdavid.hashe@amd.com    def __iadd__(self, other):
71811309Sdavid.hashe@amd.com        return self
71911309Sdavid.hashe@amd.com
72011309Sdavid.hashe@amd.com    def __itruediv__(self, other):
72111309Sdavid.hashe@amd.com        if not other:
72211309Sdavid.hashe@amd.com            return self
72311309Sdavid.hashe@amd.com        return self
72411309Sdavid.hashe@amd.com
72511309Sdavid.hashe@amd.comdef NewStat(data):
72611309Sdavid.hashe@amd.com    stat = None
72711309Sdavid.hashe@amd.com    if data.type == 'SCALAR':
72811309Sdavid.hashe@amd.com        stat = Scalar(data)
72911309Sdavid.hashe@amd.com    elif data.type == 'VECTOR':
73011309Sdavid.hashe@amd.com        stat = Vector(data)
73111309Sdavid.hashe@amd.com    elif data.type == 'DIST':
73211309Sdavid.hashe@amd.com        stat = Dist(data)
73311309Sdavid.hashe@amd.com    elif data.type == 'VECTORDIST':
73411309Sdavid.hashe@amd.com        stat = VectorDist(data)
73511309Sdavid.hashe@amd.com    elif data.type == 'VECTOR2D':
7366657Snate@binkert.org        stat = Vector2d(data)
7379745Snilay@cs.wisc.edu    elif data.type == 'FORMULA':
7389745Snilay@cs.wisc.edu        stat = Formula(data)
7399745Snilay@cs.wisc.edu
7409745Snilay@cs.wisc.edu    return stat
74110012Snilay@cs.wisc.edu
74210012Snilay@cs.wisc.edu