def __timestamp__():
return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S')
-Config = collections.namedtuple('Config', 'id hash cfile') # Named tuple for configuration
-Measure = collections.namedtuple('Measure', 'id conf_id mfile value') # Named tuple for measurement
+Config = collections.namedtuple('Config', 'id hash config') # Named tuple for configuration
+Measure = collections.namedtuple('Measure', 'id conf_id output value') # Named tuple for measurement
class database:
"Class used for accessing PostgreSQL project database."
def __init__(self):
self.db = postgresql.open(database = conf.db_database,
- user = conf.db_user,
- password = conf.db_password,
- host = conf.db_host,
- port = conf.db_port
- )
+ unix='/var/run/postgresql/.s.PGSQL.5432',
+ password='')
# check if tables are present
tables = ('toolsgit', 'configurations', 'measure')
for tab in tables:
ps(ds, cm)
return self.check_linuxgit()
- def add_configuration(self, hash, cfile, generator):
+ def add_configuration(self, hash, txtconfig, generator):
"Add configuration to database."
ps = self.db.prepare("""INSERT INTO configurations
- (hash, cfile, gtime, toolgit, linuxgit, generator)
+ (hash, config, gtime, toolgit, linuxgit, generator)
VALUES
($1, $2, $3, $4, $5, $6);
""")
gt = self.check_toolsgit()
lgt = self.check_linuxgit()
tm = datetime.datetime.now()
- ps(hash, cfile, tm, gt, lgt, generator)
+ ps(hash, '\n'.join(txtconfig), tm, gt, lgt, generator)
def get_configration(self, hash):
"Return configration id for inserted hash."
- ps = self.db.prepare("""SELECT id, cfile FROM configurations
+ ps = self.db.prepare("""SELECT id, config FROM configurations
WHERE hash = $1""")
rtn = []
for dt in ps(hash):
- rtn.append(Config(dt[0], hash, dt[1]))
+ rtn.append(Config(dt[0], hash, dt[1].split('\n')))
return rtn
- def add_measure(self, mfile, conf_id, value = None):
+ def add_measure(self, output, result, conf_id, value = None):
"Add measurement."
ps = self.db.prepare("""INSERT INTO measure
- (conf, mfile, value, mtime, toolgit, linuxgit, measurement)
+ (conf, output, value, mtime, toolgit,
+ linuxgit, measurement, result)
VALUES
- ($1, $2, $3, $4, $5, $6, $7);
+ ($1, $2, $3, $4, $5, $6, $7, $8);
""")
gt = self.check_toolsgit()
lgt = self.check_linuxgit()
tm = datetime.datetime.now()
- ps(conf_id, mfile, value, tm, gt, lgt, conf.measure_identifier)
+ ps(conf_id, output, value, tm, gt, lgt, conf.measure_identifier, result)
def update_measure(self, measure_id, value):
"Update measured value"
def get_measures(self, conf_id):
"Get measures for configuration with conf_id id"
- ps = self.db.prepare("""SELECT id, mfile, value FROM measure
+ ps = self.db.prepare("""SELECT id, output, value FROM measure
WHERE conf = $1;
""")
rtn = []
def get_unmeasured(self):
"Returns list of all unmeasured configurations."
- ps = self.db.prepare("""SELECT * FROM configurations
- WHERE NOT EXISTS
+ # FIXME: Take into account case when we want the same
+ # configuration for either different experiment or kernel
+ # version or target.
+ ps = self.db.prepare("""SELECT id, hash, config FROM configurations
+ WHERE id NOT IN
(SELECT conf FROM measure)
""")
rtn = []
for dt in ps():
- rtn.append(Config(dt[0], dt[1], dt[2]))
+ rtn.append(Config(dt[0], dt[1], dt[2].split('\n')))
+ return rtn
+
+ def add_configsort(self, configopt):
+ "Add configuration option to sorted list"
+ ps = self.db.prepare("""INSERT INTO configopt
+ (configopt) VALUES ($1)
+ """)
+ ps(configopt)
+
+ def get_configsort(self):
+ "Returns sorted list of all configuration options"
+ ps = self.db.prepare("""SELECT id, configopt FROM configopt
+ ORDER BY id ASC
+ """)
+ rtn = []
+ itms = ps()
+ for id, config in itms:
+ rtn.append(config)
return rtn