From 01871359060ecf2f313f0de33da5287d5427c5be Mon Sep 17 00:00:00 2001 From: Rory Fewell Date: Sun, 7 Dec 2025 22:55:16 +0000 Subject: [PATCH] Bugfix: Tally up all CPU totals for more accurate usage % in taskmgr --- windows/taskmgr/src/procmon.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/windows/taskmgr/src/procmon.c b/windows/taskmgr/src/procmon.c index b1f0701..4a3276d 100644 --- a/windows/taskmgr/src/procmon.c +++ b/windows/taskmgr/src/procmon.c @@ -6,6 +6,8 @@ #include "procmon.h" +#define PROC_STAT_CPU_COUNTERS 7 + // // FORWARD DECLARATIONS // @@ -236,22 +238,26 @@ static void process_get_totals( ) ) { - gchar* last_stime_s = wintc_strdup_delimited( - cpu_stats + 5, // skip 'cpu ' - " ", - 0 - ); - gchar* last_utime_s = wintc_strdup_delimited( - cpu_stats + 5, - " ", - 2 - ); + // Total up all the CPU time in various modes + // + gint running_total = 0; - *cpu_time = - strtoul(last_stime_s, NULL, 0) + strtoul(last_utime_s, NULL, 0); + for (gint i = 0; i < PROC_STAT_CPU_COUNTERS; i++) + { + gchar* time_stat_s = + wintc_strdup_delimited( + cpu_stats + 5, // skip 'cpu ' + " ", + i + ); + + running_total += strtoul(time_stat_s, NULL, 0); + + g_free(time_stat_s); + } + + *cpu_time = running_total; - g_free(last_stime_s); - g_free(last_utime_s); g_free(cpu_stats); } }