Skip to content

Commit

Permalink
ZramMeter: update bar mode
Browse files Browse the repository at this point in the history
Show both compressed and uncompressed bars.

Closes: #1216
  • Loading branch information
cgzones authored and BenBE committed Apr 11, 2023
1 parent ccf745e commit 467bb78
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
18 changes: 12 additions & 6 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion CRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ typedef enum ColorElements_ {
ZFS_OTHER,
ZFS_COMPRESSED,
ZFS_RATIO,
ZRAM,
ZRAM_COMPRESSED,
ZRAM_UNCOMPRESSED,
DYNAMIC_GRAY,
DYNAMIC_DARKGRAY,
DYNAMIC_RED,
Expand Down
5 changes: 3 additions & 2 deletions linux/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions linux/ZramMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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, ')');
Expand All @@ -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);
}
Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions linux/ZramMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 467bb78

Please sign in to comment.