From b1df27ac640cf45ce38e8cfd12220dc263c09a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 9 Apr 2023 14:15:14 +0200 Subject: [PATCH 1/3] MemoryMeter: fix indentation depth --- MemoryMeter.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MemoryMeter.h b/MemoryMeter.h index cc2a160c5..d8f5fdbc9 100644 --- a/MemoryMeter.h +++ b/MemoryMeter.h @@ -10,12 +10,12 @@ in the source distribution for its full text. #include "Meter.h" typedef enum { - MEMORY_METER_USED = 0, - MEMORY_METER_BUFFERS = 1, - MEMORY_METER_SHARED = 2, - MEMORY_METER_CACHE = 3, - MEMORY_METER_AVAILABLE = 4, - MEMORY_METER_ITEMCOUNT = 5, // number of entries in this enum + MEMORY_METER_USED = 0, + MEMORY_METER_BUFFERS = 1, + MEMORY_METER_SHARED = 2, + MEMORY_METER_CACHE = 3, + MEMORY_METER_AVAILABLE = 4, + MEMORY_METER_ITEMCOUNT = 5, // number of entries in this enum } MemoryMeterValues; extern const MeterClass MemoryMeter_class; From 5c0a48889cc573a44230df647b3e9731614ec5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 9 Apr 2023 14:18:26 +0200 Subject: [PATCH 2/3] Meter: introduce comprisedValues option Useful for bar mode if latter values of the meter comprise previous ones. --- Meter.c | 19 +++++++++++++++---- Meter.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Meter.c b/Meter.c index 7f634f19a..a88de04a3 100644 --- a/Meter.c +++ b/Meter.c @@ -219,6 +219,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { assert(startPos + w <= RichString_sizeVal(bar)); int blockSizes[10]; + int blockSizeSum = 0; // First draw in the bar[] buffer... int offset = 0; @@ -230,6 +231,12 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { } else { blockSizes[i] = 0; } + + if (Meter_comprisedValues(this)) { + blockSizes[i] = MAXIMUM(blockSizes[i] - blockSizeSum, 0); + blockSizeSum += blockSizes[i]; + } + int nextOffset = offset + blockSizes[i]; // (Control against invalid values) nextOffset = CLAMP(nextOffset, 0, w); @@ -323,10 +330,14 @@ 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]; - double value = 0.0; - for (uint8_t i = 0; i < this->curItems; i++) - value += !isnan(this->values[i]) ? this->values[i] : 0; - data->values[nValues - 1] = value; + if (Meter_comprisedValues(this)) { + data->values[nValues - 1] = (this->curItems > 0) ? this->values[this->curItems - 1] : 0.0; + } else { + double value = 0.0; + for (uint8_t i = 0; i < this->curItems; i++) + value += !isnan(this->values[i]) ? this->values[i] : 0; + data->values[nValues - 1] = value; + } } int i = nValues - (w * 2), k = 0; diff --git a/Meter.h b/Meter.h index bd7604a01..8e8618d66 100644 --- a/Meter.h +++ b/Meter.h @@ -74,6 +74,7 @@ typedef struct MeterClass_ { const char* const description; /* optional meter description in header setup menu */ const uint8_t maxItems; const bool isMultiColumn; /* whether the meter draws multiple sub-columns (defaults to false) */ + const bool comprisedValues; /* whether latter values comprise previous ones (defaults to false) */ } MeterClass; #define As_Meter(this_) ((const MeterClass*)((this_)->super.klass)) @@ -94,6 +95,7 @@ typedef struct MeterClass_ { #define Meter_name(this_) As_Meter(this_)->name #define Meter_uiName(this_) As_Meter(this_)->uiName #define Meter_isMultiColumn(this_) As_Meter(this_)->isMultiColumn +#define Meter_comprisedValues(this_) As_Meter(this_)->comprisedValues typedef struct GraphData_ { struct timeval time; From c0055e6083d88de0b78904bd7c29f5c6a2f50d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Mon, 3 Apr 2023 20:30:20 +0200 Subject: [PATCH 3/3] ZramMeter: update bar mode Show both compressed and uncompressed bars. Closes: #1216 --- CRT.c | 18 ++++++++++++------ CRT.h | 3 ++- linux/Platform.c | 5 +++-- linux/ZramMeter.c | 20 ++++++++++---------- linux/ZramMeter.h | 5 +++++ 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/CRT.c b/CRT.c index 2bc9d13f3..85a381159 100644 --- a/CRT.c +++ b/CRT.c @@ -213,7 +213,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta, Black), [ZFS_COMPRESSED] = A_BOLD | ColorPair(Blue, Black), [ZFS_RATIO] = ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), + [ZRAM_COMPRESSED] = ColorPair(Blue, Black), + [ZRAM_UNCOMPRESSED] = ColorPair(Yellow, Black), [DYNAMIC_GRAY] = ColorPairGrayBlack, [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, [DYNAMIC_RED] = ColorPair(Red, Black), @@ -323,7 +324,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_DIM, [ZFS_COMPRESSED] = A_BOLD, [ZFS_RATIO] = A_BOLD, - [ZRAM] = A_NORMAL, + [ZRAM_COMPRESSED] = A_NORMAL, + [ZRAM_UNCOMPRESSED] = A_NORMAL, [DYNAMIC_GRAY] = A_DIM, [DYNAMIC_DARKGRAY] = A_DIM, [DYNAMIC_RED] = A_BOLD, @@ -433,7 +435,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta, White), [ZFS_COMPRESSED] = ColorPair(Cyan, White), [ZFS_RATIO] = ColorPair(Magenta, White), - [ZRAM] = ColorPair(Yellow, White), + [ZRAM_COMPRESSED] = ColorPair(Cyan, White), + [ZRAM_UNCOMPRESSED] = ColorPair(Yellow, White), [DYNAMIC_GRAY] = ColorPair(Black, White), [DYNAMIC_DARKGRAY] = A_BOLD | ColorPair(Black, White), [DYNAMIC_RED] = ColorPair(Red, White), @@ -543,7 +546,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Black), [ZFS_COMPRESSED] = ColorPair(Cyan, Black), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), + [ZRAM_COMPRESSED] = ColorPair(Cyan, Black), + [ZRAM_UNCOMPRESSED] = ColorPair(Yellow, Black), [DYNAMIC_GRAY] = ColorPairGrayBlack, [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, [DYNAMIC_RED] = ColorPair(Red, Black), @@ -653,7 +657,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Blue), [ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue), [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue), - [ZRAM] = A_BOLD | ColorPair(Yellow, Blue), + [ZRAM_COMPRESSED] = ColorPair(Cyan, Blue), + [ZRAM_UNCOMPRESSED] = ColorPair(Yellow, Blue), [DYNAMIC_GRAY] = ColorPairGrayBlack, [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, [DYNAMIC_RED] = ColorPair(Red, Blue), @@ -761,7 +766,8 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZFS_OTHER] = ColorPair(Magenta, Black), [ZFS_COMPRESSED] = ColorPair(Blue, Black), [ZFS_RATIO] = ColorPair(Magenta, Black), - [ZRAM] = ColorPair(Yellow, Black), + [ZRAM_COMPRESSED] = ColorPair(Blue, Black), + [ZRAM_UNCOMPRESSED] = ColorPair(Yellow, Black), [DYNAMIC_GRAY] = ColorPairGrayBlack, [DYNAMIC_DARKGRAY] = A_BOLD | ColorPairGrayBlack, [DYNAMIC_RED] = ColorPair(Red, Black), diff --git a/CRT.h b/CRT.h index 80de73136..278c1e815 100644 --- a/CRT.h +++ b/CRT.h @@ -138,7 +138,8 @@ typedef enum ColorElements_ { ZFS_OTHER, ZFS_COMPRESSED, ZFS_RATIO, - ZRAM, + ZRAM_COMPRESSED, + ZRAM_UNCOMPRESSED, DYNAMIC_GRAY, DYNAMIC_DARKGRAY, DYNAMIC_RED, diff --git a/linux/Platform.c b/linux/Platform.c index 92da08581..88de1d9e3 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -5,6 +5,7 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include "ZramMeter.h" #include "config.h" #include "linux/Platform.h" @@ -382,8 +383,8 @@ void Platform_setSwapValues(Meter* this) { void Platform_setZramValues(Meter* this) { const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; this->total = lpl->zram.totalZram; - this->values[0] = lpl->zram.usedZramComp; - this->values[1] = lpl->zram.usedZramOrig; + this->values[ZRAM_METER_COMPRESSED] = lpl->zram.usedZramComp; + this->values[ZRAM_METER_UNCOMPRESSED] = lpl->zram.usedZramOrig; } void Platform_setZfsArcValues(Meter* this) { diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c index e1e27b710..6e80eb1a7 100644 --- a/linux/ZramMeter.c +++ b/linux/ZramMeter.c @@ -7,10 +7,12 @@ #include "Object.h" #include "Platform.h" #include "RichString.h" +#include "ZramMeter.h" -static const int ZramMeter_attributes[] = { - ZRAM +static const int ZramMeter_attributes[ZRAM_METER_ITEMCOUNT] = { + [ZRAM_METER_COMPRESSED] = ZRAM_COMPRESSED, + [ZRAM_METER_UNCOMPRESSED] = ZRAM_UNCOMPRESSED, }; static void ZramMeter_updateValues(Meter* this) { @@ -20,15 +22,12 @@ static void ZramMeter_updateValues(Meter* this) { Platform_setZramValues(this); - /* on print bar for compressed data size, not uncompressed */ - this->curItems = 1; - - written = Meter_humanUnit(buffer, this->values[0], size); + written = Meter_humanUnit(buffer, this->values[ZRAM_METER_COMPRESSED], size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, '('); - written = Meter_humanUnit(buffer, this->values[1], size); + written = Meter_humanUnit(buffer, this->values[ZRAM_METER_UNCOMPRESSED], size); METER_BUFFER_CHECK(buffer, size, written); METER_BUFFER_APPEND_CHR(buffer, size, ')'); @@ -47,11 +46,11 @@ static void ZramMeter_display(const Object* cast, RichString* out) { 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[ZRAM_METER_COMPRESSED], sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:"); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); - Meter_humanUnit(buffer, this->values[1], sizeof(buffer)); + Meter_humanUnit(buffer, this->values[ZRAM_METER_UNCOMPRESSED], sizeof(buffer)); RichString_appendAscii(out, CRT_colors[METER_TEXT], " uncompressed:"); RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer); } @@ -64,7 +63,8 @@ const MeterClass ZramMeter_class = { }, .updateValues = ZramMeter_updateValues, .defaultMode = BAR_METERMODE, - .maxItems = 2, + .maxItems = ZRAM_METER_ITEMCOUNT, + .comprisedValues = true, .total = 100.0, .attributes = ZramMeter_attributes, .name = "Zram", diff --git a/linux/ZramMeter.h b/linux/ZramMeter.h index ddba1bae7..db27d0b35 100644 --- a/linux/ZramMeter.h +++ b/linux/ZramMeter.h @@ -3,6 +3,11 @@ #include "Meter.h" +typedef enum { + ZRAM_METER_COMPRESSED = 0, + ZRAM_METER_UNCOMPRESSED = 1, + ZRAM_METER_ITEMCOUNT = 2, // number of entries in this enum +} ZramMeterValues; extern const MeterClass ZramMeter_class;