From 67ccd6b909d28ab84c77acecdfee927337489cc2 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Tue, 8 Dec 2020 23:12:44 -0500 Subject: Unhardcode tick-to-ms conversion Division by 100000.0 worked because `sysconf(_SC_CLK_TCK)` happened to be 100. By unhardcoding: 1) It becomes more clear what this 100000.0 figure comes from. 2) It protects against bugs in the case `sysconf(_SC_CLK_TCK)` ever changes. --- darwin/DarwinProcessList.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'darwin/DarwinProcessList.c') diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index dec98270..e5ca5ad8 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -21,6 +21,7 @@ in the source distribution for its full text. #include "CRT.h" #include "DarwinProcess.h" +#include "Platform.h" #include "ProcessList.h" #include "zfs/openzfs_sysctl.h" #include "zfs/ZfsArcStats.h" @@ -158,6 +159,11 @@ void ProcessList_delete(ProcessList* this) { free(this); } +static double ticksToNanoseconds(const double ticks) { + const double nanos_per_sec = 1e9; + return ticks / (double) Platform_clockTicksPerSec * Platform_timebaseToNS * nanos_per_sec; +} + void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { DarwinProcessList* dpl = (DarwinProcessList*)super; bool preExisting = true; @@ -185,6 +191,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { } } + const double time_interval = ticksToNanoseconds(dpl->global_diff) / (double) dpl->super.cpuCount; + /* Clear the thread counts */ super->kernelThreads = 0; super->userlandThreads = 0; @@ -204,7 +212,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); + DarwinProcess_setFromLibprocPidinfo(proc, dpl, time_interval); // Disabled for High Sierra due to bug in macOS High Sierra bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); -- cgit v1.2.3