forked from rgouicem/a2a-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
executable file
·137 lines (114 loc) · 4.74 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
#!/usr/bin/env python3
import argparse, logging
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sbs
#########################################
# Parse the command line arguments
parser = argparse.ArgumentParser(description="Plot facility")
parser.add_argument('-i', '--input', required=True,
help='Pickle/csv file where benchmark results are stored.')
parser.add_argument('-o', '--output', required=True,
help='Output PDF file.')
parser.add_argument('-b', '--baseline', required=True,
help='Baseline to use for comparison, in the format arch,runtime,tag.')
parser.add_argument('-v', '--verbose', action='count', default=0,
help='Set the verbosity level')
args = parser.parse_args()
# Setup logging
try:
logging.basicConfig(format='[%(levelname)s] %(message)s',
level={ 0: logging.ERROR,
1: logging.WARNING,
2: logging.INFO,
3: logging.DEBUG }[args.verbose])
except:
logging.basicConfig(format='[%(levelname)s] %(message)s',
level=logging.DEBUG)
# Read input file
if args.input.endswith(".csv"):
df = pd.read_csv(args.input, sep=';')
else:
df = pd.read_pickle(args.input)
# Parse baseline arg
try:
base_arch, base_runtime, base_tag = args.baseline.split(',')
except ValueError:
logging.error('Wrong format for baseline argument. Expecting arch,runtime,tag.')
exit(1)
# Extract baseline from dataframe
base_df = df.loc[(df['arch'] == base_arch) & (df['runtime'] == base_runtime) & (df['tag'] == base_tag)]
# Get the mean for each baseline benchmark
base_means = {}
for b in set(base_df['bench']):
base_means[b] = np.array(base_df.loc[base_df['bench'] == b]['value'].values, dtype=np.float32).mean()
# print(f"{b};{base_means[b]:.2f}")
# Print the mean of every benchmark for each runtime
mean_df = pd.DataFrame(columns=['bench',
# 'none',
'master',
'no-fences',
# 'new-mappings'
])
for b in sorted(set(df['bench'])):
df_b = df.loc[df['bench'] == b]
tmp_dict = { 'bench': b }
for t in set(df_b['tag']):
df_b_t = df_b.loc[df_b['tag'] == t]
tmp_dict[t] = np.mean(df_b_t['value'])
mean_df = mean_df.append(tmp_dict, ignore_index=True)
print(mean_df)
# Normalize all results from original df to these means
df_norm = pd.DataFrame(columns=['arch', 'bench', 'dataset', 'threads', 'unit', 'value', 'runtime',
'tag', 'norm', 'label'])
norm_vals = []
for row in df.itertuples():
try:
if row.arch == base_arch and row.runtime == base_runtime and row.tag == base_tag:
continue
# norm = base_means[row.bench] / float(row.value) # speedup
norm = float(row.value) / base_means[row.bench] # relative perf
# norm = 100 * (base_means[row.bench] - float(row.value)) / base_means[row.bench]
dct = row._asdict()
dct['norm'] = norm
dct['label'] = f"{dct['tag']}"
# dct['label'] = f"{dct['runtime']}-{dct['tag']}"
del dct['Index']
del dct['cmdline']
norm_vals.append(dct)
except KeyError:
pass
df_norm = df_norm.append(norm_vals, ignore_index=True)
# Plot
fig = plt.figure(figsize=(10, 3))
palette = sbs.color_palette("muted")
# palette ={"native-none": "C0", "qemu-master": "C4", "qemu-no-fences": "C1", "qemu-new-mappings": "C2"}
# df_norm = df_norm.loc[df_norm['label'] != 'qemu-master']
ax = sbs.barplot(data=df_norm, ci='sd',
x='bench', y='norm',
# x='norm', y='bench',
hue='label', palette=palette,
order=sorted(set(df_norm['bench'])))
plt.grid(b=True, axis='y')
# plt.grid(b=True, axis='x')
plt.xticks(# ticks=list(range(0, len(set(base_df['bench'])))),
# labels=
rotation=45, ha="right", fontsize='x-small')
# plt.ylim(0, 1.1)
# plt.ylim(0, 22)
# plt.yticks(ticks=np.arange(0, 25, step=5))
# plt.yticks(ticks=np.arange(0, 1.1, step=.1))
plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.15),borderaxespad=0, ncol=4)
# ax.get_legend().remove()
ax.set_axisbelow(True)
plt.xlabel("")
# plt.xlabel("Speedup compared to vanilla QEMU")
# plt.ylabel("Speedup w.r.t. QEMU")
plt.ylabel("Runtime relative to qemu-master")
plt.axhline(y=1, xmin=0, xmax=1, color='red')
# Annotate the raw value of the baseline
for idx, value in enumerate(sorted(set(base_means))):
plt.text(idx - .2, 1.02, f"{base_means[value]:.1f}", fontsize='xx-small')
plt.savefig(args.output, dpi=500, bbox_inches='tight')
# plt.show()