From c2f58677a311fef4fe5b1466217cf6a0094f5302 Mon Sep 17 00:00:00 2001 From: aestriplex Date: Sun, 23 Feb 2025 21:04:51 +0100 Subject: [PATCH] darwin: process' percent_cpu should be updated only if the process' running time has changed (#1619) --- darwin/DarwinProcess.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 0b4df3f6f..9bdd3f64c 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -370,13 +370,12 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable const DarwinMachine* dhost = (const DarwinMachine*) proc->super.super.host; uint64_t total_existing_time_ns = proc->stime + proc->utime; - uint64_t user_time_ns = pti.pti_total_user; uint64_t system_time_ns = pti.pti_total_system; uint64_t total_current_time_ns = user_time_ns + system_time_ns; - if (total_existing_time_ns && 1E-6 < timeIntervalNS) { - uint64_t total_time_diff_ns = total_current_time_ns - total_existing_time_ns; + if (total_existing_time_ns < total_current_time_ns) { + const uint64_t total_time_diff_ns = total_current_time_ns - total_existing_time_ns; proc->super.percent_cpu = ((double)total_time_diff_ns / timeIntervalNS) * 100.0; } else { proc->super.percent_cpu = 0.0;