-
Notifications
You must be signed in to change notification settings - Fork 6
/
run-bench
executable file
·101 lines (88 loc) · 3.51 KB
/
run-bench
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
import shutil
import os
import shlex
import subprocess
import sys
import argparse
import datetime
class Benchmark:
def __init__(self):
self.env = dict(os.environ)
self.now = datetime.datetime.utcnow()
self.db = None
def read_conffile(self, fd):
for line in fd:
line = line.strip()
if not line or line.startswith("#"): continue
if '=' in line:
key, val = line.split("=", 1)
val = shlex.split(val)[0]
if val.startswith("$"):
val = self.env[val[1:]]
self.env[key] = val
def select_db(self, name):
self.db = name
if name in ("pg", "postgresql"):
self.db = "postgresql"
self.env["DBA_DB"] = self.env["DBA_DB_POSTGRESQL"]
elif name == "mysql":
self.env["DBA_DB"] = self.env["DBA_DB_MYSQL"]
elif name == "sqlite":
self.env["DBA_DB"] = self.env["DBA_DB_SQLITE"]
elif name == "mem":
self.db = "mem"
self.env["DBA_DB"] = "mem:"
elif name == "sqlitev7":
self.env["DBA_DB"] = self.env["DBA_DB_SQLITE"]
self.env["DBA_DB_FORMAT"] = "V7"
elif name in ("pgv7", "postgresqlv7"):
self.db = "postgresqlv7"
self.env["DBA_DB"] = self.env["DBA_DB_POSTGRESQL"]
self.env["DBA_DB_FORMAT"] = "V7"
elif name == "mysqlv7":
self.db = "mysqlv7"
self.env["DBA_DB"] = self.env["DBA_DB_MYSQL"]
self.env["DBA_DB_FORMAT"] = "V7"
else:
raise RuntimeError("unknown database type {}".format(name))
def add_extra_env(self, assignments):
for arg in assignments:
if '=' in arg:
key, val = arg.split("=", 1)
self.env[key] = val
def build(self):
subprocess.check_call(["make", "-C", "dballe"])
subprocess.check_call(["make", "-C", "dballe", "bench-run"])
def run(self):
self.env["ARGS"] = self.db
csvout = subprocess.check_output(["../extra/runtest", "bench-run"], env=self.env, cwd="dballe", universal_newlines=True)
shasum = subprocess.check_output(["git", "rev-parse", "HEAD"], universal_newlines=True).strip()
ts = self.now.strftime("%Y%m%d%H%M%S")
fname = os.path.join("bench", "_".join((ts, self.db, shasum)) + ".csv")
with open(fname, "wt") as fd:
# Skip the Running... printed at the beginning by runtest
for line in csvout.splitlines()[1:]:
print(line, file=fd)
def main():
parser = argparse.ArgumentParser(description="Run DB-All.e benchmarks.")
parser.add_argument("env", nargs="*", help="Extra env var assignments")
parser.add_argument("-d", "--db", default=None, help="Database to use (pg/postgresql, mysql, sqlite, mem, sqlitev7, pgv7/postgresqlv7, mysqlv7)")
args = parser.parse_args()
bench = Benchmark()
for conffile in ("./run-check.conf", ".git/run-check.conf"):
if not os.path.exists(conffile): continue
with open(conffile, "rt") as fd:
bench.read_conffile(fd)
bench.add_extra_env(args.env)
bench.build()
if args.db is None:
for db in ("pg", "mysql", "sqlite", "mem", "sqlitev7", "postgresqlv7", "mysqlv7"):
print("Running benchmarks for {}...".format(db))
bench.select_db(db)
bench.run()
else:
bench.select_db(args.db)
bench.run()
if __name__ == "__main__":
main()