diff options
author | Explorer09 <explorer09@gmail.com> | 2023-08-26 16:56:06 +0800 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2023-08-29 21:47:56 +0200 |
commit | 25cb42f0e4be70f02dc094d81e033ba21ec18b27 (patch) | |
tree | 98bfff2502ecee0a09800f034cb960ad862db0b2 /linux | |
parent | 8ecdb75d74c393895c68be7a311db959b1f373e9 (diff) |
Rework ZramMeter and remove MeterClass.comprisedValues
The 'comprisedValues' boolean property unnecessarily complicates the
drawing algorithms of Bar meters and Graph meters. Since the only user
of 'comprisedValues' is ZramMeter, it is better to rework the meter so
that it no longer needs 'comprisedValues'.
The 'values[ZRAM_METER_UNCOMPRESSED]' now stores the difference between
uncompressed and compressed data size.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LinuxMachine.c | 3 | ||||
-rw-r--r-- | linux/Platform.c | 2 | ||||
-rw-r--r-- | linux/ZramMeter.c | 7 |
3 files changed, 8 insertions, 4 deletions
diff --git a/linux/LinuxMachine.c b/linux/LinuxMachine.c index 21fd4bd1..5d2e67e9 100644 --- a/linux/LinuxMachine.c +++ b/linux/LinuxMachine.c @@ -337,6 +337,9 @@ static void LinuxMachine_scanZramInfo(LinuxMachine* this) { this->zram.totalZram = totalZram / 1024; this->zram.usedZramComp = usedZramComp / 1024; this->zram.usedZramOrig = usedZramOrig / 1024; + if (this->zram.usedZramComp > this->zram.usedZramOrig) { + this->zram.usedZramComp = this->zram.usedZramOrig; + } } static void LinuxMachine_scanZfsArcstats(LinuxMachine* this) { diff --git a/linux/Platform.c b/linux/Platform.c index c81b3697..1a2ef617 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -418,7 +418,7 @@ void Platform_setZramValues(Meter* this) { this->total = lhost->zram.totalZram; this->values[ZRAM_METER_COMPRESSED] = lhost->zram.usedZramComp; - this->values[ZRAM_METER_UNCOMPRESSED] = lhost->zram.usedZramOrig; + this->values[ZRAM_METER_UNCOMPRESSED] = lhost->zram.usedZramOrig - lhost->zram.usedZramComp; } void Platform_setZfsArcValues(Meter* this) { diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c index 6e80eb1a..a1a98b34 100644 --- a/linux/ZramMeter.c +++ b/linux/ZramMeter.c @@ -27,7 +27,8 @@ static void ZramMeter_updateValues(Meter* this) { METER_BUFFER_APPEND_CHR(buffer, size, '('); - written = Meter_humanUnit(buffer, this->values[ZRAM_METER_UNCOMPRESSED], size); + double uncompressed = this->values[ZRAM_METER_COMPRESSED] + this->values[ZRAM_METER_UNCOMPRESSED]; + written = Meter_humanUnit(buffer, uncompressed, size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, ')'); @@ -50,7 +51,8 @@ static void ZramMeter_display(const Object* cast, RichString* out) { RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:"); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[ZRAM_METER_UNCOMPRESSED], sizeof(buffer)); + double uncompressed = this->values[ZRAM_METER_COMPRESSED] + this->values[ZRAM_METER_UNCOMPRESSED]; + Meter_humanUnit(buffer, uncompressed, sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " uncompressed:"); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); } @@ -64,7 +66,6 @@ const MeterClass ZramMeter_class = { .updateValues = ZramMeter_updateValues, .defaultMode = BAR_METERMODE, .maxItems = ZRAM_METER_ITEMCOUNT, - .comprisedValues = true, .total = 100.0, .attributes = ZramMeter_attributes, .name = "Zram", |