Skip to content

Commit

Permalink
darwin: process' percent_cpu should be updated only if the process' r…
Browse files Browse the repository at this point in the history
…unning time has changed

Fixes: #1619
  • Loading branch information
aestriplex authored and BenBE committed Feb 25, 2025
1 parent cbb0369 commit 6a663f3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6a663f3

Please sign in to comment.