This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
forked from basicthinker/YCSB-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_result.py
executable file
·88 lines (75 loc) · 2.71 KB
/
plot_result.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
#!/usr/bin/env python3
## plot result of YCSB
# example of dir format
# --- result dir
# \-- pxno
# \-- workloada.result
# |-- workloadb.result
# |-- rocksdb
# \-- workloada.result
# |-- workloadb.result
import matplotlib.pyplot as plt
import numpy as np
import sys
import os
def main():
if len(sys.argv) != 2 or sys.argv[1] == '-h':
print("Usage: {} [result dir]".format(sys.argv[0]))
sys.exit(-1)
result_dir = sys.argv[1]
result_suffix = ".png"
entries = os.listdir(result_dir)
db_names = [f for f in entries if os.path.isdir(os.path.join(result_dir, f))]
workloads = ['workloada', 'workloadb', 'workloadc', 'workloadd', 'workloadf']
threads = 0
results = {}
for db in db_names:
path = [os.path.join(result_dir, db, w + ".result") for w in workloads]
for f in path:
lines = [line.strip().split() for line in open(f)]
for line in lines:
if line[0][0] == '#':
continue
num_threads = int(line[0])
threads = max(threads, num_threads)
throughput = float(line[1])
dir_name, workload = os.path.split(f)
workload = os.path.splitext(workload)[0]
if db not in results:
results[db] = {}
if workload not in results[db]:
results[db][workload] = {}
if num_threads not in results[db][workload]:
results[db][workload][num_threads] = []
results[db][workload][num_threads].append(throughput)
width = 0.3
fig, ax = plt.subplots()
db_results = {}
shift = np.linspace(-len(db_names), len(db_names), len(db_names)) * (width / len(db_names))
for workload in workloads:
ax.clear()
count = 0
for db in db_names:
keys = sorted(results[db][workload].keys())
x = list(keys)
xa = x + shift[count]
va = []
for key in keys:
va.append(max(results[db][workload][key]))
bar = ax.bar(xa, va, width, label=db)
ax.set_ylabel('throughput [KOPS]')
ax.set_xlabel('threads')
ax.set_title(workload)
ax.set_xticks(x)
ax.legend()
if workloads not in workloads:
db_results[workload] = {}
if db not in db_results[workload]:
db_results[workload][db] = []
db_results[workload][db].append(bar)
count += 1
fig.tight_layout()
result_fig = os.path.join(result_dir, workload + result_suffix)
plt.savefig(result_fig)
if __name__ == '__main__':
main()