feat: Enhance inference management with device tracking and telemetry updates

This commit is contained in:
2026-05-13 22:39:08 +02:00
parent 83346dc985
commit 6c401b62bb
7 changed files with 630 additions and 27 deletions

View File

@@ -26,6 +26,9 @@ class TelemetrySnapshot:
cpu_percent_core: float # process CPU per single core — can exceed 100%
memory_mb: float | None # process private working set in MB
timestamp: float # time.perf_counter() when snapshot was taken
# Inference fields — None when inference is disabled / model not loaded
inference_device: str | None = None # e.g. "cpu", "mps"
inference_time_ms: float | None = None # rolling average of model() call time
class TelemetryCollector(QObject):
@@ -69,6 +72,10 @@ class TelemetryCollector(QObject):
self._process.cpu_percent() # first call always returns 0.0; discard
self._cpu_count: int = max(psutil.cpu_count(logical=True) or 1, 1)
# Inference stats (updated externally via set_inference_stats)
self._inference_device: str | None = None
self._inference_time_ms: float | None = None
# periodic snapshot timer
self._timer = QTimer(self)
self._timer.setInterval(update_interval_ms)
@@ -85,6 +92,16 @@ class TelemetryCollector(QObject):
"""Record the FPS that was requested from the camera."""
self._target_fps = fps
def set_inference_stats(self, device: str, avg_ms: float) -> None:
"""Update inference device and average inference time (called from MainWindow)."""
self._inference_device: str | None = device
self._inference_time_ms: float | None = avg_ms
def clear_inference_stats(self) -> None:
"""Clear inference stats when inference is disabled."""
self._inference_device = None
self._inference_time_ms = None
# ------------------------------------------------------------------
# Frame subscriber callback
# ------------------------------------------------------------------
@@ -175,6 +192,12 @@ class TelemetryCollector(QObject):
cpu_percent_core=round(cpu_core, 1),
memory_mb=round(mem_mb, 1) if mem_mb is not None else None,
timestamp=now,
inference_device=self._inference_device,
inference_time_ms=(
round(self._inference_time_ms, 1)
if self._inference_time_ms is not None
else None
),
)
def _make_empty_snapshot(self) -> TelemetrySnapshot:
@@ -187,4 +210,6 @@ class TelemetryCollector(QObject):
cpu_percent_core=0.0,
memory_mb=None,
timestamp=time.perf_counter(),
inference_device=None,
inference_time_ms=None,
)