diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-01-08 21:38:57 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-01-08 22:03:37 +0100 |
commit | d97cf58261d340922c85bee9b9e1670b4f88eafc (patch) | |
tree | daa6eb00a7c84e584255de6421e872179f4e305d | |
parent | 650cf0f13bf667270d0a6a4612437af264667585 (diff) |
Improve code readability by creating constants for SWAP memory values
-rw-r--r-- | SwapMeter.c | 6 | ||||
-rw-r--r-- | SwapMeter.h | 5 | ||||
-rw-r--r-- | darwin/Platform.c | 2 | ||||
-rw-r--r-- | dragonflybsd/Platform.c | 4 | ||||
-rw-r--r-- | freebsd/Platform.c | 4 | ||||
-rw-r--r-- | netbsd/Platform.c | 4 | ||||
-rw-r--r-- | openbsd/Platform.c | 4 | ||||
-rw-r--r-- | pcp/Platform.c | 4 | ||||
-rw-r--r-- | solaris/Platform.c | 4 |
9 files changed, 21 insertions, 16 deletions
diff --git a/SwapMeter.c b/SwapMeter.c index 081967fe..c0f48200 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -45,12 +45,12 @@ static void SwapMeter_display(const Object* cast, RichString* out) { RichString_writeAscii(out, CRT_colors[METER_TEXT], ":"); Meter_humanUnit(buffer, this->total, sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[0], sizeof(buffer)); + Meter_humanUnit(buffer, this->values[SWAP_METER_USED], sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:"); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); - if (!isnan(this->values[1])) { - Meter_humanUnit(buffer, this->values[1], sizeof(buffer)); + if (!isnan(this->values[SWAP_METER_CACHE])) { + Meter_humanUnit(buffer, this->values[SWAP_METER_CACHE], sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " cache:"); RichString_appendAscii(out, CRT_colors[SWAP_CACHE], buffer); } diff --git a/SwapMeter.h b/SwapMeter.h index 485485a1..b71e83fe 100644 --- a/SwapMeter.h +++ b/SwapMeter.h @@ -9,6 +9,11 @@ in the source distribution for its full text. #include "Meter.h" +typedef enum { + SWAP_METER_USED = 0, + SWAP_METER_CACHE = 1, + SWAP_METER_ITEMCOUNT = 2, // number of entries in this enum +} SwapMeterValues; extern const MeterClass SwapMeter_class; diff --git a/darwin/Platform.c b/darwin/Platform.c index e9d6caab..38b1a8af 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -278,7 +278,7 @@ void Platform_setSwapValues(Meter* mtr) { sysctl(mib, 2, &swapused, &swlen, NULL, 0); mtr->total = swapused.xsu_total / 1024; - mtr->values[0] = swapused.xsu_used / 1024; + mtr->values[SWAP_METER_USED] = swapused.xsu_used / 1024; } void Platform_setZfsArcValues(Meter* this) { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 944df990..769a46ed 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -218,8 +218,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = NAN; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 3f69d207..e2f2509c 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -250,8 +250,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = NAN; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; } void Platform_setZfsArcValues(Meter* this) { diff --git a/netbsd/Platform.c b/netbsd/Platform.c index e2f8c880..78579189 100644 --- a/netbsd/Platform.c +++ b/netbsd/Platform.c @@ -280,8 +280,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = NAN; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 74247484..24e8aca1 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -237,8 +237,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = NAN; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; } char* Platform_getProcessEnv(pid_t pid) { diff --git a/pcp/Platform.c b/pcp/Platform.c index d1bd0bc4..994cef3c 100644 --- a/pcp/Platform.c +++ b/pcp/Platform.c @@ -548,8 +548,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = pl->cachedSwap; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = pl->cachedSwap; } void Platform_setZramValues(Meter* this) { diff --git a/solaris/Platform.c b/solaris/Platform.c index a99052c3..f3a386bc 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -247,8 +247,8 @@ void Platform_setMemoryValues(Meter* this) { void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; this->total = pl->totalSwap; - this->values[0] = pl->usedSwap; - this->values[1] = NAN; + this->values[SWAP_METER_USED] = pl->usedSwap; + this->values[SWAP_METER_CACHE] = NAN; } void Platform_setZfsArcValues(Meter* this) { |