From 3c65d78d77e43de12284417012fad2d8c195770e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 7 Sep 2020 12:24:32 +0200 Subject: [PATCH] Update CPU freq display to use NAN on error --- CPUMeter.c | 2 +- darwin/Platform.c | 3 ++- dragonflybsd/Platform.c | 2 +- freebsd/Platform.c | 2 +- linux/LinuxProcessList.c | 2 +- openbsd/Platform.c | 2 +- solaris/Platform.c | 2 +- unsupported/Platform.c | 4 +++- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CPUMeter.c b/CPUMeter.c index 62c9971b..badca940 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -42,7 +42,7 @@ static void CPUMeter_updateValues(Meter* this, char* buffer, int size) { if (this->pl->settings->showCPUFrequency) { double cpuFrequency = this->values[CPU_METER_FREQUENCY]; char cpuFrequencyBuffer[16]; - if (cpuFrequency < 0) { + if (isnan(cpuFrequency)) { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "N/A"); } else { xSnprintf(cpuFrequencyBuffer, sizeof(cpuFrequencyBuffer), "%.0fMHz", cpuFrequency); diff --git a/darwin/Platform.c b/darwin/Platform.c index 1186fe04..129b1cb9 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -19,6 +19,7 @@ in the source distribution for its full text. #include "zfs/ZfsCompressedArcMeter.h" #include "DarwinProcessList.h" +#include #include @@ -210,7 +211,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; - mtr->values[CPU_METER_FREQUENCY] = -1; + mtr->values[CPU_METER_FREQUENCY] = NAN; return CLAMP(total, 0.0, 100.0); } diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 3b8e1a0d..e4e78e38 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -168,7 +168,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/freebsd/Platform.c b/freebsd/Platform.c index df664ae5..3fc5de31 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -171,7 +171,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 18dda3ed..9f754f19 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1153,7 +1153,7 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { for (int i = 0; i <= cpus; i++) { CPUData* cpuData = &(this->cpus[i]); - cpuData->frequency = -1; + cpuData->frequency = NAN; } int numCPUsWithFrequency = 0; diff --git a/openbsd/Platform.c b/openbsd/Platform.c index cb162078..bd5ef7ef 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -162,7 +162,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_STEAL] = 0.0; v[CPU_METER_GUEST] = 0.0; v[CPU_METER_IOWAIT] = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; Meter_setItems(this, 8); totalPercent = v[0]+v[1]+v[2]+v[3]; } else { diff --git a/solaris/Platform.c b/solaris/Platform.c index 436c9ce9..d3ad1f93 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -186,7 +186,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return percent; } diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 420dfb78..20df3376 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -6,6 +6,8 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#include + #include "Platform.h" #include "CPUMeter.h" #include "MemoryMeter.h" @@ -105,7 +107,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { (void) cpu; double* v = this->values; - v[CPU_METER_FREQUENCY] = -1; + v[CPU_METER_FREQUENCY] = NAN; return 0.0; }