forked from f18m/malloc-benchmarks
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_plot_results.py
executable file
·167 lines (129 loc) · 5.15 KB
/
bench_plot_results.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/python3
"""Generates some figures (plots) that shows all benchmarking results
"""
import sys
import os
import json
import matplotlib.pyplot as plt
filled_markers = ('o', 'v', '^', '<', '>', '8', 's', 'p', '*', 'h', 'H', 'D', 'd', 'P', 'X')
colours = ('r', 'g', 'b', 'black', 'yellow', 'purple')
def plot_graphs(outfilename, benchmark_dict):
"""Plots the given dictionary of benchmark results
"""
# print("outfilename = {}".format(outfilename))
# print("benchmark_dict = {}".format(benchmark_dict))
# any one of the data sets--just to grab some subtitle data that is common to all the data sets
a_key = list(benchmark_dict.keys())[0]
data_dict = benchmark_dict[a_key][0]
# print("data_dict = {}".format(data_dict))
# -------------------------
# Begin plot
# -------------------------
plt.figure()
plt.clf()
# main figure title
plt.suptitle("Malloc speed tests (tested w/glibc's `benchtests/bench-malloc-thread.c`)")
rows = 2
cols = 1
# -------------------------
# Subplot 1
# -------------------------
plt.subplot(rows, cols, 1)
# figure subtitle
plt.title("num bytes per malloc: min = {}; max = {}".format(data_dict["min_size"],
data_dict["max_size"]), fontsize=10, pad=30) # more `pad` shifts the subtitle UP more
plt.grid(alpha=.5) # alpha=0 is fully transparent; 1 is fully opaque
plt.xlabel('Number of threads')
# bench-malloc-thread uses RDTSC counter for reporting time => CPU clock cycles
plt.ylabel('CPU cycles per sum of (1 free + 1 malloc) op')
nmarker=0
max_x=[]
max_y=[]
for impl_name in benchmark_dict.keys():
data_list_of_dicts = benchmark_dict[impl_name]
# print("data_list_of_dicts = {}".format(data_list_of_dicts))
# add a line plot
X = [x["threads"] for x in data_list_of_dicts]
Y = [y["time_per_iteration"] for y in data_list_of_dicts]
lines = plt.plot(X, Y, '-' + filled_markers[nmarker], label=impl_name)
plt.setp(lines, 'color', colours[nmarker])
# remember max X/Y
# In case you only ran some of the tests, don't attempt to get `max()` on an empty list--ie:
# for a benchmark you didn't run. Only operate if the lists aren't empty.
if X:
max_x.append(max(X))
if Y:
max_y.append(max(Y))
nmarker=nmarker+1
# set some graph global properties:
plt.xlim(0, max(max_x)*1.1)
plt.ylim(0, max(max_y)*1.3)
plt.legend(loc='upper left')
# -------------------------
# Subplot 2
# -------------------------
plt.subplot(rows, cols, 2)
plt.grid(alpha=.5)
plt.xlabel('Number of threads')
plt.ylabel('Max Resident Set Size (RSS) RAM usage (in MB)')
nmarker=0
max_x=[]
max_y=[]
for impl_name in benchmark_dict.keys():
data_list_of_dicts = benchmark_dict[impl_name]
# add a line plot
X = [x["threads"] for x in data_list_of_dicts]
# rss default units are in kB, so convert to MB
Y = [y["max_rss"]/1000 for y in data_list_of_dicts]
lines = plt.plot(X, Y, '-' + filled_markers[nmarker], label=impl_name)
plt.setp(lines, 'color', colours[nmarker])
# remember max X/Y
if X:
max_x.append(max(X))
if Y:
max_y.append(max(Y))
nmarker=nmarker+1
# set some graph global properties:
plt.xlim(0, max(max_x)*1.1)
plt.ylim(0, max(max_y)*1.3)
plt.legend(loc='upper left')
# -------------------------
# Save and show plots
# -------------------------
outfilename_dir = os.path.dirname(outfilename)
print("Writing plot into '%s'" % outfilename)
print(("- - -\n" +
"Close the plot to terminate the program. Run `RESULT_DIRNAME='{}' make plot_results`\n" +
"to plot the results again.\n" +
"- - -").format(outfilename_dir))
figure = plt.gcf() # get current figure
figure.set_size_inches(9, 9)
plt.savefig(outfilename, dpi=200)
print("Done.")
plt.show()
def main(args):
"""Program Entry Point
"""
if len(args) < 2:
print('Usage: %s <image-output-file> <file1> <file2> ...' % sys.argv[0])
sys.exit(os.EX_USAGE)
benchmark_dict = {}
for filepath in args[1:]:
print("Parsing '{}'...".format(filepath))
with open(filepath, 'r') as benchfile:
filename = os.path.basename(filepath)
try:
bench_list_of_dicts = json.load(benchfile)
except Exception as ex:
print("Invalid JSON file {}: {}".format(filepath, ex))
sys.exit(2)
# print(json.dumps(bench_list_of_dicts, sort_keys=True, indent=4,
# separators=(',', ': ')))
benchmark_dict[filename] = []
for bench in bench_list_of_dicts:
data_dict = bench["functions"]["malloc"][""]
benchmark_dict[filename].append(data_dict)
print(' Found {} data points in {}...'.format(len(benchmark_dict[filename]), filepath))
plot_graphs(args[0], benchmark_dict)
if __name__ == '__main__':
main(sys.argv[1:])