Refactor CPU usage reporting to simplify diagnostics and enhance readability

This commit is contained in:
2025-08-18 10:02:02 +02:00
parent ce5918ca85
commit e38bf3a851
+1 -9
View File
@@ -2072,20 +2072,12 @@ class MainWindow(QtWidgets.QMainWindow):
# Program CPU usage (actual per-process percent, smoothed via history)
if memory_info.get('has_psutil', False):
# Ensure history contains the latest sample (already appended earlier)
if self._resource_history['cpu_percent']:
cur_cpu, max_cpu_p, avg_cpu_p = self._get_resource_stats(self._resource_history['cpu_percent'])
else:
cur_cpu = memory_info.get('cpu_percent', 0.0)
max_cpu_p = avg_cpu_p = cur_cpu
# Loop timing (optional extra diagnostic)
loop_extra = ""
if hasattr(self, '_loop_times') and self._loop_times:
loop_current = self._loop_times[-1] * 1000 # seconds -> ms
loop_extra = f" | Loop {loop_current:.0f}ms"
program_cpu_text = f"CPU: {cur_cpu:.1f}%\nAvg: {avg_cpu_p:.1f}% | Max: {max_cpu_p:.1f}%{loop_extra}"
program_cpu_text = f"CPU: {cur_cpu:.1f}%\nAvg: {avg_cpu_p:.1f}% | Max: {max_cpu_p:.1f}%"
program_cpu_color = (
colors['error'] if cur_cpu > 80 else
colors['warning'] if cur_cpu > 60 else