feat(types): Complete strict static analysis and typing track

This commit is contained in:
2026-03-04 09:46:02 -05:00
parent c6c2a1b40c
commit fe2114a2e0
46 changed files with 606 additions and 795 deletions

View File

@@ -2,38 +2,38 @@ from __future__ import annotations
import time
import psutil
import threading
from typing import Any
from typing import Any, Optional, Callable
class PerformanceMonitor:
def __init__(self) -> None:
self._start_time = None
self._last_frame_time = 0.0
self._fps = 0.0
self._last_calculated_fps = 0.0
self._frame_count = 0
self._total_frame_count = 0
self._fps_last_time = time.time()
self._process = psutil.Process()
self._cpu_usage = 0.0
self._cpu_lock = threading.Lock()
self._start_time: Optional[float] = None
self._last_frame_time: float = 0.0
self._fps: float = 0.0
self._last_calculated_fps: float = 0.0
self._frame_count: int = 0
self._total_frame_count: int = 0
self._fps_last_time: float = time.time()
self._process: psutil.Process = psutil.Process()
self._cpu_usage: float = 0.0
self._cpu_lock: threading.Lock = threading.Lock()
# Input lag tracking
self._last_input_time = None
self._input_lag_ms = 0.0
self._last_input_time: Optional[float] = None
self._input_lag_ms: float = 0.0
# Alerts
self.alert_callback = None
self.thresholds = {
self.alert_callback: Optional[Callable[[str], None]] = None
self.thresholds: dict[str, float] = {
'frame_time_ms': 33.3, # < 30 FPS
'cpu_percent': 80.0,
'input_lag_ms': 100.0
}
self._last_alert_time = 0
self._alert_cooldown = 30 # seconds
self._last_alert_time: float = 0.0
self._alert_cooldown: int = 30 # seconds
# Detailed profiling
self._component_timings = {}
self._comp_start = {}
self._component_timings: dict[str, float] = {}
self._comp_start: dict[str, float] = {}
# Start CPU usage monitoring thread
self._stop_event = threading.Event()
self._cpu_thread = threading.Thread(target=self._monitor_cpu, daemon=True)
self._stop_event: threading.Event = threading.Event()
self._cpu_thread: threading.Thread = threading.Thread(target=self._monitor_cpu, daemon=True)
self._cpu_thread.start()
def _monitor_cpu(self) -> None:
@@ -107,15 +107,13 @@ class PerformanceMonitor:
def get_metrics(self) -> dict[str, Any]:
with self._cpu_lock:
cpu_usage = self._cpu_usage
metrics = {
metrics: dict[str, Any] = {
'last_frame_time_ms': self._last_frame_time,
'fps': self._last_calculated_fps,
'cpu_percent': cpu_usage,
'total_frames': self._total_frame_count,
'input_lag_ms': self._last_input_time if self._last_input_time else 0.0 # Wait, this should be the calculated lag
'input_lag_ms': self._input_lag_ms
}
# Oops, fixed the input lag logic in previous turn, let's keep it consistent
metrics['input_lag_ms'] = self._input_lag_ms
# Add detailed timings
for name, elapsed in self._component_timings.items():
metrics[f'time_{name}_ms'] = elapsed