diff -r bc23f2c316fc -r 18472246898b src/python/m5/stats/__init__.py --- a/src/python/m5/stats/__init__.py Tue Jan 15 18:38:42 2013 +0000 +++ b/src/python/m5/stats/__init__.py Tue Jan 15 18:40:12 2013 +0000 @@ -324,6 +324,7 @@ Session = sessionmaker(bind = self.db) create_tables(self.db) self.session = Session() + insert_database_information(self.session) # @brief Write the stats to the database. On the first dump we also write # the information about the stats to the database. This is only done once. diff -r bc23f2c316fc -r 18472246898b src/python/m5/stats/sql.py --- a/src/python/m5/stats/sql.py Tue Jan 15 18:38:42 2013 +0000 +++ b/src/python/m5/stats/sql.py Tue Jan 15 18:40:12 2013 +0000 @@ -48,6 +48,13 @@ from math import isnan import zlib +# @brief Returns the version of the stats database. This should be updated when +# either the tables in the database change, or when the method used to store +# a particular stat is changed. Both of the values are stored in the database. +# The first element (integer) is used internally as it can be compared directly. +# The second element (string) is designed as a human readable version. +def version(): + return (1, '1.0') # @brief Create the database used to store the stats. If it exists, we delete # it. @@ -72,6 +79,14 @@ def create_tables(db): metadata = MetaData(db) + # Stores information about the database + db_info_table = Table('dbInfo', metadata, + Column('internal_version', Integer, + primary_key = True), + Column('version', String), + Column('timestamp', DateTime), + ) + # Stores the information about the stats stats_table = Table('stats', metadata, Column('id', Integer, primary_key = True), @@ -140,6 +155,25 @@ Base = declarative_base() +# @brief Class used to insert information about the database itself into the +# database. +class DatabaseInfoClass(Base): + __tablename__ = 'dbInfo' + + internal_version = Column(Integer, primary_key = True) + version = Column(String) + timestamp = Column(DateTime) + + def __init__(self): + databaseVersion = version() + self.internal_version = databaseVersion[0] + self.version = databaseVersion[1] + import datetime + self.timestamp = datetime.datetime.utcnow() + + def __repr__(self): + return "" % (self.version, self.timestamp) + # @brief Class used to insert the information about stats into the database. class StatsInfoClass(Base): __tablename__ = 'stats' @@ -316,6 +350,12 @@ return "" % (self.id, self.dump, self.samples, self.elements, self.values) +# @brief Inserts versioning information into the database. +# @param session The session associated with the database. +def insert_database_information(session): + info = DatabaseInfoClass() + session.add(info) + session.commit() # @brief Add the information about a stat. # @param name The name of the stat.