diff options
author | Daniel Lange <DLange@git.local> | 2020-12-13 20:02:38 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-12-13 20:02:38 +0100 |
commit | 4b1a4a4ebd1e547ee8e101d4aaeadbaf79d932e1 (patch) | |
tree | 1aab95fd258d103b04bf955f0d04f9b91c571852 /darwin | |
parent | 3655b6ca0b1b89a2d6415211c1ce484dd6afe39f (diff) | |
parent | f32f0188cd140f965c5e02f7fb875116522c4b41 (diff) |
Merge branch 'fix_mach_timebase' of benbe/htop
Diffstat (limited to 'darwin')
-rw-r--r-- | darwin/DarwinProcess.c | 3 | ||||
-rw-r--r-- | darwin/Platform.c | 46 | ||||
-rw-r--r-- | darwin/Platform.h | 4 |
3 files changed, 38 insertions, 15 deletions
diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 0c20bc61..d8d7ab7b 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -14,6 +14,7 @@ in the source distribution for its full text. #include <mach/mach.h> #include "CRT.h" +#include "Platform.h" #include "Process.h" @@ -308,7 +309,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* uint64_t diff = (pti.pti_total_system - proc->stime) + (pti.pti_total_user - proc->utime); - proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount + proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount * Platform_timebaseToNS / ((double)dpl->global_diff * 100000.0); // fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu, diff --git a/darwin/Platform.c b/darwin/Platform.c index 672c1ad0..235044f9 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -6,30 +6,38 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "Platform.h" -#include "Macros.h" -#include "CPUMeter.h" -#include "MemoryMeter.h" -#include "SwapMeter.h" -#include "TasksMeter.h" -#include "LoadAverageMeter.h" + +#include <math.h> +#include <stdlib.h> + +#include <CoreFoundation/CoreFoundation.h> +#include <CoreFoundation/CFString.h> +#include <IOKit/ps/IOPowerSources.h> +#include <IOKit/ps/IOPSKeys.h> + #include "ClockMeter.h" +#include "CPUMeter.h" +#include "DarwinProcessList.h" #include "DateMeter.h" #include "DateTimeMeter.h" #include "HostnameMeter.h" +#include "LoadAverageMeter.h" +#include "Macros.h" +#include "MemoryMeter.h" #include "ProcessLocksScreen.h" +#include "SwapMeter.h" +#include "TasksMeter.h" #include "UptimeMeter.h" #include "zfs/ZfsArcMeter.h" #include "zfs/ZfsCompressedArcMeter.h" -#include "DarwinProcessList.h" -#include <math.h> -#include <stdlib.h> +#ifdef HAVE_MACH_MACH_TIME_H +#include <mach/mach_time.h> +#endif -#include <CoreFoundation/CoreFoundation.h> -#include <CoreFoundation/CFString.h> -#include <IOKit/ps/IOPowerSources.h> -#include <IOKit/ps/IOPSKeys.h> ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; @@ -104,8 +112,18 @@ const MeterClass* const Platform_meterTypes[] = { int Platform_numberOfFields = LAST_PROCESSFIELD; +double Platform_timebaseToNS = 1.0; + void Platform_init(void) { - /* no platform-specific setup needed */ + // Check if we can determine the timebase used on this system. + // If the API is unavailable assume we get our timebase in nanoseconds. +#ifdef HAVE_MACH_TIMEBASE_INFO + mach_timebase_info_data_t info; + mach_timebase_info(&info); + Platform_timebaseToNS = (double)info.numer / (double)info.denom; +#else + Platform_timebaseToNS = 1.0; +#endif } void Platform_done(void) { diff --git a/darwin/Platform.h b/darwin/Platform.h index 808502b4..74b46190 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -19,10 +19,14 @@ in the source distribution for its full text. #include "ProcessLocksScreen.h" #include "SignalsPanel.h" +extern ProcessFieldData Process_fields[]; + extern ProcessField Platform_defaultFields[]; extern int Platform_numberOfFields; +extern double Platform_timebaseToNS; + extern const SignalItem Platform_signals[]; extern const unsigned int Platform_numberOfSignals; |