-
Notifications
You must be signed in to change notification settings - Fork 6
/
run_bench.py
120 lines (103 loc) · 3.62 KB
/
run_bench.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''
Python script to run microbenchmark for different
index structure
'''
import json
import optparse
import os
import subprocess
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
g_insertOnly = False
def getThroughput(wl):
fp = open("tmp").readlines()
if wl == 'a' or wl == 'd' or wl == 'b' or wl == 'f':
searchStr = "read/update"
elif wl == 'c' and g_insertOnly == False:
searchStr = "read"
elif wl == 'c' and g_insertOnly == True:
searchStr = "insert"
else:
searchStr = "insert/scan"
for line in fp:
w = line.split()
if w[0] == searchStr:
return w[1]
def plotgraph(plot_data, workload, key_type, threads, final_dir):
fig = plt.figure()
if g_insertOnly == False:
title = workload + '_' + key_type
else:
title = "insertOnly" + '_' + key_type
fig.suptitle(title)
ax = fig.add_subplot(111)
for keys in plot_data:
ax.plot(threads, plot_data[keys], marker='o', linestyle='-', label = keys)
ax.set_xlabel('threads')
ax.set_ylabel('Mops/s')
ax.legend(loc = 'upper left')
fig.savefig(final_dir + title + '.png')
###################
parser = optparse.OptionParser()
parser.add_option("-d", "--dest", default = "temp",
help = "destination folder")
parser.add_option("-c", "--config", default = "config.json",
help = "config file")
parser.add_option("-p", "--plot", default = False,
help = "plot only")
parser.add_option("-i", "--insert", default = False,
help = "insert only")
(opts, args) = parser.parse_args()
#Create result directory
result_dir = "./resutls/" + opts.dest + "/"
try:
os.stat(result_dir)
except:
os.makedirs(result_dir)
if opts.insert:
print "Insert Only"
g_insertOnly = True
## Make binary
if opts.plot == False:
print "Building binary"
status = subprocess.check_output('make clean; make', shell = True)
## Read config files
with open(opts.config) as json_data_file:
json_data = json.load(json_data_file)
for test in json_data:
data = json_data[test][0]
final_dir = result_dir + test + "/"
try:
os.stat(final_dir)
except:
os.makedirs(final_dir)
for workload in data["workloads"]:
for key_type in data["key_type"]:
plot_data = {}
for index in data["index"]:
plot_data[index] = []
if g_insertOnly:
log = final_dir + index + "_" + "insertOnly" + "_" + key_type
else:
log = final_dir + index + "_" + workload + "_" + key_type
log_file = open(log, "w+")
for threads in data["threads"]:
if key_type == "email":
cmd = "./workload_string " + workload + " " + key_type + " " + index
else:
cmd = "./workload " + workload + " " + key_type + " " + index
if g_insertOnly == True:
cmd = cmd + " " + str(threads) + " --insert-only"
else:
cmd = cmd + " " + str(threads)
print cmd
while os.system(cmd + " >> tmp") != 0:
pass
thp = getThroughput(workload)
print thp
os.system("rm -rf tmp")
log_file.write(str(threads) + " " + thp+ "\n")
plot_data[index].append(float(thp))
log_file.close()
plotgraph(plot_data, workload, key_type, data["threads"], final_dir)