-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_container_states.py
More file actions
97 lines (83 loc) · 3.37 KB
/
plot_container_states.py
File metadata and controls
97 lines (83 loc) · 3.37 KB
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
import sys
import json
import numpy as np
import matplotlib.pyplot as plt
from pprint import pprint
if len(sys.argv) != 1:
usage = '''[Usage]: python3 plot_results.py
'''
print(usage)
exit(1)
strats = [
"lru",
"mru",
"mfe",
"pq",
"naive"
]
periods = [5, 10, 15]
total_cold_container_stats = {
5: {},
10: {},
15: {},
}
total_warm_container_stats = {
5: {},
10: {},
15: {},
}
total_prewarmed_container_stats = {
5: {},
10: {},
15: {},
}
total_recreated_container_stats = {
5: {},
10: {},
15: {},
}
for strat in strats:
for period in periods:
if strat == "naive":
prefix = "naive"
else:
prefix = f"{strat}_{period}"
with open(f"./{prefix}/results.json", "r") as f:
json_data = json.load(f)
for fun_name in json_data.keys():
if fun_name == "languages":
continue
if strat in total_cold_container_stats[period]:
total_cold_container_stats[period][strat] += json_data[fun_name]["coldContainerCount"]
else:
total_cold_container_stats[period][strat] = 0
if strat in total_warm_container_stats[period]:
total_warm_container_stats[period][strat] += json_data[fun_name]["warmedContainerCount"]
else:
total_warm_container_stats[period][strat] = 0
if strat in total_prewarmed_container_stats[period]:
total_prewarmed_container_stats[period][strat] += json_data[fun_name]["prewarmedContainerCount"]
else:
total_prewarmed_container_stats[period][strat] = 0
if strat in total_recreated_container_stats[period]:
total_recreated_container_stats[period][strat] += json_data[fun_name]["recreatedContainerCount"]
else:
total_recreated_container_stats[period][strat] = 0
pprint(total_cold_container_stats)
for period in periods:
period = int(period)
fig_title = f"Period {period}"
fig, axs = plt.subplots(1, 1)
bottom = np.zeros(len(strats))
print(total_cold_container_stats.keys())
print(total_cold_container_stats[period].values())
axs.bar(total_cold_container_stats[period].keys(), total_cold_container_stats[period].values(), label="Cold", color="blue")
axs.bar(total_warm_container_stats[period].keys(), total_warm_container_stats[period].values(), bottom=np.array(list(total_cold_container_stats[period].values())), label="Warmed", color="red")
axs.bar(total_prewarmed_container_stats[period].keys(), total_prewarmed_container_stats[period].values(), bottom=np.array(list(total_cold_container_stats[period].values())) + np.array(list(total_warm_container_stats[period].values())),label="Prewarmed", color="salmon")
axs.bar(total_recreated_container_stats[period].keys(), total_recreated_container_stats[period].values(), label="Recreated", bottom=np.array(list(total_cold_container_stats[period].values())) + np.array(list(total_warm_container_stats[period].values())) + np.array(list(total_prewarmed_container_stats[period].values())), color="dodgerblue")
plt.title(f"Total number of containers for period {period}")
plt.xlabel("Strategy")
plt.ylabel("Number of container starts")
plt.legend()
plt.savefig(fig_title + ".png", bbox_inches="tight")
plt.clf()