diff options
author | Alexander Momchilov <alexandermomchilov@gmail.com> | 2021-08-20 17:52:07 -0400 |
---|---|---|
committer | Alexander Momchilov <alexandermomchilov@gmail.com> | 2021-08-23 10:37:49 -0400 |
commit | 5b4d63d1be3a6dc1a8fd646e418ccf585ea85bc8 (patch) | |
tree | 2289958a6ba9032faa4704275589c002575d33df /darwin/DarwinProcessList.c | |
parent | ccb756d3c702cd80443fee2215e51c13a69c0fe1 (diff) |
Fix macOS CPU time calculations
Diffstat (limited to 'darwin/DarwinProcessList.c')
-rw-r--r-- | darwin/DarwinProcessList.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 60f8a7ca..3cfdca6f 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -160,9 +160,11 @@ void ProcessList_delete(ProcessList* this) { free(this); } -static double ticksToNanoseconds(const double ticks) { +// Converts "scheduler ticks" to nanoseconds. +// See `sysconf(_SC_CLK_TCK)`, as used to define the `Platform_clockTicksPerSec` constant. +static double schedulerTicksToNanoseconds(const double ticks) { const double nanos_per_sec = 1e9; - return (ticks / Platform_timebaseToNS) * (nanos_per_sec / (double) Platform_clockTicksPerSec); + return ticks * (nanos_per_sec / (double) Platform_clockTicksPerSec); } void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { @@ -192,7 +194,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { } } - const double time_interval = ticksToNanoseconds(dpl->global_diff) / (double) dpl->super.activeCPUs; + const double time_interval_ns = schedulerTicksToNanoseconds(dpl->global_diff) / (double) dpl->super.activeCPUs; /* Clear the thread counts */ super->kernelThreads = 0; @@ -213,7 +215,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); - DarwinProcess_setFromLibprocPidinfo(proc, dpl, time_interval); + DarwinProcess_setFromLibprocPidinfo(proc, dpl, time_interval_ns); if (proc->super.st_uid != ps[i].kp_eproc.e_ucred.cr_uid) { proc->super.st_uid = ps[i].kp_eproc.e_ucred.cr_uid; |