-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_results.py
More file actions
257 lines (193 loc) · 10.7 KB
/
Copy pathplot_results.py
File metadata and controls
257 lines (193 loc) · 10.7 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
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
import os
import glob
import json
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
def load_data():
log_dir = "logs"
lista_file = glob.glob(f"{log_dir}/client_stats_*.json")
summary_data = []
raw_data = []
for file in lista_file:
if not os.path.isfile(file):
continue
try:
base_name = os.path.basename(file).replace('.json', '')
parts = base_name.split('_')
resolution = int(parts[-1])
dispositivo = "_".join(parts[2:-1]) if len(parts) > 3 else "Edge_Device"
dispositivo = dispositivo.upper()
if dispositivo == "PISTRESS":
dispositivo = "PI_STRESS"
with open(file, 'r') as f:
content = json.load(f)
phases = content.get("phases", {})
acq = phases.get("client_image_acquisition", {})
offload = phases.get("client_ask_offloading", {})
inf = phases.get("client_local_inference", {})
net = phases.get("client_network_upload", {})
# ---------------------------------------------------
# DATI AGGREGATI (SUMMARY) PER GRAFICI A BARRE/LINEE
# ---------------------------------------------------
t_acq = acq.get("wall_time_ms", {}).get("mean", 0)
t_off = offload.get("wall_time_ms", {}).get("mean", 0)
t_inf = inf.get("wall_time_ms", {}).get("mean", 0)
t_net = net.get("wall_time_ms", {}).get("mean", 0) if net else 0
t_pipeline = t_off + t_inf + t_net
fps = (1000 / t_pipeline) if t_pipeline > 0 else 0
summary_data.append({
"Dispositivo": dispositivo,
"Risoluzione": resolution,
"Throughput Medio (FPS)": fps,
"Tempo Acq (ms)": t_acq,
"Tempo Offload (ms)": t_off,
"Tempo Inferenza (ms)": t_inf,
"Tempo Rete (ms)": t_net,
"RAM Processo (MB)": inf.get("memory_analysis", {}).get("ram_process_mb_mean", 0),
"Temp Media (°C)": inf.get("thermal_analysis", {}).get("cpu_temp_c_mean", 0),
"Temp Max (°C)": inf.get("thermal_analysis", {}).get("cpu_temp_c_max", 0)
})
# ---------------------------------------------------
# DATI GREZZI (RAW) PER I BOXPLOT
# ---------------------------------------------------
raw_acq = acq.get("wall_time_ms", {}).get("raw_values", [])
raw_off = offload.get("wall_time_ms", {}).get("raw_values", [])
raw_inf = inf.get("wall_time_ms", {}).get("raw_values", [])
raw_net = net.get("wall_time_ms", {}).get("raw_values", [])
if raw_inf:
min_len = min([len(l) for l in [raw_acq, raw_off, raw_inf] if len(l) > 0])
for i in range(min_len):
r_acq = raw_acq[i] if i < len(raw_acq) else 0
r_off = raw_off[i] if i < len(raw_off) else 0
r_inf = raw_inf[i] if i < len(raw_inf) else 0
r_net = raw_net[i] if raw_net and i < len(raw_net) else 0
r_totale = r_acq + r_off + r_inf + r_net
r_pipeline = r_off + r_inf + r_net
r_fps = (1000 / r_pipeline) if r_pipeline > 0 else 0
raw_data.append({
"Dispositivo": dispositivo,
"Risoluzione": resolution,
"FPS": r_fps,
"Latenza Totale (ms)": r_totale
})
except Exception as e:
print(f"⚠️ Errore leggendo {file}: {e}")
df_summary = pd.DataFrame(summary_data)
df_raw = pd.DataFrame(raw_data)
if not df_summary.empty:
df_summary = df_summary.sort_values(by=["Risoluzione", "Dispositivo"])
df_summary["Risoluzione"] = df_summary["Risoluzione"].astype(str)
if not df_raw.empty:
df_raw = df_raw.sort_values(by=["Risoluzione", "Dispositivo"])
df_raw["Risoluzione"] = df_raw["Risoluzione"].astype(str)
return df_summary, df_raw
def plot_charts(df_summary, df_raw):
out_dir = "grafici_benchmark"
os.makedirs(out_dir, exist_ok=True)
sns.set_theme(style="whitegrid")
has_multiple_devices = len(df_summary["Dispositivo"].unique()) > 1
# -------------------------------------------------------------
# 1. THROUGHPUT (FPS) - LOG SCALE ADDED + VALORI SUL BOXPLOT
# -------------------------------------------------------------
plt.figure(figsize=(10, 6))
if not df_raw.empty:
# Torniamo al boxplot pulito originale (senza punti neri!)
ax = sns.boxplot(data=df_raw, x="Risoluzione", y="FPS", hue="Dispositivo", palette="viridis", showfliers=False)
plt.title("1. Throughput Reale (Log Scale - FPS senza overhead)", fontsize=14, pad=15)
dispositivi = sorted(df_raw["Dispositivo"].unique())
risoluzioni = df_raw["Risoluzione"].unique()
n_hues = len(dispositivi)
offsets = np.linspace(0, 0.8 - 0.8/n_hues, n_hues)
offsets -= offsets.mean()
for i, res in enumerate(risoluzioni):
for j, dev in enumerate(dispositivi):
subset = df_raw[(df_raw["Risoluzione"] == res) & (df_raw["Dispositivo"] == dev)]
if not subset.empty:
med_val = subset["FPS"].median()
x_pos = i + offsets[j]
ax.text(x_pos, med_val, f"{med_val:.1f}",
ha='center', va='center', fontsize=9, color='black', fontweight='bold',
bbox=dict(facecolor='white', alpha=0.7, edgecolor='none', pad=1.5))
else:
ax = sns.barplot(data=df_summary, x="Risoluzione", y="Throughput Medio (FPS)", hue="Dispositivo", palette="viridis")
plt.title("1. Throughput Reale (Log Scale - Media FPS senza overhead)", fontsize=14, pad=15)
for container in ax.containers:
ax.bar_label(container, fmt='%.1f', padding=3, fontsize=9, color='black')
# ATTIVAZIONE SCALA LOGARITMICA
ax.set_yscale("log")
plt.grid(True, which="both", ls="--", alpha=0.4)
plt.ylabel("System FPS (Log Scale)")
plt.tight_layout()
plt.savefig(f"{out_dir}/1_throughput_fps.png", dpi=300)
plt.close()
# -------------------------------------------------------------
# 2. LATENCY BREAKDOWN (Stacked Bar) - LOG SCALE ADDED
# -------------------------------------------------------------
if has_multiple_devices:
g = sns.FacetGrid(df_summary, col="Dispositivo", height=6, aspect=1.2)
else:
g = sns.FacetGrid(df_summary, height=6, aspect=1.5)
def stacked_bar(*args, **kwargs):
data = kwargs.pop('data')
data_to_plot = data[["Risoluzione", "Tempo Acq (ms)", "Tempo Offload (ms)", "Tempo Inferenza (ms)", "Tempo Rete (ms)"]].set_index("Risoluzione")
ax = data_to_plot.plot(kind='bar', stacked=True, ax=plt.gca(), colormap="Spectral", legend=False)
ax.grid(True, axis='y', ls="--", alpha=0.4)
for container in ax.containers:
labels = [f'{v.get_height():.1f}' if v.get_height() > 0.1 else '' for v in container]
ax.bar_label(container, labels=labels, label_type='center', fontsize=8, color='black')
g.map_dataframe(stacked_bar)
g.set_axis_labels("Risoluzione Modello", "Latenza Media (ms) - Log Scale")
g.fig.suptitle("2. Latency Breakdown (Log Scale ms per inference)", y=1.05, fontsize=16)
handles, labels = plt.gca().get_legend_handles_labels()
g.fig.legend(handles, labels, title="Fasi dell'Architettura", bbox_to_anchor=(1.15, 0.5), loc='center right')
plt.savefig(f"{out_dir}/2_latency_breakdown_stacked.png", dpi=300, bbox_inches='tight')
plt.close()
# -------------------------------------------------------------
# 3. MEMORY PEAK
# -------------------------------------------------------------
plt.figure(figsize=(10, 6))
ax = sns.barplot(data=df_summary, x="Risoluzione", y="RAM Processo (MB)", hue="Dispositivo", palette="Purples_d")
# 🟢 ATTIVAZIONE SCALA LOGARITMICA (Rimuovi se preferisci lineare per la RAM)
ax.set_yscale("log")
plt.grid(True, which="both", ls="--", alpha=0.4)
# 🟢 Aggiungiamo i valori testuali sopra le barre
for container in ax.containers:
ax.bar_label(container, fmt='%.0f', padding=3, fontsize=9, color='black')
plt.title("3. Memory Footprint (Log Scale): RAM Usata dal Processo", fontsize=14, pad=15)
plt.ylabel("RAM Allocata (MB) - Log Scale")
plt.tight_layout()
plt.savefig(f"{out_dir}/3_memory_peak.png", dpi=300)
plt.close()
# -------------------------------------------------------------
# 4. THERMAL BEHAVIOR
# -------------------------------------------------------------
plt.figure(figsize=(10, 6))
df_temp = df_summary.melt(id_vars=["Dispositivo", "Risoluzione"], value_vars=["Temp Media (°C)", "Temp Max (°C)"], var_name="Misurazione", value_name="Gradi")
ax = sns.lineplot(data=df_temp, x="Risoluzione", y="Gradi", hue="Misurazione", style="Dispositivo", markers=True, dashes=False, linewidth=2.5, palette="rocket")
plt.axhline(y=80, color='r', linestyle='--', alpha=0.5, label="Throttling Limit (80°C)")
# 🟢 Aggiungiamo il valore esatto vicino al pallino
for index, row in df_temp.iterrows():
ax.annotate(f"{row['Gradi']:.1f}°",
(row['Risoluzione'], row['Gradi']),
textcoords="offset points",
xytext=(0, 10),
ha='center',
fontsize=8)
plt.title("4. Thermal Behavior: Media vs Picco Sotto Sforzo", fontsize=14, pad=15)
plt.ylabel("Temperatura (°C)")
handles, labels = plt.gca().get_legend_handles_labels()
plt.legend(handles=handles, labels=labels, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
plt.savefig(f"{out_dir}/4_thermal_behavior.png", dpi=300, bbox_inches='tight')
plt.close()
df_summary.to_csv(f"{out_dir}/confronto_benchmark_finale.csv", index=False)
print(f"✅ I grafici sono stati salvati nella cartella '{out_dir}/'!")
if __name__ == "__main__":
df_summ, df_r = load_data()
if not df_summ.empty:
print("📊 Dati estratti! Generazione grafici in corso...")
plot_charts(df_summ, df_r)
else:
print("⚠️ Nessun file trovato o nessun dato valido.")