Skip to content

Commit

Permalink
{Memory,Swap}Meter: make sure new constants are used consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
intelfx authored and BenBE committed Apr 23, 2023
1 parent 1b640df commit b2ada27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions MemoryMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ static void MemoryMeter_updateValues(Meter* this) {
Platform_setMemoryValues(this);

/* Do not print available memory in bar mode */
this->curItems = 4;
static_assert(MEMORY_METER_AVAILABLE + 1 == MEMORY_METER_ITEMCOUNT,
"MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues");
this->curItems = MEMORY_METER_AVAILABLE;

written = Meter_humanUnit(buffer, this->values[MEMORY_METER_USED], size);
METER_BUFFER_CHECK(buffer, size, written);
Expand Down Expand Up @@ -87,7 +89,7 @@ const MeterClass MemoryMeter_class = {
},
.updateValues = MemoryMeter_updateValues,
.defaultMode = BAR_METERMODE,
.maxItems = 5,
.maxItems = MEMORY_METER_ITEMCOUNT,
.total = 100.0,
.attributes = MemoryMeter_attributes,
.name = "Memory",
Expand Down
6 changes: 3 additions & 3 deletions SwapMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ static void SwapMeter_updateValues(Meter* this) {
size_t size = sizeof(this->txtBuffer);
int written;

this->values[1] = NAN; /* 'cached' not present on all platforms */
this->values[SWAP_METER_CACHE] = NAN; /* 'cached' not present on all platforms */
Platform_setSwapValues(this);

written = Meter_humanUnit(buffer, this->values[0], size);
written = Meter_humanUnit(buffer, this->values[SWAP_METER_USED], size);
METER_BUFFER_CHECK(buffer, size, written);

METER_BUFFER_APPEND_CHR(buffer, size, '/');
Expand Down Expand Up @@ -64,7 +64,7 @@ const MeterClass SwapMeter_class = {
},
.updateValues = SwapMeter_updateValues,
.defaultMode = BAR_METERMODE,
.maxItems = 2,
.maxItems = SWAP_METER_ITEMCOUNT,
.total = 100.0,
.attributes = SwapMeter_attributes,
.name = "Swap",
Expand Down
4 changes: 2 additions & 2 deletions linux/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,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) {
Expand Down

0 comments on commit b2ada27

Please sign in to comment.