diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-05 15:50:23 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2021-01-19 18:06:48 +0100 |
commit | 4d85848988d8d4e7b2dc64e6600b099171e5b803 (patch) | |
tree | b2970454f078fe57536cf2ebc8bb6ba32bd092a1 /linux/HugePageMeter.c | |
parent | 71f51a20c1f7aa94f8e8c0012448c05c465cfc01 (diff) |
Linux: handle hugepages
Subtract hugepages from normal memory.
Add a HugePageMeter.
Closes: #447
Diffstat (limited to 'linux/HugePageMeter.c')
-rw-r--r-- | linux/HugePageMeter.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/linux/HugePageMeter.c b/linux/HugePageMeter.c new file mode 100644 index 00000000..e546c79a --- /dev/null +++ b/linux/HugePageMeter.c @@ -0,0 +1,63 @@ +/* +htop - HugePageMeter.c +(C) 2021 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "HugePageMeter.h" + +#include "LinuxProcessList.h" + +#include "CRT.h" +#include "Object.h" +#include "RichString.h" + + +static const int HugePageMeter_attributes[] = { + MEMORY_USED, +}; + +static void HugePageMeter_updateValues(Meter* this, char* buffer, size_t size) { + int written; + + const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl; + this->total = lpl->totalHugePageMem; + this->values[0] = lpl->totalHugePageMem - lpl->freeHugePageMem; + + written = Meter_humanUnit(buffer, this->values[0], size); + METER_BUFFER_CHECK(buffer, size, written); + + METER_BUFFER_APPEND_CHR(buffer, size, '/'); + + Meter_humanUnit(buffer, this->total, size); +} + +static void HugePageMeter_display(const Object* cast, RichString* out) { + char buffer[50]; + const Meter* this = (const Meter*)cast; + + RichString_writeAscii(out, CRT_colors[METER_TEXT], ":"); + 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); +} + +const MeterClass HugePageMeter_class = { + .super = { + .extends = Class(Meter), + .delete = Meter_delete, + .display = HugePageMeter_display, + }, + .updateValues = HugePageMeter_updateValues, + .defaultMode = BAR_METERMODE, + .maxItems = 1, + .total = 100.0, + .attributes = HugePageMeter_attributes, + .name = "HugePages", + .uiName = "HugePages", + .caption = "HP" +}; |