forked from unikraft/eurosys21-artifacts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
122 lines (101 loc) · 2.99 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
#!/bin/env python3
#
# Authors: Alexander Jung <[email protected]>
#
import sys
import csv
import fire
import os.path
import matplotlib.pyplot as plt
from platform import python_version as pythonversion
from matplotlib import __version__ as matplotlibversion
def crosstick(label="X"):
if label == "V":
return "✓"
else:
return "✗"
def plot(data=None, output=None):
if not os.path.isfile(data):
print("cannot find: %s" % data)
sys.exit(1)
# platform_labels = {
# 'linux': 'Linux/KVM',
# 'linux-nomitig': 'Linux/KVM',
# 'unikraft': 'Unikraft/KVM',
# 'both': 'Both'
# }
# rcall_labels = {
# 'scall': 'System call',
# 'scall-nomitig': 'System call (no mitigations)',
# 'fcall': 'Function Call'
# }
col_labels = {
'name': 'Library',
'musl-size': 'musl\nsize\n(MB)',
'musl-std': 'musl\nstd.',
'musl-compat': 'musl\ncompat.\nlayer',
'newlib-size': 'newlib\nsize\n(MB)',
'newlib-std': 'newlib\nstd.',
'newlib-compat': 'newlib\ncompat.\nlayer',
'cloc': 'Glue\nCode\nLoC'
}
parsed = {}
table_vals = []
with open(data, 'r') as csvfile:
csvdata = csv.reader(csvfile, delimiter=",")
next(csvdata) # skip header
# curr = None
for row in csvdata:
parsed[row[0]] = {
'musl-size': row[1],
'musl-std': row[2],
'musl-compat': row[3],
'newlib-size': row[4],
'newlib-std': row[5],
'newlib-compat': row[6],
'cloc': row[7]
}
# Setup matplotlib axis
fig = plt.figure(figsize=(13, 20))
renderer = fig.canvas.get_renderer()
# image size axis
ax1 = fig.add_subplot(1,1,1)
col_labels = [
col_labels[k] for k in col_labels
]
for lib in parsed:
table_vals.append([
lib,
parsed[lib]['musl-size'],
crosstick(parsed[lib]['musl-std']),
crosstick(parsed[lib]['musl-compat']),
parsed[lib]['newlib-size'],
crosstick(parsed[lib]['newlib-std']),
crosstick(parsed[lib]['newlib-compat']),
parsed[lib]['cloc']
])
# Draw table
table = plt.table(cellText=table_vals,
colWidths=[0.12, 0.05, 0.04, 0.06, 0.05, 0.05, 0.06, 0.05],
colLabels=col_labels,
loc='center',
cellLoc='left')
# set header cell height
cellDict = table.get_celld()
for i in range(0,len(col_labels)):
cellDict[(0,i)].set_height(.02)
# for j in range(1,len(table_vals)+1):
# cellDict[(j,i)].set_height(.01)
table.auto_set_font_size(False)
table.set_fontsize(24)
table.scale(3, 4)
# Removing ticks and spines enables you to get the figure only with table
plt.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
plt.tick_params(axis='y', which='both', right=False, left=False, labelleft=False)
for pos in ['right','top','bottom','left']:
plt.gca().spines[pos].set_visible(False)
# Save to file
fig.tight_layout()
plt.savefig(output)
if __name__ == '__main__':
fire.Fire(plot)