summaryrefslogtreecommitdiffstats
path: root/darwin/DarwinProcessList.c
diff options
context:
space:
mode:
authorAlexander Momchilov <alexandermomchilov@gmail.com>2020-12-08 23:12:44 -0500
committercgzones <cgzones@googlemail.com>2020-12-19 21:30:39 +0100
commit67ccd6b909d28ab84c77acecdfee927337489cc2 (patch)
tree25c9c86935167f733356a387fdc6656a0aaef292 /darwin/DarwinProcessList.c
parentf614b8a19fe92cd13862605c16d69aa23c8b9bd1 (diff)
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.
Diffstat (limited to 'darwin/DarwinProcessList.c')
-rw-r--r--darwin/DarwinProcessList.c10
1 files changed, 9 insertions, 1 deletions
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);

© 2014-2024 Faster IT GmbH | imprint | privacy policy