feat(perf): Add high-resolution component profiling to main loop
This commit is contained in:
@@ -26,6 +26,10 @@ class PerformanceMonitor:
|
||||
}
|
||||
self._last_alert_time = 0
|
||||
self._alert_cooldown = 30 # seconds
|
||||
|
||||
# Detailed profiling
|
||||
self._component_timings = {}
|
||||
self._comp_start = {}
|
||||
|
||||
# Start CPU usage monitoring thread
|
||||
self._stop_event = threading.Event()
|
||||
@@ -46,6 +50,14 @@ class PerformanceMonitor:
|
||||
def record_input_event(self):
|
||||
self._last_input_time = time.time()
|
||||
|
||||
def start_component(self, name: str):
|
||||
self._comp_start[name] = time.time()
|
||||
|
||||
def end_component(self, name: str):
|
||||
if name in self._comp_start:
|
||||
elapsed = (time.time() - self._comp_start[name]) * 1000.0
|
||||
self._component_timings[name] = elapsed
|
||||
|
||||
def end_frame(self):
|
||||
if self._start_time is None:
|
||||
return
|
||||
@@ -92,12 +104,20 @@ class PerformanceMonitor:
|
||||
with self._cpu_lock:
|
||||
cpu_usage = self._cpu_usage
|
||||
|
||||
return {
|
||||
metrics = {
|
||||
'last_frame_time_ms': self._last_frame_time,
|
||||
'fps': self._fps,
|
||||
'cpu_percent': cpu_usage,
|
||||
'input_lag_ms': self._input_lag_ms
|
||||
'input_lag_ms': self._last_input_time if self._last_input_time else 0.0 # Wait, this should be the calculated lag
|
||||
}
|
||||
# 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
|
||||
|
||||
return metrics
|
||||
|
||||
def stop(self):
|
||||
self._stop_event.set()
|
||||
|
||||
Reference in New Issue
Block a user