diff -r 307de98f49ab -r bfac87aa5771 src/python/m5/stats/__init__.py --- a/src/python/m5/stats/__init__.py Wed Apr 24 11:25:38 2013 +0100 +++ b/src/python/m5/stats/__init__.py Wed Apr 24 11:26:04 2013 +0100 @@ -253,6 +253,9 @@ shelf['info%d' % stat.id] = stat._info shelf['value%d' % stat.id] = stat.value +## @brief Keeps track of the number of stats dumps which have occured. +dumpCount = 0 + class display_text(object): def __init__(self, filename, desc): self.filename = filename @@ -270,8 +273,13 @@ save_desc = display.descriptions display.descriptions = self.desc - # Open the input file. - f = m5.core.openOutputFile(self.filename, 'a') + # Open the input file. Check to see if this is the first time + # that we are opening it during this run of gem5. Either + # overwrite it if it already exists and we are writing the + # stats for the first time, or append to the file if this is + # not the first stats dump. + mode = 'w' if dumpCount == 0 else 'a' + f = m5.core.openOutputFile(self.filename, mode) print >>f print >>f, "---------- Begin Simulation Statistics ----------" @@ -313,6 +321,11 @@ for output in outputList: output(context) + # Increment dumpCount to keep track of the number of dumps which + # have occured. + global dumpCount + dumpCount += 1 + ## @brief Reset all statistics to the base state. def reset(): # call reset stats on all SimObjects diff -r 307de98f49ab -r bfac87aa5771 src/python/m5/stats/display.py --- a/src/python/m5/stats/display.py Wed Apr 24 11:25:38 2013 +0100 +++ b/src/python/m5/stats/display.py Wed Apr 24 11:26:04 2013 +0100 @@ -171,7 +171,10 @@ p.display(out) return - mytotal = reduce(lambda x,y: float(x) + float(y), self.value) + mytotal = sum( x for x in self.value if not isnan(x) ) + if isnan(mytotal): + mytotal = 0 + mycdf = 0.0 value = self.value @@ -378,12 +381,12 @@ if any(stat.subnames): subnames = stat.subnames else: - subnames = range(stat.x) + subnames = map(str, range(stat.x)) if any(stat.y_subnames): y_subnames = stat.y_subnames else: - y_subnames = range(stat.y) + y_subnames = map(str, range(stat.y)) for x,sname in enumerate(subnames): o = x * stat.y diff -r 307de98f49ab -r bfac87aa5771 src/python/m5/stats/info.py --- a/src/python/m5/stats/info.py Wed Apr 24 11:25:38 2013 +0100 +++ b/src/python/m5/stats/info.py Wed Apr 24 11:26:04 2013 +0100 @@ -91,7 +91,11 @@ ## @brief Sum all of the values for a stat. # @return The sum. def total(stat): - return sum(values(stat)) + val = values(stat) + try: + return sum(val) + except TypeError: + return val ## @brief Get the length of a stat. # @return The length. @@ -103,7 +107,7 @@ # the value. These are used to calculate combinations of statistics. class Value(object): def __getattr__(self, attr): - if attr in ('__scalar__', '__vector'): + if attr in ('__scalar__', '__vector__'): raise AttributeError, "must define %s for %s" % (attr, type (self)) raise AttributeError, \ @@ -149,6 +153,11 @@ def __scalar__(self): return True + ## @brief Get the length of the stat. + # @return 1 as the length of a scalar is always 1. + def __len__(self): + return 1 + ## @brief Test if a stat is a vector. # @return False def __vector__(self): @@ -213,6 +222,11 @@ def __value__(self): return self.constant + ## @brief Get the length of the stat. + # @return 1 as the length of a scalar is always 1. + def __len__(self): + return 1 + ## @brief Get the constant as a string. # @return A string representation of the constant. def __str__(self): @@ -859,7 +873,7 @@ if not other: return self if isinstance(self.value, (list, tuple)): - for iq in xrange(len(self.value)): + for i in xrange(len(self.value)): self.value[i] /= other else: self.value /= other