diff -r 9eb01ff3c4fc -r 68ea5c8f8d6c src/python/m5/stats/__init__.py --- a/src/python/m5/stats/__init__.py Thu Apr 25 13:04:24 2013 +0100 +++ b/src/python/m5/stats/__init__.py Thu Apr 25 13:04:24 2013 +0100 @@ -213,22 +213,6 @@ return None -## @brief A proxy used to store the value of a statistic and the information -# about it. -class ValueProxy(object): - ## @brief Constructor. - # @param info The information about the stat. - # @param value The value if the stat. - def __init__(self, info, value): - self._info = info - self.value = value - - def __getattr__(self, attr): - return getattr(self._info, attr) - - def __nonzero__(self): - return - ## @brief Get all of the stats from the C++ into the python. Loop over each # registered stat and call stat.info which returns all information about the # statistic. @@ -238,7 +222,10 @@ for stat in sim_stats: value = convert_value(stat) info = stat.info - stats.append(ValueProxy(info, value)) + info.value = value + if stat.info.type in ('VectorInfo', 'FormulaInfo'): + info.total = stat.total() + stats.append(info) return stats ## @brief Convert from C++ stats to python stats, and store as a context. diff -r 9eb01ff3c4fc -r 68ea5c8f8d6c src/python/m5/stats/display.py --- a/src/python/m5/stats/display.py Thu Apr 25 13:04:24 2013 +0100 +++ b/src/python/m5/stats/display.py Thu Apr 25 13:04:24 2013 +0100 @@ -171,9 +171,15 @@ p.display(out) return - mytotal = sum( x for x in self.value if not isnan(x) ) - if isnan(mytotal): - mytotal = 0 + # Don't recalculate the total if we already have it. In this + # case it has already been calculated in C++ and passed into + # the python via SWIG. + if hasattr(self, "total"): + mytotal = self.total + else: + mytotal = sum( x for x in self.value if not isnan(x) ) + if isnan(mytotal): + mytotal = 0 mycdf = 0.0 @@ -235,10 +241,8 @@ p.display(out) return - mytotal = self.total - mycdf = 0.0 + value = self.value - value = self.value if any(self.subnames): subnames = [''] * len(value) for i,subname in enumerate(self.subnames): @@ -253,22 +257,35 @@ if self.subdescs[i]: subdescs[i] = self.subdescs[i] - for val,sname,sdesc in map(None, value, subnames, subdescs): - if mytotal > 0.0: + mytotal = self.total + mycdf = 0.0 + + # If the total is greater than zero, we print out the elements of the + # stat. + if mytotal > 0.0: + for val,sname,sdesc in map(None, value, subnames, subdescs): mypdf = float(val) / float(mytotal) mycdf += mypdf + + # If there are no subnames, then continue to next iteration + # without printing the stats. + if not sname: + continue + + # Check if we should be printing the PDF (and therefore also the + # CDF). if (self.flags & flags.pdf): p.pdf = mypdf p.cdf = mycdf - if not sname: - continue + # Append the subname to the name of the stat, and write it to + # the output file. + p.name = self.name + sname + p.desc = sdesc + p.value = val + p.display(out) - p.name = self.name + sname - p.desc = sdesc - p.value = val - p.display(out) - + # Check if we should print the total. if self.flags & flags.total: p.reset() p.name = self.name + '::total' @@ -408,7 +425,7 @@ p.value = value(stat, 0) else: p = VectorDisplay(stat) - p.value = [ value(stat, i) for i in xrange(len(stat)) ] + p.value = stat.value p.display(out) @register_display(Formula) @@ -421,10 +438,16 @@ elif vector(stat): if len(stat) == 1: p = Display(stat) - p.value = value(stat, 0) + try: + p.value = stat.value[0] + except (AttributeError, IndexError): + p.value = value(stat, 0) else: p = VectorFormulaDisplay(stat) - p.value = [ value(stat, i) for i in xrange(len(stat)) ] + try: + p.value = stat.value + except AttributeError: + p.value = [ value(stat, i) for i in xrange(len(stat)) ] p.display(out) @register_display(Dist) diff -r 9eb01ff3c4fc -r 68ea5c8f8d6c src/python/m5/stats/info.py --- a/src/python/m5/stats/info.py Thu Apr 25 13:04:24 2013 +0100 +++ b/src/python/m5/stats/info.py Thu Apr 25 13:04:24 2013 +0100 @@ -61,7 +61,6 @@ # @return True if stat is a scalar, False otherwise. def scalar(stat): stat = unproxy(stat) - assert(stat.__scalar__() != stat.__vector__()) return stat.__scalar__() ## @brief Test if a stat is a vector. @@ -69,7 +68,6 @@ # @return True if stat is a vector, False otherwise. def vector(stat): stat = unproxy(stat) - assert(stat.__scalar__() != stat.__vector__()) return stat.__vector__() ## @brief Get the value of a (scalar) stat. @@ -636,7 +634,7 @@ return self.total # Return the properties of the value. - if attr in ('__scalar__', '__vector__', '__value__', '__len__'): + elif attr in ('__scalar__', '__vector__', '__value__', '__len__'): return getattr(self._the_value, attr) return super(Formula, self).__getattr__(attr)