Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/server/communication/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ async def split_inference(request: Request):

if ricevuti_elementi != attesa_elementi:
error_msg = f"MISMATCH DIMENSIONI: attesi {attesa_elementi} elementi, ricevuti {ricevuti_elementi}."
print(f"[SERVER ERROR] {error_msg}")
logger.error(error_msg)
return JSONResponse(status_code=400, content={"error": error_msg})

# Ora puoi fare il reshape in sicurezza
Expand Down Expand Up @@ -433,7 +433,7 @@ async def split_inference(request: Request):
if float(np.max(grid[:, :, 1])) > soglia_client: oggetti_rilevati.append("BICI")
if float(np.max(grid[:, :, 2])) > soglia_client: oggetti_rilevati.append("STOP")

print(f"[SERVER] {device_id} -> Vede: {oggetti_rilevati if oggetti_rilevati else '[]'}", flush=True)
logger.info(f"{device_id} -> Vede: {oggetti_rilevati if oggetti_rilevati else '[]'}")

# --- 6. RISPOSTA FINALE ---
output = np.nan_to_num(input_data, nan=0.0, posinf=0.0, neginf=0.0) if np.issubdtype(input_data.dtype, np.floating) else input_data
Expand Down
18 changes: 10 additions & 8 deletions src/server/communication/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ def __init__(self):
started_at=server_started_at.isoformat(),
)

# Print header once
# Log header once
if not RequestHandler.header_printed:
print(
"\nDevice | Offload | Acq Time (ms) | Device Comp (ms) | Edge Comp (ms) | Net Time (ms) | Total (ms)"
logger.info(
"\nDevice | Offload | Acq Time (ms) | Device Comp (ms) | Edge Comp (ms) | Net Time (ms) | Total (ms)\n"
+ "-" * 100
)
print("-" * 100)
RequestHandler.header_printed = True

# Empty the debug folder every time the server starts
Expand Down Expand Up @@ -665,7 +665,9 @@ def handle_device_inference_result(self, body, received_timestamp):
decision_candidates = offloading_algo.candidate_evaluations

# Stampiamo la tabella SOLO se il calcolo è andato a buon fine!
print(f"{device_id:13s} | {message_data.offloading_layer_index:7d} | {acq_time:13.2f} | {device_comp_time:16.2f} | {edge_comp_time:14.2f} | {network_time:13.2f} | {total_time:10.2f}")
logger.info(
f"{device_id:13s} | {message_data.offloading_layer_index:7d} | {acq_time:13.2f} | {device_comp_time:16.2f} | {edge_comp_time:14.2f} | {network_time:13.2f} | {total_time:10.2f}"
)

except IndexError:
# Se mancano i file restituiamo il layer massimo usando la variabile corretta.
Expand Down Expand Up @@ -799,7 +801,7 @@ def handle_device_inference_result(self, body, received_timestamp):
self.profiler.stop_cprofile("server_deep_analysis")
# Lo riavviamo per catturare i prossimi 50
self.profiler.start_cprofile()
print(f"📊 [PROFILER SERVER] Dati macro e micro (cProfile) esportati.")
logger.info("📊 [PROFILER SERVER] Dati macro e micro (cProfile) esportati.")

return best_offloading_layer, device_id, prediction

Expand Down Expand Up @@ -897,8 +899,8 @@ def build_model_registry(cls, models_config: dict):
"last_offloading_layer": model_config["last_offloading_layer"],
"num_layers": model_config["last_offloading_layer"] + 1,
}
print(
logger.info(
f"Registered model '{model_name}' (dir: {model_dir}) with hash {model_hash}"
)
except Exception as e:
print(f"Warning: could not register model {model_name}: {e}")
logger.warning(f"Could not register model {model_name}: {e}")
24 changes: 24 additions & 0 deletions tests/unit/test_no_print_statements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import re
from pathlib import Path

SRC_ROOT = Path(__file__).resolve().parents[2] / "src"

# request_handler.py and http_server.py (the endpoint handlers) must use the
# structured logger instead of print(), which bypasses log levels/handlers.
FILES_REQUIRING_STRUCTURED_LOGGING = [
SRC_ROOT / "server" / "communication" / "request_handler.py",
SRC_ROOT / "server" / "communication" / "http_server.py",
]

PRINT_CALL_RE = re.compile(r"(?<![.\w])print\s*\(")


def test_no_print_calls_in_request_and_endpoint_handlers():
offenders = {}
for path in FILES_REQUIRING_STRUCTURED_LOGGING:
source = path.read_text()
matches = PRINT_CALL_RE.findall(source)
if matches:
offenders[str(path)] = len(matches)

assert offenders == {}
Loading