Mercurial > hg > truffle
comparison mx/benchmarkdb.py @ 4150:c78bace5086a
start work on integrating old hooks into mx, work on sanity checks
introduce a DB class to access the bench DB in an easier way (create benchmarks and benchmark values automatically in the DB)
author | Gilles Duboscq <gilles.m.duboscq@gmail.com> |
---|---|
date | Tue, 20 Dec 2011 15:34:43 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4149:cf4de9cc1268 | 4150:c78bace5086a |
---|---|
1 import sqlite3 | |
2 | |
3 class BenchmarkDb: | |
4 def __init__(self, path): | |
5 self.con = sqlite3.connect(path) | |
6 c = self.con.cursor(); | |
7 c.execute('pragma foreign_keys = on') | |
8 c.execute('create table if not exists results (revnum integer, foreign key(benchmarkid) references benchmarks(benchmarkid), foreign key(valueid) references benchmarkvalues(valueid), value real)') | |
9 c.execute('create table if not exists benchmarks (benchmarkid integer primary key autoincrement, name text)') | |
10 c.execute('create table if not exists benchmarkvalues (valueid integer primary key autoincrement, name text)') | |
11 self.con.commit() | |
12 c.close() | |
13 | |
14 def insertResults(self, revision, results): | |
15 c = self.con.cursor() | |
16 for result in results: | |
17 if not result.has_key('benchmark'): | |
18 continue | |
19 benchmarkName = result['benchmark'] | |
20 del result['benchmark'] | |
21 if len(result.keys()) <= 0: | |
22 continue | |
23 | |
24 benchIdRow = c.execute('select benchmarkid from benchmarks where name="' + benchmarkName + '"').fetchone() | |
25 benchId = -1; | |
26 if benchIdRow is None: | |
27 c.execute('insert into benchmarks (name) values ("' + benchmarkName + '") values ') | |
28 benchId = c.lastrowid() | |
29 else: | |
30 benchId = benchIdRow['benchmarkid'] | |
31 | |
32 insertcmd = 'insert into results (revnum, benchmarkid, valueid, value) ' | |
33 first = True | |
34 for valueName in result.keys(): | |
35 valueIdRow = c.execute('select valueid from benchmarkvalues where name="' + valueName + '"').fetchone() | |
36 valueId = -1; | |
37 if valueIdRow is None: | |
38 c.execute('insert into benchmarkvalues (name) values ("' + valueName + '")') | |
39 valueId = c.lastrowid() | |
40 else: | |
41 valueId = benchIdRow['valueid'] | |
42 | |
43 if first: | |
44 insertcmd = insertcmd + 'select ' + str(revision) + ' as revnum, ' + str(benchId) + ' as benchmarkid, ' + str(valueId) + ' as valueid, ' + result[valueName] + ' as value ' | |
45 else: | |
46 insertcmd = insertcmd + 'union select ' + str(revision) + ', ' + str(benchId) + ', ' + str(valueId) + ', ' + result[valueName] + ' ' | |
47 c.execute(insertcmd) | |
48 self.con.commit() | |
49 c.close() | |
50 | |
51 def close(self): | |
52 self.con.close() |