summaryrefslogtreecommitdiff
path: root/util/stats/db.py
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2005-10-21 16:29:13 -0400
committerNathan Binkert <binkertn@umich.edu>2005-10-21 16:29:13 -0400
commite00237e49e3cb171a1235f5de43587e8eb31ec2c (patch)
tree4430d3aae17e97a048be4f803264c6830a605df3 /util/stats/db.py
parent8ab674582e88582f06d729237d9cb1c00562451e (diff)
downloadgem5-e00237e49e3cb171a1235f5de43587e8eb31ec2c.tar.xz
Major cleanup of the statistics handling code
util/stats/db.py: Build a result object as the result of a query operation so it is easier to populate and contains a bit more information than just a big dict. Also change the next level data into a matrix instead of a dict of dicts. Move the "get" function into the Database object. (The get function is used by the output parsing function as the interface for accessing backend storage, same interface for profile stuff.) Change the old get variable to the method variable, it describes how the get works, (whether using sum, stdev, etc.) util/stats/display.py: Clean up the display functions, mostly formatting. Handle values the way they should be now. util/stats/info.py: Totally re-work how values are accessed from their data store. Access individual values on demand instead of calculating everything and passing up a huge result from the bottom. This impacts the way that proxying works, and in general, everything is now esentially a proxy for the lower level database. Provide new operators: unproxy, scalar, vector, value, values, total, and len which retrieve the proper result from the object they are called on. Move the ProxyGroup stuff (proxies of proxies!) here from the now gone proxy.py file and integrate the shared parts of the code. The ProxyGroup stuff allows you to write formulas without specifying the statistics until evaluation time. Get rid of global variables! util/stats/output.py: Move the dbinfo stuff into the Database itself. Each source should have it's own get() function for accessing it's data. This get() function behaves a bit differently than before in that it can return vectors as well, deal with these vectors and with no result conditions better. util/stats/stats.py: the info module no longer has the source global variable, just create the database source and pass it around as necessary --HG-- extra : convert_revision : 8e5aa228e5d3ae8068ef9c40f65b3a2f9e7c0cff
Diffstat (limited to 'util/stats/db.py')
-rw-r--r--util/stats/db.py72
1 files changed, 50 insertions, 22 deletions
diff --git a/util/stats/db.py b/util/stats/db.py
index ab005e67b..0d321a360 100644
--- a/util/stats/db.py
+++ b/util/stats/db.py
@@ -103,6 +103,20 @@ class Node(object):
def __str__(self):
return self.name
+class Result(object):
+ def __init__(self, x, y):
+ self.data = {}
+ self.x = x
+ self.y = y
+
+ def __contains__(self, run):
+ return run in self.data
+
+ def __getitem__(self, run):
+ if run not in self.data:
+ self.data[run] = [ [ 0.0 ] * self.y for i in xrange(self.x) ]
+ return self.data[run]
+
class Database(object):
def __init__(self):
self.host = 'zizzer.pool'
@@ -135,7 +149,23 @@ class Database(object):
self.runs = None
self.bins = None
self.ticks = None
- self.__dict__['get'] = type(self).sum
+ self.method = 'sum'
+ self._method = type(self).sum
+
+ def get(self, job, stat):
+ run = self.allRunNames.get(job.name, None)
+ if run is None:
+ print 'run "%s" not found' % job
+ return None
+
+ from info import scalar, vector, value, total, len
+ stat.system = self[job.system]
+ if scalar(stat):
+ return value(stat, run.run)
+ if vector(stat):
+ return values(stat, run.run)
+
+ return None
def query(self, sql):
self.cursor.execute(sql)
@@ -203,7 +233,7 @@ class Database(object):
self.query('select * from stats')
import info
for result in self.cursor.fetchall():
- stat = info.NewStat(StatData(result))
+ stat = info.NewStat(self, StatData(result))
self.append(stat)
self.allStats.append(stat)
self.allStatIds[stat.stat] = stat
@@ -421,30 +451,17 @@ class Database(object):
def stdev(self, stat, bins, ticks):
return self.outer('stddev', 'sum', stat, bins, ticks)
- def __getattribute__(self, attr):
- if attr != 'get':
- return super(Database, self).__getattribute__(attr)
-
- if self.__dict__['get'] == type(self).sum:
- return 'sum'
- elif self.__dict__['get'] == type(self).avg:
- return 'avg'
- elif self.__dict__['get'] == type(self).stdev:
- return 'stdev'
- else:
- return ''
-
def __setattr__(self, attr, value):
- if attr != 'get':
- super(Database, self).__setattr__(attr, value)
+ super(Database, self).__setattr__(attr, value)
+ if attr != 'method':
return
if value == 'sum':
- self.__dict__['get'] = type(self).sum
+ self._method = self.sum
elif value == 'avg':
- self.__dict__['get'] = type(self).avg
+ self._method = self.avg
elif value == 'stdev':
- self.__dict__['get'] = type(self).stdev
+ self._method = self.stdev
else:
raise AttributeError, "can only set get to: sum | avg | stdev"
@@ -453,10 +470,12 @@ class Database(object):
bins = self.bins
if ticks is None:
ticks = self.ticks
- sql = self.__dict__['get'](self, stat, bins, ticks)
+ sql = self._method(self, stat, bins, ticks)
self.query(sql)
runs = {}
+ xmax = 0
+ ymax = 0
for x in self.cursor.fetchall():
data = Data(x)
if not runs.has_key(data.run):
@@ -464,8 +483,17 @@ class Database(object):
if not runs[data.run].has_key(data.x):
runs[data.run][data.x] = {}
+ xmax = max(xmax, data.x)
+ ymax = max(ymax, data.y)
runs[data.run][data.x][data.y] = data.data
- return runs
+
+ results = Result(xmax + 1, ymax + 1)
+ for run,data in runs.iteritems():
+ result = results[run]
+ for x,ydata in data.iteritems():
+ for y,data in ydata.iteritems():
+ result[x][y] = data
+ return results
def __getitem__(self, key):
return self.stattop[key]