summaryrefslogtreecommitdiffstats
path: root/linux/HugePageMeter.c
diff options
context:
space:
mode:
authorDavid Zarzycki <dave@znu.io>2021-01-14 09:46:37 -0500
committercgzones <cgzones@googlemail.com>2021-01-19 18:06:48 +0100
commit03824da684731557ecf2e809ade6310277744a7e (patch)
tree6c786b93893835b8f1a0bb886cd301011b6cbc38 /linux/HugePageMeter.c
parent4d85848988d8d4e7b2dc64e6600b099171e5b803 (diff)
Linux: individual huge page values in the huge page meter
Diffstat (limited to 'linux/HugePageMeter.c')
-rw-r--r--linux/HugePageMeter.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/linux/HugePageMeter.c b/linux/HugePageMeter.c
index e546c79a..7222c87a 100644
--- a/linux/HugePageMeter.c
+++ b/linux/HugePageMeter.c
@@ -9,23 +9,56 @@ in the source distribution for its full text.
#include "LinuxProcessList.h"
+#include <limits.h>
+#include <math.h>
+
#include "CRT.h"
#include "Object.h"
#include "RichString.h"
+static const char *HugePageMeter_active_labels[4] = { NULL, NULL, NULL, NULL };
static const int HugePageMeter_attributes[] = {
- MEMORY_USED,
+ HUGEPAGE_1,
+ HUGEPAGE_2,
+ HUGEPAGE_3,
+ HUGEPAGE_4,
+};
+
+static const char* const HugePageMeter_labels[] = {
+ " 64K:", " 128K:", " 256K:", " 512K:",
+ " 1M:", " 2M:", " 4M:", " 8M:", " 16M:", " 32M:", " 64M:", " 128M:", " 256M:", " 512M:",
+ " 1G:", " 2G:", " 4G:", " 8G:", " 16G:", " 32G:", " 64G:", " 128G:", " 256G:", " 512G:",
};
static void HugePageMeter_updateValues(Meter* this, char* buffer, size_t size) {
+ assert(ARRAYSIZE(HugePageMeter_labels) == HTOP_HUGEPAGE_COUNT);
+
int written;
+ unsigned long long int usedTotal = 0;
+ unsigned nextUsed = 0;
const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl;
this->total = lpl->totalHugePageMem;
- this->values[0] = lpl->totalHugePageMem - lpl->freeHugePageMem;
+ this->values[0] = 0;
+ HugePageMeter_active_labels[0] = " used:";
+ for (unsigned i = 1; i < ARRAYSIZE(HugePageMeter_active_labels); i++) {
+ this->values[i] = NAN;
+ HugePageMeter_active_labels[i] = NULL;
+ }
+ for (unsigned i = 0; i < HTOP_HUGEPAGE_COUNT; i++) {
+ unsigned long long int value = lpl->usedHugePageMem[i];
+ if (value != ULLONG_MAX) {
+ this->values[nextUsed] = value;
+ usedTotal += value;
+ HugePageMeter_active_labels[nextUsed] = HugePageMeter_labels[i];
+ if (++nextUsed == ARRAYSIZE(HugePageMeter_active_labels)) {
+ break;
+ }
+ }
+ }
- written = Meter_humanUnit(buffer, this->values[0], size);
+ written = Meter_humanUnit(buffer, usedTotal, size);
METER_BUFFER_CHECK(buffer, size, written);
METER_BUFFER_APPEND_CHR(buffer, size, '/');
@@ -41,9 +74,14 @@ static void HugePageMeter_display(const Object* cast, RichString* out) {
Meter_humanUnit(buffer, this->total, sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
- RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:");
- Meter_humanUnit(buffer, this->values[0], sizeof(buffer));
- RichString_appendAscii(out, CRT_colors[MEMORY_USED], buffer);
+ for (unsigned i = 0; i < ARRAYSIZE(HugePageMeter_active_labels); i++) {
+ if (isnan(this->values[i])) {
+ break;
+ }
+ RichString_appendAscii(out, CRT_colors[METER_TEXT], HugePageMeter_active_labels[i]);
+ Meter_humanUnit(buffer, this->values[i], sizeof(buffer));
+ RichString_appendAscii(out, CRT_colors[HUGEPAGE_1 + i], buffer);
+ }
}
const MeterClass HugePageMeter_class = {
@@ -54,7 +92,7 @@ const MeterClass HugePageMeter_class = {
},
.updateValues = HugePageMeter_updateValues,
.defaultMode = BAR_METERMODE,
- .maxItems = 1,
+ .maxItems = ARRAYSIZE(HugePageMeter_active_labels),
.total = 100.0,
.attributes = HugePageMeter_attributes,
.name = "HugePages",

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