Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "single value" model for monochrome graph #928

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->summaryValue = 0;
return;
}

this->summaryValue = percent;

char cpuUsageBuffer[8] = { 0 };
char cpuFrequencyBuffer[16] = { 0 };
char cpuTemperatureBuffer[16] = { 0 };
Expand Down
6 changes: 3 additions & 3 deletions MemoryMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->summaryValue = this->values[MEMORY_METER_USED];
if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
used += this->values[MEMORY_METER_COMPRESSED];
this->summaryValue += this->values[MEMORY_METER_COMPRESSED];
}

written = Meter_humanUnit(buffer, used, size);
written = Meter_humanUnit(buffer, this->summaryValue, size);
METER_BUFFER_CHECK(buffer, size, written);

METER_BUFFER_APPEND_CHR(buffer, size, '/');
Expand Down
5 changes: 4 additions & 1 deletion Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->summaryValue = NAN;
this->total = type->total;
this->caption = xStrdup(type->caption);
if (Meter_initFn(this)) {
Expand Down Expand Up @@ -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->summaryValue)) {
data->values[nValues - 1] = this->summaryValue;
} else if (Meter_comprisedValues(this)) {
data->values[nValues - 1] = (this->curItems > 0) ? this->values[this->curItems - 1] : 0.0;
} else {
double value = 0.0;
Expand Down
1 change: 1 addition & 0 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ struct Meter_ {
const int* curAttributes;
char txtBuffer[METER_TXTBUFFER_LEN];
double* values;
double summaryValue;
double total;
void* meterData;
};
Expand Down
4 changes: 3 additions & 1 deletion SwapMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->summaryValue = this->values[SWAP_METER_USED];

written = Meter_humanUnit(buffer, this->summaryValue, size);
METER_BUFFER_CHECK(buffer, size, written);

METER_BUFFER_APPEND_CHR(buffer, size, '/');
Expand Down