2021-01-05 14:50:23 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-04-29 18:13:36 +00:00
|
|
|
#include "linux/HugePageMeter.h"
|
2021-01-05 14:50:23 +00:00
|
|
|
|
2021-04-29 15:12:43 +00:00
|
|
|
#include <assert.h>
|
2021-01-14 14:46:37 +00:00
|
|
|
#include <math.h>
|
2021-04-29 15:12:43 +00:00
|
|
|
#include <stddef.h>
|
2021-01-14 14:46:37 +00:00
|
|
|
|
2021-01-05 14:50:23 +00:00
|
|
|
#include "CRT.h"
|
2021-04-29 15:12:43 +00:00
|
|
|
#include "Macros.h"
|
2021-01-05 14:50:23 +00:00
|
|
|
#include "Object.h"
|
2021-04-29 15:12:43 +00:00
|
|
|
#include "ProcessList.h"
|
2021-01-05 14:50:23 +00:00
|
|
|
#include "RichString.h"
|
2021-04-29 18:13:36 +00:00
|
|
|
#include "linux/LinuxProcessList.h"
|
2021-01-05 14:50:23 +00:00
|
|
|
|
2021-04-29 15:12:43 +00:00
|
|
|
|
2021-07-14 17:24:18 +00:00
|
|
|
static const char* HugePageMeter_active_labels[4] = { NULL, NULL, NULL, NULL };
|
2021-01-05 14:50:23 +00:00
|
|
|
|
|
|
|
static const int HugePageMeter_attributes[] = {
|
2021-01-14 14:46:37 +00:00
|
|
|
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:",
|
2021-01-05 14:50:23 +00:00
|
|
|
};
|
|
|
|
|
2020-10-06 11:13:16 +00:00
|
|
|
static void HugePageMeter_updateValues(Meter* this) {
|
2021-01-14 14:46:37 +00:00
|
|
|
assert(ARRAYSIZE(HugePageMeter_labels) == HTOP_HUGEPAGE_COUNT);
|
|
|
|
|
2020-10-06 11:13:16 +00:00
|
|
|
char* buffer = this->txtBuffer;
|
|
|
|
size_t size = sizeof(this->txtBuffer);
|
2021-01-05 14:50:23 +00:00
|
|
|
int written;
|
2021-01-06 17:11:24 +00:00
|
|
|
memory_t usedTotal = 0;
|
2021-01-14 14:46:37 +00:00
|
|
|
unsigned nextUsed = 0;
|
2021-01-05 14:50:23 +00:00
|
|
|
|
|
|
|
const LinuxProcessList* lpl = (const LinuxProcessList*) this->pl;
|
|
|
|
this->total = lpl->totalHugePageMem;
|
2021-01-14 14:46:37 +00:00
|
|
|
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++) {
|
2021-01-06 17:11:24 +00:00
|
|
|
memory_t value = lpl->usedHugePageMem[i];
|
|
|
|
if (value != MEMORY_MAX) {
|
2021-01-14 14:46:37 +00:00
|
|
|
this->values[nextUsed] = value;
|
|
|
|
usedTotal += value;
|
|
|
|
HugePageMeter_active_labels[nextUsed] = HugePageMeter_labels[i];
|
|
|
|
if (++nextUsed == ARRAYSIZE(HugePageMeter_active_labels)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-05 14:50:23 +00:00
|
|
|
|
2021-01-14 14:46:37 +00:00
|
|
|
written = Meter_humanUnit(buffer, usedTotal, size);
|
2021-01-05 14:50:23 +00:00
|
|
|
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);
|
|
|
|
|
2021-01-14 14:46:37 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-01-05 14:50:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MeterClass HugePageMeter_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete,
|
|
|
|
.display = HugePageMeter_display,
|
|
|
|
},
|
|
|
|
.updateValues = HugePageMeter_updateValues,
|
|
|
|
.defaultMode = BAR_METERMODE,
|
2021-01-14 14:46:37 +00:00
|
|
|
.maxItems = ARRAYSIZE(HugePageMeter_active_labels),
|
2021-01-05 14:50:23 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = HugePageMeter_attributes,
|
|
|
|
.name = "HugePages",
|
|
|
|
.uiName = "HugePages",
|
|
|
|
.caption = "HP"
|
|
|
|
};
|