diff --git a/CPUMeter.c b/CPUMeter.c index a946aa7d7..c3304946b 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -73,9 +73,12 @@ static void CPUMeter_updateValues(Meter* this) { double percent = Platform_setCPUValues(this, cpu); if (isnan(percent)) { xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "offline"); + this->single_value = 0; return; } + this->single_value = percent; + char cpuUsageBuffer[8] = { 0 }; char cpuFrequencyBuffer[16] = { 0 }; char cpuTemperatureBuffer[16] = { 0 }; diff --git a/MemoryMeter.c b/MemoryMeter.c index 28c0be277..4228e60dc 100644 --- a/MemoryMeter.c +++ b/MemoryMeter.c @@ -41,12 +41,12 @@ static void MemoryMeter_updateValues(Meter* this) { this->curItems = MEMORY_METER_AVAILABLE; /* we actually want to show "used + compressed" */ - double used = this->values[MEMORY_METER_USED]; + this->single_value = this->values[MEMORY_METER_USED]; if (!isnan(this->values[MEMORY_METER_COMPRESSED])) { - used += this->values[MEMORY_METER_COMPRESSED]; + this->single_value += this->values[MEMORY_METER_COMPRESSED]; } - written = Meter_humanUnit(buffer, used, size); + written = Meter_humanUnit(buffer, this->single_value, size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, '/'); diff --git a/Meter.c b/Meter.c index cf0fe36ac..232505165 100644 --- a/Meter.c +++ b/Meter.c @@ -41,6 +41,7 @@ Meter* Meter_new(const Machine* host, unsigned int param, const MeterClass* type this->curItems = type->maxItems; this->curAttributes = NULL; this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL; + this->single_value = NAN; this->total = type->total; this->caption = xStrdup(type->caption); if (Meter_initFn(this)) { @@ -330,7 +331,9 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { for (int i = 0; i < nValues - 1; i++) data->values[i] = data->values[i + 1]; - if (Meter_comprisedValues(this)) { + if (!isnan(this->single_value)) { + data->values[nValues - 1] = this->single_value; + } else if (Meter_comprisedValues(this)) { data->values[nValues - 1] = (this->curItems > 0) ? this->values[this->curItems - 1] : 0.0; } else { double value = 0.0; diff --git a/Meter.h b/Meter.h index db93e4c04..69934895c 100644 --- a/Meter.h +++ b/Meter.h @@ -117,6 +117,7 @@ struct Meter_ { const int* curAttributes; char txtBuffer[METER_TXTBUFFER_LEN]; double* values; + double single_value; double total; void* meterData; }; diff --git a/SwapMeter.c b/SwapMeter.c index 84e58a26e..ae4a8060e 100644 --- a/SwapMeter.c +++ b/SwapMeter.c @@ -33,7 +33,9 @@ static void SwapMeter_updateValues(Meter* this) { this->values[SWAP_METER_FRONTSWAP] = NAN; /* 'frontswap' not present on all platforms */ Platform_setSwapValues(this); - written = Meter_humanUnit(buffer, this->values[SWAP_METER_USED], size); + this->single_value = this->values[SWAP_METER_USED]; + + written = Meter_humanUnit(buffer, this->single_value, size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, '/');