Improve CPU usage reporting with actual per-process percent and enhanced diagnostics
This commit is contained in:
@@ -2070,14 +2070,29 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
# === PROGRAM USAGE SECTION ===
|
||||
|
||||
# Program CPU usage (estimated based on process activity)
|
||||
if memory_info.get('has_psutil', False) and hasattr(self, '_loop_times') and self._loop_times:
|
||||
current_loop, max_loop, avg_loop = self._get_resource_stats(self._resource_history['loop_times'])
|
||||
estimated_cpu = min(100, (current_loop / 50) * 10) # Scale loop time to CPU estimate
|
||||
program_cpu_text = f"CPU: ~{estimated_cpu:.1f}%\nLoop: {current_loop:.0f}ms"
|
||||
program_cpu_color = colors['error'] if estimated_cpu > 20 else colors['warning'] if estimated_cpu > 10 else colors['success']
|
||||
# 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_color = (
|
||||
colors['error'] if cur_cpu > 80 else
|
||||
colors['warning'] if cur_cpu > 60 else
|
||||
colors['success']
|
||||
)
|
||||
else:
|
||||
program_cpu_text = "CPU: --\nNot running"
|
||||
program_cpu_text = "CPU: N/A\npsutil needed"
|
||||
program_cpu_color = colors['text_light']
|
||||
|
||||
self.program_cpu_label.setText(program_cpu_text)
|
||||
|
||||
Reference in New Issue
Block a user