-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_ycsb.py
261 lines (229 loc) · 8.41 KB
/
plot_ycsb.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import argparse
import seaborn as sns
import pandas as pd
from pandas import DataFrame
from re import search, findall, MULTILINE
from os.path import basename, getsize
from typing import List
from dataclasses import dataclass, field, asdict
COLORS = [ str(i) for i in range(20) ]
# COLORS = mcolors.CSS4_COLORS.keys()
# COLORS = [
# 'blue',
# 'cyan',
# 'green',
# 'yellow',
# 'orange',
# 'red',
# 'magenta',
# ]
hue_map = {
'2.0_bridge_-1.0_overall': 'qemu-virtio',
'2.0_bridge-e1000_-1.0_overall': 'qemu-e1000',
'2.0_bridge-vhost_-1.0_overall': 'qemu-vhost',
'2.0_vfio_-1.0_overall': 'qemu-pt',
'2.0_vmux-dpdk-e810_-1.0_overall': 'vmux-emu-e810',
'2.0_vmux-emu_-1.0_overall': 'vmux-emu-e1000',
'2.0_vmux-med_-1.0_overall': 'vmux-med-e810'
}
YLABEL = 'Per-VM req/s'
XLABEL = ' Nr. of VMs'
def map_hue(df_hue, hue_map):
return df_hue.apply(lambda row: hue_map.get(str(row), row))
def setup_parser():
parser = argparse.ArgumentParser(
description='Plot packet loss graph'
)
parser.add_argument('-t',
'--title',
type=str,
help='Title of the plot',
)
parser.add_argument('-W', '--width',
type=float,
default=12,
help='Width of the plot in inches'
)
parser.add_argument('-H', '--height',
type=float,
default=6,
help='Height of the plot in inches'
)
parser.add_argument('-o', '--output',
type=argparse.FileType('w+'),
help='''Path to the output plot
(default: packet_loss.pdf)''',
default='ycsb.pdf'
)
parser.add_argument('-l', '--logarithmic',
action='store_true',
help='Plot logarithmic latency axis',
)
for color in COLORS:
parser.add_argument(f'--{color}',
type=argparse.FileType('r'),
nargs='+',
help=f'''Paths to MoonGen measurement logs for
the {color} plot''',
)
for color in COLORS:
parser.add_argument(f'--{color}-name',
type=str,
default=color,
help=f'''Name of {color} plot''',
)
return parser
def parse_args(parser):
args = parser.parse_args()
if not any([args.__dict__[color] for color in COLORS]):
parser.error('At least one set of moongen log paths must be ' +
'provided')
return args
def parse_filename(self, filename: str):
ret = dict()
parts = filename.split("_")
ret['becnhmark'] = parts[0]
ret['num_vms']
def parse_result(self, repetition: int, vm_number: int) -> DataFrame:
def find(haystack: List[str], needle: str) -> str:
matches = [line for line in haystack if needle in line ]
if len(matches) != 1:
raise Exception("Seemingly an error occured during execution")
value = matches[0].split(" ")[-1]
return value
with open(self.output_path_per_vm(repetition, vm_number), 'r') as file:
lines = file.readlines()
data = []
test_spec = {
**asdict(self), # put selfs member variables and values into this dict
"repetition": repetition,
"vm_number": vm_number,
}
data += [{
**test_spec,
"op": "read",
"avg_us": float(find(lines, "[READ], AverageLatency(us),")),
"95th_us": float(find(lines, "[READ], 95thPercentileLatency(us),")),
"99th_us": float(find(lines, "[READ], 99thPercentileLatency(us),")),
"ops": int(find(lines, "[READ], Operations,"))
}]
data += [{
**test_spec,
"op": "update",
"avg_us": float(find(lines, "[UPDATE], AverageLatency(us),")),
"95th_us": float(find(lines, "[UPDATE], 95thPercentileLatency(us),")),
"99th_us": float(find(lines, "[UPDATE], 99thPercentileLatency(us),")),
"ops": int(find(lines, "[UPDATE], Operations,"))
}]
data += [{
**test_spec, # merge test_spec dict with this dict
"op": "overall",
"runtime": float(find(lines, "[OVERALL], RunTime(ms),")),
"ops_per_sec": float(find(lines, "[OVERALL], Throughput(ops/sec),"))
}]
return DataFrame(data=data)
def cast_column(df, column: str, caster = lambda i: int(i)):
df[column] = df.apply(lambda row: caster(row[column]), axis=1)
def main():
parser = setup_parser()
args = parse_args(parser)
sns.set_theme()
sns.set_style("whitegrid")
fig = plt.figure(figsize=(args.width, args.height))
ax = fig.add_subplot(1, 1, 1)
ax.set_axisbelow(True)
if args.title:
plt.title(args.title)
plt.grid()
# plt.xlim(0, 0.83)
ax.set_yscale('log' if args.logarithmic else 'linear')
dfs = []
for color in COLORS:
if args.__dict__[color]:
arg_dfs = [ pd.read_csv(f.name) for f in args.__dict__[color] ]
arg_df = pd.concat(arg_dfs)
name = args.__dict__[f'{color}_name']
arg_df["hue"] = name
dfs += [ arg_df ]
df = pd.concat(dfs, ignore_index=True)
del df['Unnamed: 0']
df = df[df.op == 'overall'] # only the overall stat has ops_per_sec
hue = ['repetitions', 'num_vms', 'interface', 'fastclick']
# groups = df.groupby(hue)
# summary = df.groupby(hue)['rxMppsCalc'].describe()
df_hue = df.apply(lambda row: '_'.join(str(row[col]) for col in ['repetitions', 'interface', 'rps', 'op']), axis=1)
df_hue = map_hue(df_hue, hue_map)
df['aggregate_ops_per_sec'] = df.apply(lambda row: row['num_vms'] * row['ops_per_sec'], axis=1)
# df['aggregate_ops_per_sec'] = df.apply(lambda row: print(row), axis=1)
# cast_column(df, 'num_vms', lambda i: int(i))
cast_column(df, 'num_vms', int)
markers = []
for hue in df['hue'].unique():
if hue == 'Qemu-pt':
markers += [ 'o' ]
elif "vMux" in hue:
markers += [ 'o' ]
else:
markers += [ 'X' ]
linestyles = []
for hue in df['hue'].unique():
if "vMux" in hue:
linestyles += [ '-' ]
else:
linestyles += [ ':' ]
# markers = { 'vMux-emu-e810': 'x' }
# markers = [ 'x', '.', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' ]
# linestyles = [ '-', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--', '--']
# Plot using Seaborn
sns.pointplot(x='num_vms', y='ops_per_sec', hue="hue", data=df, palette='colorblind',
# kind='point',
err_kws={'linewidth': 1},
capsize=.01, # errorbar='sd'
markers=markers,
# linestyles=['-', '--'],
linestyles=linestyles,
linewidth=2,
markeredgecolor='white',
markersize=6,
markeredgewidth=1,
native_scale=True,
log_scale=(True, False),
)
sns.move_legend(
ax, "upper left",
bbox_to_anchor=(1, 1),
ncol=1,
title=None,
frameon=False,
)
ax.annotate(
"↑ Higher is better", # or ↓ ← ↑ →
xycoords="axes points",
# xy=(0, 0),
xy=(0, 0),
xytext=(-55, -34),
# fontsize=FONT_SIZE,
color="navy",
weight="bold",
)
# plt.subplots_adjust(right=0.3)
plt.xlabel(XLABEL)
plt.ylabel(YLABEL)
plt.ylim(bottom=0)
plt.xlim(right=110)
# for container in ax.containers:
# ax.bar_label(container, fmt='%.0f')
sns.despine()
# legend = plt.legend()
# legend.get_frame().set_facecolor('white')
# legend.get_frame().set_alpha(0.8)
fig.tight_layout(pad=0.1)
# plt.subplots_adjust(bottom=0.28)
plt.savefig(args.output.name)
plt.close()
if __name__ == '__main__':
main()