summaryrefslogtreecommitdiffstats
path: root/MemoryMeter.c
diff options
context:
space:
mode:
authorIvan Shapovalov <intelfx@intelfx.name>2022-12-27 04:57:52 +0400
committerBenBE <BenBE@geshi.org>2023-04-23 16:00:17 +0200
commitb29b33ebb9ae80a95e7d09eb537e0fccc5043d68 (patch)
treebbd2c2642784757885d150ba0c598877f6f3e9d7 /MemoryMeter.c
parentb2ada278403e643a3bc339783740f262b7879803 (diff)
{Memory,Swap}Meter: add "compressed memory" metrics
For now, the semantics are mostly fit for Linux zswap subsystem. For instance, we add the third swap usage metric that indicates the amount of memory that is accounted to swap but in fact stored elsewhere. This exactly matches the definition of frontswap/zswap, and is probably of little use to all other platforms.
Diffstat (limited to 'MemoryMeter.c')
-rw-r--r--MemoryMeter.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/MemoryMeter.c b/MemoryMeter.c
index 1dad1356..28c0be27 100644
--- a/MemoryMeter.c
+++ b/MemoryMeter.c
@@ -20,6 +20,7 @@ static const int MemoryMeter_attributes[] = {
MEMORY_USED,
MEMORY_BUFFERS,
MEMORY_SHARED,
+ MEMORY_COMPRESSED,
MEMORY_CACHE
};
@@ -28,8 +29,9 @@ static void MemoryMeter_updateValues(Meter* this) {
size_t size = sizeof(this->txtBuffer);
int written;
- /* shared and available memory are not supported on all platforms */
+ /* shared, compressed and available memory are not supported on all platforms */
this->values[MEMORY_METER_SHARED] = NAN;
+ this->values[MEMORY_METER_COMPRESSED] = NAN;
this->values[MEMORY_METER_AVAILABLE] = NAN;
Platform_setMemoryValues(this);
@@ -38,7 +40,13 @@ static void MemoryMeter_updateValues(Meter* this) {
"MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues");
this->curItems = MEMORY_METER_AVAILABLE;
- written = Meter_humanUnit(buffer, this->values[MEMORY_METER_USED], size);
+ /* we actually want to show "used + compressed" */
+ double used = this->values[MEMORY_METER_USED];
+ if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
+ used += this->values[MEMORY_METER_COMPRESSED];
+ }
+
+ written = Meter_humanUnit(buffer, used, size);
METER_BUFFER_CHECK(buffer, size, written);
METER_BUFFER_APPEND_CHR(buffer, size, '/');
@@ -69,6 +77,13 @@ static void MemoryMeter_display(const Object* cast, RichString* out) {
RichString_appendAscii(out, CRT_colors[MEMORY_SHARED], buffer);
}
+ /* compressed memory is not supported on all platforms */
+ if (!isnan(this->values[MEMORY_METER_COMPRESSED])) {
+ Meter_humanUnit(buffer, this->values[MEMORY_METER_COMPRESSED], sizeof(buffer));
+ RichString_appendAscii(out, CRT_colors[METER_TEXT], " compressed:");
+ RichString_appendAscii(out, CRT_colors[MEMORY_COMPRESSED], buffer);
+ }
+
Meter_humanUnit(buffer, this->values[MEMORY_METER_CACHE], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " cache:");
RichString_appendAscii(out, CRT_colors[MEMORY_CACHE], buffer);

© 2014-2024 Faster IT GmbH | imprint | privacy policy