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

ZramMeter: update bar mode #1217

Merged
merged 3 commits into from
Apr 11, 2023
Merged
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
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
12 changes: 6 additions & 6 deletions MemoryMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 15 additions & 4 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
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