Skip to content
Closed
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
26 changes: 17 additions & 9 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ in the source distribution for its full text.
#include "ListItem.h"
#include "Macros.h"
#include "MainPanel.h"
#include "MemoryMeter.h"
#include "OpenFilesScreen.h"
#include "Platform.h"
#include "Process.h"
#include "ProcessLocksScreen.h"
#include "ProvideCurses.h"
Expand Down Expand Up @@ -750,16 +752,22 @@ static Htop_Reaction actionHelp(State* st) {
attrset(CRT_colors[DEFAULT_COLOR]);
mvaddstr(line++, 0, "Memory bar: ");
addattrstr(CRT_colors[BAR_BORDER], "[");
addbartext(CRT_colors[MEMORY_USED], "", "used");
addbartext(CRT_colors[MEMORY_SHARED], "/", "shared");
addbartext(CRT_colors[MEMORY_COMPRESSED], "/", "compressed");
if (st->host->settings->showCachedMemory) {
addbartext(CRT_colors[MEMORY_BUFFERS_TEXT], "/", "buffers");
addbartext(CRT_colors[MEMORY_CACHE], "/", "cache");
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
} else {
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
// memory classes are OS-specific and provided in their <os>/Platform.c implementation
// ideal length of memory bar == 56 chars. Any length < 45 requires padding to 45.
// [0 1 2 3 4 5 ]
// [12345678901234567890123456789012345678901234567890123456]
// [ ^ 5 ]
// [class1/class2/class3/.../classN used/total]
int barTxtLen = 0;
for (unsigned int i = 0; i < Platform_numberOfMemoryClasses; i++) {
if (!st->host->settings->showCachedMemory && Platform_memoryClasses[i].countsAsCache)
continue; // skip reclaimable cache memory classes if "show cached memory" is not ticked
addbartext(CRT_colors[Platform_memoryClasses[i].color], (i == 0 ? "" : "/"), Platform_memoryClasses[i].label);
barTxtLen += (i == 0 ? 0 : 1) + strlen (Platform_memoryClasses[i].label);
}
for (int i = barTxtLen; i < 45; i++)
addattrstr(CRT_colors[BAR_SHADOW], " "); // pad to 45 chars if necessary
addbartext(CRT_colors[BAR_SHADOW], " ", "used");
addbartext(CRT_colors[BAR_SHADOW], "/", "total");
addattrstr(CRT_colors[BAR_BORDER], "]");

Expand Down
84 changes: 42 additions & 42 deletions CRT.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = A_BOLD | ColorPairGrayBlack,
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
[GRAPH_2] = ColorPair(Cyan, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
[MEMORY_SHARED] = ColorPair(Magenta, Black),
[MEMORY_COMPRESSED] = A_BOLD | ColorPairGrayBlack,
[MEMORY_1] = ColorPair(Green, Black),
[MEMORY_2] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_3] = ColorPair(Yellow, Black),
[MEMORY_4] = ColorPair(Magenta, Black),
[MEMORY_5] = A_BOLD | ColorPairGrayBlack,
[MEMORY_6] = ColorPair(Red, Black),
[HUGEPAGE_1] = ColorPair(Green, Black),
[HUGEPAGE_2] = ColorPair(Yellow, Black),
[HUGEPAGE_3] = ColorPair(Red, Black),
Expand Down Expand Up @@ -296,12 +296,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = A_DIM,
[GRAPH_1] = A_BOLD,
[GRAPH_2] = A_NORMAL,
[MEMORY_USED] = A_BOLD,
[MEMORY_BUFFERS] = A_NORMAL,
[MEMORY_BUFFERS_TEXT] = A_NORMAL,
[MEMORY_CACHE] = A_NORMAL,
[MEMORY_SHARED] = A_NORMAL,
[MEMORY_COMPRESSED] = A_DIM,
[MEMORY_1] = A_BOLD,
[MEMORY_2] = A_NORMAL,
[MEMORY_3] = A_NORMAL,
[MEMORY_4] = A_NORMAL,
[MEMORY_5] = A_DIM,
[MEMORY_6] = A_NORMAL,
[HUGEPAGE_1] = A_BOLD,
[HUGEPAGE_2] = A_NORMAL,
[HUGEPAGE_3] = A_REVERSE | A_BOLD,
Expand Down Expand Up @@ -414,12 +414,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = A_BOLD | ColorPair(Black, White),
[GRAPH_1] = A_BOLD | ColorPair(Blue, White),
[GRAPH_2] = ColorPair(Blue, White),
[MEMORY_USED] = ColorPair(Green, White),
[MEMORY_BUFFERS] = ColorPair(Cyan, White),
[MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White),
[MEMORY_CACHE] = ColorPair(Yellow, White),
[MEMORY_SHARED] = ColorPair(Magenta, White),
[MEMORY_COMPRESSED] = A_BOLD | ColorPair(Black, White),
[MEMORY_1] = ColorPair(Green, White),
[MEMORY_2] = ColorPair(Cyan, White),
[MEMORY_3] = ColorPair(Yellow, White),
[MEMORY_4] = ColorPair(Magenta, White),
[MEMORY_5] = A_BOLD | ColorPair(Black, White),
[MEMORY_6] = ColorPair(Red, White),
[HUGEPAGE_1] = ColorPair(Green, White),
[HUGEPAGE_2] = ColorPair(Yellow, White),
[HUGEPAGE_3] = ColorPair(Red, White),
Expand Down Expand Up @@ -532,12 +532,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = ColorPairGrayBlack,
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Black),
[GRAPH_2] = ColorPair(Cyan, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = ColorPair(Cyan, Black),
[MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
[MEMORY_SHARED] = ColorPair(Magenta, Black),
[MEMORY_COMPRESSED] = ColorPairGrayBlack,
[MEMORY_1] = ColorPair(Green, Black),
[MEMORY_2] = ColorPair(Cyan, Black),
[MEMORY_3] = ColorPair(Yellow, Black),
[MEMORY_4] = ColorPair(Magenta, Black),
[MEMORY_5] = ColorPairGrayBlack,
[MEMORY_6] = ColorPair(Red, Black),
[HUGEPAGE_1] = ColorPair(Green, Black),
[HUGEPAGE_2] = ColorPair(Yellow, Black),
[HUGEPAGE_3] = ColorPair(Red, Black),
Expand Down Expand Up @@ -650,12 +650,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = A_BOLD | ColorPair(Black, Blue),
[GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue),
[GRAPH_2] = ColorPair(Cyan, Blue),
[MEMORY_USED] = A_BOLD | ColorPair(Green, Blue),
[MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan, Blue),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue),
[MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue),
[MEMORY_SHARED] = A_BOLD | ColorPair(Magenta, Blue),
[MEMORY_COMPRESSED] = A_BOLD | ColorPair(Black, Blue),
[MEMORY_1] = A_BOLD | ColorPair(Green, Blue),
[MEMORY_2] = A_BOLD | ColorPair(Cyan, Blue),
[MEMORY_3] = A_BOLD | ColorPair(Yellow, Blue),
[MEMORY_4] = A_BOLD | ColorPair(Magenta, Blue),
[MEMORY_5] = A_BOLD | ColorPair(Black, Blue),
[MEMORY_6] = A_BOLD | ColorPair(Red, Blue),
[HUGEPAGE_1] = A_BOLD | ColorPair(Green, Blue),
[HUGEPAGE_2] = A_BOLD | ColorPair(Yellow, Blue),
[HUGEPAGE_3] = A_BOLD | ColorPair(Red, Blue),
Expand Down Expand Up @@ -768,12 +768,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = ColorPair(Yellow, Black),
[GRAPH_1] = A_BOLD | ColorPair(Green, Black),
[GRAPH_2] = ColorPair(Green, Black),
[MEMORY_USED] = ColorPair(Green, Black),
[MEMORY_BUFFERS] = ColorPair(Blue, Black),
[MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black),
[MEMORY_CACHE] = ColorPair(Yellow, Black),
[MEMORY_SHARED] = ColorPair(Magenta, Black),
[MEMORY_COMPRESSED] = ColorPair(Yellow, Black),
[MEMORY_1] = ColorPair(Green, Black),
[MEMORY_2] = ColorPair(Blue, Black),
[MEMORY_3] = ColorPair(Yellow, Black),
[MEMORY_4] = ColorPair(Magenta, Black),
[MEMORY_5] = ColorPair(Yellow, Black),
[MEMORY_6] = ColorPair(Red, Black),
[HUGEPAGE_1] = ColorPair(Green, Black),
[HUGEPAGE_2] = ColorPair(Yellow, Black),
[HUGEPAGE_3] = ColorPair(Red, Black),
Expand Down Expand Up @@ -881,12 +881,12 @@ static int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[SWAP_FRONTSWAP] = A_BOLD | ColorPairGrayBlack,
[GRAPH_1] = A_BOLD,
[GRAPH_2] = A_NORMAL,
[MEMORY_USED] = A_BOLD | ColorPair(Yellow, Black),
[MEMORY_BUFFERS] = A_NORMAL,
[MEMORY_BUFFERS_TEXT] = A_NORMAL,
[MEMORY_CACHE] = A_NORMAL,
[MEMORY_SHARED] = A_NORMAL,
[MEMORY_COMPRESSED] = A_BOLD | ColorPairGrayBlack,
[MEMORY_1] = A_BOLD | ColorPair(Yellow, Black),
[MEMORY_2] = A_NORMAL,
[MEMORY_3] = A_NORMAL,
[MEMORY_4] = A_NORMAL,
[MEMORY_5] = A_BOLD | ColorPairGrayBlack,
[MEMORY_6] = A_NORMAL,
[HUGEPAGE_1] = A_BOLD,
[HUGEPAGE_2] = A_NORMAL,
[HUGEPAGE_3] = A_BOLD | ColorPair(Cyan, Black),
Expand Down
12 changes: 6 additions & 6 deletions CRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ typedef enum ColorElements_ {
BAR_SHADOW,
GRAPH_1,
GRAPH_2,
MEMORY_USED,
MEMORY_BUFFERS,
MEMORY_BUFFERS_TEXT,
MEMORY_CACHE,
MEMORY_SHARED,
MEMORY_COMPRESSED,
MEMORY_1,
MEMORY_2,
MEMORY_3,
MEMORY_4,
MEMORY_5,
MEMORY_6,
HUGEPAGE_1,
HUGEPAGE_2,
HUGEPAGE_3,
Expand Down
5 changes: 0 additions & 5 deletions Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ typedef struct Machine_ {
#endif

memory_t totalMem;
memory_t usedMem;
memory_t buffersMem;
memory_t cachedMem;
memory_t sharedMem;
memory_t availableMem;

memory_t totalSwap;
memory_t usedSwap;
Expand Down
91 changes: 38 additions & 53 deletions MemoryMeter.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
htop - MemoryMeter.c
(C) 2004-2011 Hisham H. Muhammad
(C) 2025 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
Expand All @@ -21,11 +22,12 @@ in the source distribution for its full text.


static const int MemoryMeter_attributes[] = {
MEMORY_USED,
MEMORY_SHARED,
MEMORY_COMPRESSED,
MEMORY_BUFFERS,
MEMORY_CACHE
MEMORY_1,
MEMORY_2,
MEMORY_3,
MEMORY_4,
MEMORY_5,
MEMORY_6
};

static void MemoryMeter_updateValues(Meter* this) {
Expand All @@ -35,26 +37,30 @@ static void MemoryMeter_updateValues(Meter* this) {

Settings *settings = this->host->settings;

/* 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;
/* not all memory classes are supported on all platforms */
for (unsigned int memoryClassIdx = 0; memoryClassIdx < Platform_numberOfMemoryClasses; memoryClassIdx++) {
this->values[memoryClassIdx] = NAN;
}

Platform_setMemoryValues(this);
this->curItems = (uint8_t) Platform_numberOfMemoryClasses;

/* compute the used memory */
double used = 0.0;
for (unsigned int memoryClassIdx = 0; memoryClassIdx < Platform_numberOfMemoryClasses; memoryClassIdx++) {
if (Platform_memoryClasses[memoryClassIdx].countsAsUsed) {
used += this->values[memoryClassIdx];
}
}

/* clear the values we don't want to see */
if ((this->mode == GRAPH_METERMODE || this->mode == BAR_METERMODE) && !settings->showCachedMemory) {
this->values[MEMORY_METER_BUFFERS] = 0;
this->values[MEMORY_METER_CACHE] = 0;
for (unsigned int memoryClassIdx = 0; memoryClassIdx < Platform_numberOfMemoryClasses; memoryClassIdx++) {
if (Platform_memoryClasses[memoryClassIdx].countsAsCache) {
this->values[memoryClassIdx] = NAN;
}
}
}
/* Do not print available memory in bar mode */
static_assert(MEMORY_METER_AVAILABLE + 1 == MEMORY_METER_ITEMCOUNT,
"MEMORY_METER_AVAILABLE is not the last item in MemoryMeterValues");
this->curItems = MEMORY_METER_AVAILABLE;

/* we actually want to show "used + shared + compressed" */
double used = this->values[MEMORY_METER_USED];
if (isPositive(this->values[MEMORY_METER_SHARED]))
used += this->values[MEMORY_METER_SHARED];
if (isPositive(this->values[MEMORY_METER_COMPRESSED]))
used += this->values[MEMORY_METER_COMPRESSED];

written = Meter_humanUnit(buffer, used, size);
METER_BUFFER_CHECK(buffer, size, written);
Expand All @@ -73,37 +79,16 @@ static void MemoryMeter_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[MEMORY_METER_USED], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " used:");
RichString_appendAscii(out, CRT_colors[MEMORY_USED], buffer);

/* shared memory is not supported on all platforms */
if (isNonnegative(this->values[MEMORY_METER_SHARED])) {
Meter_humanUnit(buffer, this->values[MEMORY_METER_SHARED], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " shared:");
RichString_appendAscii(out, CRT_colors[MEMORY_SHARED], buffer);
}

/* compressed memory is not supported on all platforms */
if (isNonnegative(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_BUFFERS], sizeof(buffer));
RichString_appendAscii(out, settings->showCachedMemory ? CRT_colors[METER_TEXT] : CRT_colors[METER_SHADOW], " buffers:");
RichString_appendAscii(out, settings->showCachedMemory ? CRT_colors[MEMORY_BUFFERS_TEXT] : CRT_colors[METER_SHADOW], buffer);

Meter_humanUnit(buffer, this->values[MEMORY_METER_CACHE], sizeof(buffer));
RichString_appendAscii(out, settings->showCachedMemory ? CRT_colors[METER_TEXT] : CRT_colors[METER_SHADOW], " cache:");
RichString_appendAscii(out, settings->showCachedMemory ? CRT_colors[MEMORY_CACHE] : CRT_colors[METER_SHADOW], buffer);
/* print the memory classes in the order supplied (specific to each platform) */
for (unsigned int memoryClassIdx = 0; memoryClassIdx < Platform_numberOfMemoryClasses; memoryClassIdx++) {
if (!settings->showCachedMemory && Platform_memoryClasses[memoryClassIdx].countsAsCache)
continue; // skip reclaimable cache memory classes if "show cached memory" is not ticked

/* available memory is not supported on all platforms */
if (isNonnegative(this->values[MEMORY_METER_AVAILABLE])) {
Meter_humanUnit(buffer, this->values[MEMORY_METER_AVAILABLE], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " available:");
RichString_appendAscii(out, CRT_colors[METER_VALUE], buffer);
Meter_humanUnit(buffer, this->values[memoryClassIdx], sizeof(buffer));
RichString_appendAscii(out, CRT_colors[METER_TEXT], " ");
RichString_appendAscii(out, CRT_colors[METER_TEXT], Platform_memoryClasses[memoryClassIdx].label);
RichString_appendAscii(out, CRT_colors[METER_TEXT], ":");
RichString_appendAscii(out, CRT_colors[Platform_memoryClasses[memoryClassIdx].color], buffer);
}
}

Expand All @@ -116,7 +101,7 @@ const MeterClass MemoryMeter_class = {
.updateValues = MemoryMeter_updateValues,
.defaultMode = BAR_METERMODE,
.supportedModes = METERMODE_DEFAULT_SUPPORTED,
.maxItems = MEMORY_METER_ITEMCOUNT,
.maxItems = 6, // maximum of MEMORY_N settings
.isPercentChart = true,
.total = 100.0,
.attributes = MemoryMeter_attributes,
Expand Down
16 changes: 7 additions & 9 deletions MemoryMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
/*
htop - MemoryMeter.h
(C) 2004-2011 Hisham H. Muhammad
(C) 2025 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include "Meter.h"

typedef enum {
MEMORY_METER_USED = 0,
MEMORY_METER_SHARED = 1,
MEMORY_METER_COMPRESSED = 2,
MEMORY_METER_BUFFERS = 3,
MEMORY_METER_CACHE = 4,
MEMORY_METER_AVAILABLE = 5,
MEMORY_METER_ITEMCOUNT = 6, // number of entries in this enum
} MemoryMeterValues;
typedef struct MemoryClass_s {
const char *label; // e.g. "wired", "shared", "compressed" - platform-specific memory classe names
bool countsAsUsed; // memory class counts as "used" memory
bool countsAsCache; // memory class reclaimed under pressure (displayed with "show cached memory")
ColorElements color; // one of the MEMORY CRT color values
} MemoryClass;

extern const MeterClass MemoryMeter_class;

Expand Down
4 changes: 0 additions & 4 deletions darwin/DarwinMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ typedef struct DarwinMachine_ {
Machine super;

host_basic_info_data_t host_info;
#ifdef HAVE_STRUCT_VM_STATISTICS64
vm_statistics64_data_t vm_stats;
#else
vm_statistics_data_t vm_stats;
#endif
processor_cpu_load_info_t prev_load;
processor_cpu_load_info_t curr_load;

Expand Down
Loading
Loading