From c803ec6dae5556fa35d6bd8124aa536633887f77 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 3 Mar 2023 23:47:43 +0100 Subject: Improve code readability by using enum values instead of raw numbers --- dragonflybsd/Platform.c | 6 +++--- freebsd/Platform.c | 6 +++--- linux/Platform.c | 10 +++++----- netbsd/Platform.c | 8 ++++---- openbsd/Platform.c | 8 ++++---- pcp/Platform.c | 15 ++++++++------- solaris/Platform.c | 6 +++--- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 277f1876..ab21d365 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -192,11 +192,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0] + v[1] + v[2] + v[3]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } else { - v[2] = cpuData->systemAllPercent; + v[CPU_METER_KERNEL] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0] + v[1] + v[2]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL]; } percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 061de70b..618ed6b4 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -213,11 +213,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0] + v[1] + v[2] + v[3]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } else { - v[2] = cpuData->systemAllPercent; + v[CPU_METER_NORMAL] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0] + v[1] + v[2]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL]; } percent = CLAMP(percent, 0.0, 100.0); diff --git a/linux/Platform.c b/linux/Platform.c index 005d8316..93be689d 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -325,15 +325,15 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; this->curItems = 8; if (this->pl->settings->accountGuestInCPUMeter) { - percent = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ] + v[CPU_METER_SOFTIRQ] + v[CPU_METER_STEAL] + v[CPU_METER_GUEST]; } else { - percent = v[0] + v[1] + v[2] + v[3] + v[4]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ] + v[CPU_METER_SOFTIRQ]; } } else { - v[2] = cpuData->systemAllPeriod / total * 100.0; - v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; + v[CPU_METER_KERNEL] = cpuData->systemAllPeriod / total * 100.0; + v[CPU_METER_IRQ] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; this->curItems = 4; - percent = v[0] + v[1] + v[2] + v[3]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) { diff --git a/netbsd/Platform.c b/netbsd/Platform.c index c5c42d0a..9b07d8f0 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -254,11 +254,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; this->curItems = 8; - totalPercent = v[0] + v[1] + v[2] + v[3]; + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } else { - v[2] = cpuData->sysAllPeriod / total * 100.0; - v[3] = 0.0; // No steal nor guest on NetBSD - totalPercent = v[0] + v[1] + v[2]; + v[CPU_METER_KERNEL] = cpuData->sysAllPeriod / total * 100.0; + v[CPU_METER_IRQ] = 0.0; // No steal nor guest on NetBSD + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL]; this->curItems = 4; } diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 71419f8e..615397e2 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -205,11 +205,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; this->curItems = 8; - totalPercent = v[0] + v[1] + v[2] + v[3]; + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } else { - v[2] = cpuData->sysAllPeriod / total * 100.0; - v[3] = 0.0; // No steal nor guest on OpenBSD - totalPercent = v[0] + v[1] + v[2]; + v[CPU_METER_KERNEL] = cpuData->sysAllPeriod / total * 100.0; + v[CPU_METER_IRQ] = 0.0; // No steal nor guest on OpenBSD + totalPercent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL]; this->curItems = 4; } diff --git a/pcp/Platform.c b/pcp/Platform.c index a76c0288..7319fcb0 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -501,16 +501,17 @@ static double Platform_setOneCPUValues(Meter* this, pmAtomValue* values) { v[CPU_METER_GUEST] = values[CPU_GUEST_PERIOD].ull / total * 100.0; v[CPU_METER_IOWAIT] = values[CPU_IOWAIT_PERIOD].ull / total * 100.0; this->curItems = 8; - if (this->pl->settings->accountGuestInCPUMeter) - percent = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6]; - else - percent = v[0] + v[1] + v[2] + v[3] + v[4]; + if (this->pl->settings->accountGuestInCPUMeter) { + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ] + v[CPU_METER_SOFTIRQ] + v[CPU_METER_STEAL] + v[CPU_METER_GUEST]; + } else { + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ] + v[CPU_METER_SOFTIRQ]; + } } else { - v[2] = values[CPU_SYSTEM_ALL_PERIOD].ull / total * 100.0; + v[CPU_METER_KERNEL] = values[CPU_SYSTEM_ALL_PERIOD].ull / total * 100.0; value = values[CPU_STEAL_PERIOD].ull + values[CPU_GUEST_PERIOD].ull; - v[3] = value / total * 100.0; + v[CPU_METER_IRQ] = value / total * 100.0; this->curItems = 4; - percent = v[0] + v[1] + v[2] + v[3]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) diff --git a/solaris/Platform.c b/solaris/Platform.c index 4cadf1a0..f7ab6558 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -219,11 +219,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0] + v[1] + v[2] + v[3]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL] + v[CPU_METER_IRQ]; } else { - v[2] = cpuData->systemAllPercent; + v[CPU_METER_KERNEL] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0] + v[1] + v[2]; + percent = v[CPU_METER_NICE] + v[CPU_METER_NORMAL] + v[CPU_METER_KERNEL]; } percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); -- cgit v1.2.3