diff -r 708750fde4d5 -r 7583ac576962 src/python/m5/stats/sql.py --- a/src/python/m5/stats/sql.py Wed Apr 24 11:29:47 2013 +0100 +++ b/src/python/m5/stats/sql.py Wed Apr 24 11:29:52 2013 +0100 @@ -100,6 +100,7 @@ Column('id', Integer), Column('dump', Integer), Column('value', Binary), + Column('total', Binary), ) # Stores distributions. @@ -223,16 +224,20 @@ id = Column(Integer, primary_key = True) dump = Column(Integer) value = Column(Binary) + total = Column(Binary) - def __init__(self, id, dump, value): + def __init__(self, id, dump, value, total): import array self.id = id self.dump = dump a = array.array('f', value) self.value = a.tostring() + a = array.array('f', total) + self.total = a.tostring() def __repr__(self): - return "" % (self.id, self.dump, self.value) + return "" % (self.id, self.dump, self.value, + self.total) # @brief Class used to insert dictribution stats into the database. @@ -318,8 +323,39 @@ elif stat.type == "VectorInfo" or stat.type == "Vector2dInfo" \ or stat.type == "FormulaInfo": + + # We need to calculate the total for each of the stat types in a + # different way and therefore we need to check what the type of + # statistic is. + theTotal = [] + if stat.type == "FormulaInfo": + # The total for the formula can be caculated directly. This + # calculation takes place in the info.formula class. + theTotal.append(stat.total) + elif stat.type == "VectorInfo": + # The total for a vector is the sum of all values. However, as we + # are unable to sum NaNs, these need to first be removed. + import math + noNan = filter(lambda x: not math.isnan(x), stat.value) + + # The total for a vector stat is calculated ignoring any values + # which are NaN. This is to preserve compatibilty with the old + # stats system. + theTotal.append(sum(noNan)) + else: + # For a 2D vector we want to calculate the total for each value of + # x, and therefore get an array of totals. If an overall total is + # desired, this would be the sum of this array. This, however, is + # not stored as it can be computed offline. + for i in range(stat.x): + iy = i * stat.y + total = 0.0 + for j in range(stat.y): + total += stat.value[iy + j] + theTotal.append(total) + temp = VectorValueClass(id = stat.id, dump = dumpCount, - value = stat.value) + value = stat.value, total = theTotal) session.add(temp) elif stat.type == "DistInfo":