-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplot.py
166 lines (135 loc) · 4.27 KB
/
plot.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
166
#!/bin/env python3
# SPDX-License-Identifier: BSD-3-Clause
#
# Authors: Alexander Jung <[email protected]>
#s
import os
import csv
import sys
import fire
import numpy as np
from time import gmtime
from time import strftime
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from common import sizeof_fmt, common_style, mk_groups, KBYTES, SMALL_SIZE, MEDIUM_SIZE, LARGE_SIZE
from os import listdir, makedirs
import pprint
pp = pprint.PrettyPrinter(indent=4)
def plot(data=None, output=None):
WORKDIR = os.getcwd()
RESULTSDIR = data
RESULTEXT = '.csv'
GROUP_BAR_WIDTH = .4
DEFAULT = '_'
THROUGHPUT = 'throughput'
MEAN_KEY = 'mean'
MEDIAN_KEY = 'median'
AMAX_KEY = 'amax'
AMIN_KEY = 'amin'
files = []
labels = []
apps = []
stats = {}
throughput_max = 0 # maximum observed throughput
total_apps = 0
bar_color = '#5697C4'
labels = {
'mimalloc': 'Mimalloc',
'tlsf': 'TLSF',
'buddy': 'Binary Buddy',
'tinyalloc': 'tinyalloc',
}
for f in os.listdir(RESULTSDIR):
if f.endswith(RESULTEXT):
unikernel = f.replace(RESULTEXT,'')
if unikernel not in stats:
stats[unikernel] = {
MEAN_KEY: 0,
MEDIAN_KEY: 0,
AMAX_KEY: 0,
AMIN_KEY: 0
}
with open(os.path.join(RESULTSDIR, f), 'r') as csvfile:
csvdata = csv.reader(csvfile, delimiter="\t")
next(csvdata) # skip header
throughput = []
for row in csvdata:
throughput.append(float(row[0]) / 1000)
throughput = np.array(throughput)
throughput = {
MEAN_KEY: np.average(throughput),
MEDIAN_KEY: np.median(throughput),
AMAX_KEY: np.amax(throughput),
AMIN_KEY: np.amin(throughput)
}
if throughput[AMAX_KEY] > throughput_max:
throughput_max = throughput[AMAX_KEY]
stats[unikernel] = throughput
# General style
common_style(plt)
throughput_max += 80 # margin above biggest bar
# Setup matplotlib axis
fig = plt.figure(figsize=(8, 5))
renderer = fig.canvas.get_renderer()
# image size axis
ax1 = fig.add_subplot(1,1,1)
ax1.set_ylabel("Average Throughput (x1000 req/s)")
ax1.grid(which='major', axis='y', linestyle=':', alpha=0.5, zorder=0)
ax1_yticks = np.arange(0, throughput_max, step=40)
ax1.set_yticks(ax1_yticks, minor=False)
ax1.set_yticklabels(["%3.0f" % ytick for ytick in ax1_yticks])
ax1.set_ylim(0, throughput_max)
# Plot coordinates
scale = 1. / len(stats.keys())
xlabels = []
# Adjust margining
# fig.subplots_adjust(bottom=.15) #, top=1)
i = 0
line_offset = 0
for unikernel in labels.keys():
xlabels.append(labels[unikernel])
throughput = stats[unikernel]
yerr = throughput[AMAX_KEY] - throughput[AMIN_KEY]
print(unikernel, throughput[MEAN_KEY], '+/-', yerr)
# Plot each application
bar = ax1.bar([i + 1], throughput[MEAN_KEY],
label=unikernel,
align='center',
zorder=4,
yerr=throughput[AMAX_KEY]-throughput[AMIN_KEY],
error_kw=dict(lw=2, capsize=10, capthick=1),
width=GROUP_BAR_WIDTH,
color=bar_color,
linewidth=.5
)
ax1.text(i + 1, throughput[MEAN_KEY] + yerr + 1, "%3.1f" % throughput[MEAN_KEY],
ha='center',
va='bottom',
zorder=6,
fontsize=LARGE_SIZE,
linespacing=0,
bbox=dict(pad=-.6, facecolor='white', linewidth=0),
rotation='vertical'
)
i += 1
# sys.exit(1)
# set up x-axis labels
xticks = range(1, len(xlabels) + 1)
ax1.set_xticks(xticks)
# ax1.set_xticklabels(xlabels, fontsize=LARGE_SIZE, rotation=45, ha='right', rotation_mode='anchor')
ax1.set_xticklabels(xlabels, fontsize=LARGE_SIZE, fontweight='bold')
ax1.set_xlim(.5, len(xlabels) + .5)
ax1.yaxis.grid(True, zorder=0, linestyle=':')
ax1.tick_params(axis='both', which='both', length=0)
# Create a unique legend
# handles, labels = plt.gca().get_legend_handles_labels()
# by_label = dict(zip(labels, handles))
# leg = plt.legend(by_label.values(), by_label.keys(), loc='upper left', ncol=4)
# leg.get_frame().set_linewidth(0.0)
plt.setp(ax1.lines, linewidth=.5)
# Save to file
fig.tight_layout()
fig.savefig(output) #, bbox_extra_artists=(ax1,), bbox_inches='tight')
if __name__ == '__main__':
fire.Fire(plot)