summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSohaib Mohamed <sohaib.amhmd@gmail.com>2023-08-22 16:46:59 +1000
committerNathan Scott <nathans@redhat.com>2023-08-30 13:11:57 +1000
commit53bdcab942298e0e452d62237bc18e3a4cd551cf (patch)
treee7a62910b9f4a1a58560a4ded2e6f7e83d0b631e
parent0f751e991d399769fb8d7800f7c4bccec2ca7f60 (diff)
Support dynamic screens with 'top-most' entities beyond processes
This implements our concept of 'dynamic screens' in htop, with a first use-case of pcp-htop displaying things like top-filesystem and top-cgroups under new screen tabs. However the idea is more general than use in pcp-htop and we've paved the way here for us to collectively build mroe general tabular screens in core htop, as well. From the pcp-htop side of things, dynamic screens are configured using text-based configuration files that define the mapping for PCP metrics to columns (and metric instances to rows). Metrics are defined either directly (via metric names) or indirectly via PCP derived metric specifications. Value scaling and the units displayed is automatic based on PCP metric units and data types. This commit represents a collaborative effort of several months, primarily between myself, Nathan and BenBE. Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com> Signed-off-by: Nathan Scott <nathans@redhat.com>
-rw-r--r--Action.c61
-rw-r--r--Action.h2
-rw-r--r--AvailableColumnsPanel.c48
-rw-r--r--AvailableColumnsPanel.h3
-rw-r--r--CategoriesPanel.c18
-rw-r--r--ColumnsPanel.c5
-rw-r--r--CommandLine.c13
-rw-r--r--DisplayOptionsPanel.c4
-rw-r--r--DynamicColumn.c15
-rw-r--r--DynamicColumn.h25
-rw-r--r--DynamicScreen.c65
-rw-r--r--DynamicScreen.h39
-rw-r--r--Machine.c36
-rw-r--r--Machine.h7
-rw-r--r--MainPanel.c20
-rw-r--r--MainPanel.h4
-rw-r--r--Makefile.am12
-rw-r--r--Process.c4
-rw-r--r--Process.h2
-rw-r--r--Row.c19
-rw-r--r--Row.h6
-rw-r--r--ScreenManager.c2
-rw-r--r--ScreenTabsPanel.c372
-rw-r--r--ScreenTabsPanel.h60
-rw-r--r--ScreensPanel.c23
-rw-r--r--ScreensPanel.h6
-rw-r--r--Settings.c107
-rw-r--r--Settings.h17
-rw-r--r--Table.c3
-rw-r--r--darwin/Platform.h14
-rw-r--r--dragonflybsd/Platform.h14
-rw-r--r--freebsd/Platform.h14
-rw-r--r--linux/Platform.h14
-rw-r--r--netbsd/Platform.h14
-rw-r--r--openbsd/Platform.h14
-rw-r--r--pcp/InDomTable.c97
-rw-r--r--pcp/InDomTable.h36
-rw-r--r--pcp/Instance.c160
-rw-r--r--pcp/Instance.h37
-rw-r--r--pcp/PCPDynamicColumn.c249
-rw-r--r--pcp/PCPDynamicColumn.h21
-rw-r--r--pcp/PCPDynamicMeter.h6
-rw-r--r--pcp/PCPDynamicScreen.c405
-rw-r--r--pcp/PCPDynamicScreen.h56
-rw-r--r--pcp/PCPMachine.c2
-rw-r--r--pcp/PCPMetric.c19
-rw-r--r--pcp/PCPMetric.h4
-rw-r--r--pcp/Platform.c32
-rw-r--r--pcp/Platform.h16
-rw-r--r--pcp/screens/biosnoop41
-rw-r--r--pcp/screens/cgroups45
-rw-r--r--pcp/screens/cgroupsio49
-rw-r--r--pcp/screens/cgroupsmem48
-rw-r--r--pcp/screens/devices114
-rw-r--r--pcp/screens/execsnoop37
-rw-r--r--pcp/screens/exitsnoop48
-rw-r--r--pcp/screens/filesystems50
-rw-r--r--pcp/screens/opensnoop27
-rw-r--r--solaris/Platform.h14
-rw-r--r--unsupported/Platform.h14
60 files changed, 2532 insertions, 177 deletions
diff --git a/Action.c b/Action.c
index f7fc4a43..e00383c7 100644
--- a/Action.c
+++ b/Action.c
@@ -165,6 +165,17 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
// ----------------------------------------
+static bool Action_writeableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ bool readonly = Settings_isReadonly() || settings->ss->dynamic;
+ return !readonly;
+}
+
+static bool Action_readableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ return !settings->ss->dynamic;
+}
+
static Htop_Reaction actionSetSortColumn(State* st) {
Htop_Reaction reaction = HTOP_OK;
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
@@ -303,7 +314,7 @@ static Htop_Reaction actionIncSearch(State* st) {
}
static Htop_Reaction actionHigherPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, -1);
@@ -311,7 +322,7 @@ static Htop_Reaction actionHigherPriority(State* st) {
}
static Htop_Reaction actionLowerPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, 1);
@@ -345,13 +356,27 @@ static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
return st->host->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
}
+static inline void setActiveScreen(Settings* settings, State* st, unsigned int ssIdx) {
+ assert(settings->ssIndex == ssIdx);
+ Machine* host = st->host;
+
+ settings->ss = settings->screens[ssIdx];
+ if (!settings->ss->table)
+ settings->ss->table = host->processTable;
+ host->activeTable = settings->ss->table;
+
+ // set correct functionBar - readonly if requested, and/or with non-process screens
+ bool readonly = Settings_isReadonly() || (host->activeTable != host->processTable);
+ MainPanel_setFunctionBar(st->mainPanel, readonly);
+}
+
static Htop_Reaction actionNextScreen(State* st) {
Settings* settings = st->host->settings;
settings->ssIndex++;
if (settings->ssIndex == settings->nScreens) {
settings->ssIndex = 0;
}
- settings->ss = settings->screens[settings->ssIndex];
+ setActiveScreen(settings, st, settings->ssIndex);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
@@ -362,21 +387,22 @@ static Htop_Reaction actionPrevScreen(State* st) {
} else {
settings->ssIndex--;
}
- settings->ss = settings->screens[settings->ssIndex];
+ setActiveScreen(settings, st, settings->ssIndex);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
-Htop_Reaction Action_setScreenTab(Settings* settings, int x) {
+Htop_Reaction Action_setScreenTab(State* st, int x) {
+ Settings* settings = st->host->settings;
int s = 2;
for (unsigned int i = 0; i < settings->nScreens; i++) {
if (x < s) {
return 0;
}
- const char* name = settings->screens[i]->name;
- int len = strlen(name);
+ const char* tab = settings->screens[i]->heading;
+ int len = strlen(tab);
if (x <= s + len + 1) {
settings->ssIndex = i;
- settings->ss = settings->screens[i];
+ setActiveScreen(settings, st, i);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
s += len + 3;
@@ -389,7 +415,7 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) {
}
static Htop_Reaction actionSetAffinity(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
Machine* host = st->host;
@@ -426,7 +452,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
#ifdef SCHEDULER_SUPPORT
static Htop_Reaction actionSetSchedPolicy(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_KEEP_FOLLOWING;
static int preSelectedPolicy = SCHEDULINGPANEL_INITSELECTEDPOLICY;
@@ -470,7 +496,7 @@ static Htop_Reaction actionSetSchedPolicy(State* st) {
#endif /* SCHEDULER_SUPPORT */
static Htop_Reaction actionKill(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;
@@ -521,7 +547,7 @@ static Htop_Reaction actionSetup(State* st) {
}
static Htop_Reaction actionLsof(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
@@ -539,6 +565,9 @@ static Htop_Reaction actionLsof(State* st) {
}
static Htop_Reaction actionShowLocks(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -554,7 +583,7 @@ static Htop_Reaction actionShowLocks(State* st) {
}
static Htop_Reaction actionStrace(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
@@ -805,6 +834,9 @@ static Htop_Reaction actionTagAllChildren(State* st) {
}
static Htop_Reaction actionShowEnvScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -820,6 +852,9 @@ static Htop_Reaction actionShowEnvScreen(State* st) {
}
static Htop_Reaction actionShowCommandScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
diff --git a/Action.h b/Action.h
index 3540e93e..d285e1b8 100644
--- a/Action.h
+++ b/Action.h
@@ -57,7 +57,7 @@ bool Action_setUserOnly(const char* userName, uid_t* userId);
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
-Htop_Reaction Action_setScreenTab(Settings* settings, int x);
+Htop_Reaction Action_setScreenTab(State* st, int x);
Htop_Reaction Action_follow(State* st);
diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c
index f3c40843..a590bac2 100644
--- a/AvailableColumnsPanel.c
+++ b/AvailableColumnsPanel.c
@@ -18,6 +18,7 @@ in the source distribution for its full text.
#include "Hashtable.h"
#include "ListItem.h"
#include "Object.h"
+#include "Platform.h"
#include "Process.h"
#include "ProvideCurses.h"
#include "XUtils.h"
@@ -35,7 +36,7 @@ static void AvailableColumnsPanel_delete(Object* object) {
static void AvailableColumnsPanel_insert(AvailableColumnsPanel* this, int at, int key) {
const char* name;
if (key >= ROW_DYNAMIC_FIELDS)
- name = DynamicColumn_init(key);
+ name = DynamicColumn_name(key);
else
name = Process_fields[key].name;
Panel_insert(this->columns, at, (Object*) ListItem_new(name, key));
@@ -81,42 +82,61 @@ const PanelClass AvailableColumnsPanel_class = {
static void AvailableColumnsPanel_addDynamicColumn(ht_key_t key, void* value, void* data) {
const DynamicColumn* column = (const DynamicColumn*) value;
- Panel* super = (Panel*) data;
- const char* title = column->caption ? column->caption : column->heading;
- if (!title)
- title = column->name; // fallback to the only mandatory field
+ if (column->table) /* DynamicScreen, handled differently */
+ return;
+ AvailableColumnsPanel* this = (AvailableColumnsPanel*) data;
+ const char* title = column->heading ? column->heading : column->name;
+ const char* text = column->description ? column->description : column->caption;
char description[256];
- xSnprintf(description, sizeof(description), "%s - %s", title, column->description);
- Panel_add(super, (Object*) ListItem_new(description, key));
+ if (text)
+ xSnprintf(description, sizeof(description), "%s - %s", title, text);
+ else
+ xSnprintf(description, sizeof(description), "%s", title);
+ Panel_add(&this->super, (Object*) ListItem_new(description, key));
}
// Handle DynamicColumns entries in the AvailableColumnsPanel
-static void AvailableColumnsPanel_addDynamicColumns(Panel* super, Hashtable* dynamicColumns) {
+static void AvailableColumnsPanel_addDynamicColumns(AvailableColumnsPanel* this, Hashtable* dynamicColumns) {
assert(dynamicColumns);
- Hashtable_foreach(dynamicColumns, AvailableColumnsPanel_addDynamicColumn, super);
+ Hashtable_foreach(dynamicColumns, AvailableColumnsPanel_addDynamicColumn, this);
}
// Handle remaining Platform Meter entries in the AvailableColumnsPanel
-static void AvailableColumnsPanel_addPlatformColumn(Panel* super) {
+static void AvailableColumnsPanel_addPlatformColumns(AvailableColumnsPanel* this) {
for (int i = 1; i < LAST_PROCESSFIELD; i++) {
if (i != COMM && Process_fields[i].description) {
char description[256];
xSnprintf(description, sizeof(description), "%s - %s", Process_fields[i].name, Process_fields[i].description);
- Panel_add(super, (Object*) ListItem_new(description, i));
+ Panel_add(&this->super, (Object*) ListItem_new(description, i));
}
}
}
+// Handle DynamicColumns entries associated with DynamicScreens
+static void AvailableColumnsPanel_addDynamicScreens(AvailableColumnsPanel* this, const char* screen) {
+ Platform_addDynamicScreenAvailableColumns(&this->super, screen);
+}
+
+void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamicScreen, Hashtable* dynamicColumns) {
+ Panel* super = (Panel*) this;
+ Panel_prune(super);
+ if (dynamicScreen) {
+ AvailableColumnsPanel_addDynamicScreens(this, dynamicScreen);
+ } else {
+ AvailableColumnsPanel_addPlatformColumns(this);
+ AvailableColumnsPanel_addDynamicColumns(this, dynamicColumns);
+ }
+}
+
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns) {
AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
Panel* super = (Panel*) this;
FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
-
Panel_setHeader(super, "Available Columns");
- AvailableColumnsPanel_addPlatformColumn(super);
- AvailableColumnsPanel_addDynamicColumns(super, dynamicColumns);
this->columns = columns;
+ AvailableColumnsPanel_fill(this, NULL, dynamicColumns);
+
return this;
}
diff --git a/AvailableColumnsPanel.h b/AvailableColumnsPanel.h
index aca59060..3d233be0 100644
--- a/AvailableColumnsPanel.h
+++ b/AvailableColumnsPanel.h
@@ -9,6 +9,7 @@ in the source distribution for its full text.
#include "Hashtable.h"
#include "Panel.h"
+#include "Settings.h"
typedef struct AvailableColumnsPanel_ {
@@ -20,4 +21,6 @@ extern const PanelClass AvailableColumnsPanel_class;
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns);
+void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamicScreen, Hashtable* dynamicColumns);
+
#endif
diff --git a/CategoriesPanel.c b/CategoriesPanel.c
index ba7ee503..31c7da05 100644
--- a/CategoriesPanel.c
+++ b/CategoriesPanel.c
@@ -25,6 +25,7 @@ in the source distribution for its full text.
#include "Object.h"
#include "ProvideCurses.h"
#include "ScreensPanel.h"
+#include "ScreenTabsPanel.h"
#include "Vector.h"
#include "XUtils.h"
@@ -72,11 +73,21 @@ static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
ScreenManager_add(this->scr, colors, -1);
}
+#if defined(HTOP_PCP) /* all platforms supporting dynamic screens */
+static void CategoriesPanel_makeScreenTabsPage(CategoriesPanel* this) {
+ Settings* settings = this->host->settings;
+ Panel* screenTabs = (Panel*) ScreenTabsPanel_new(settings);
+ Panel* screenNames = (Panel*) ((ScreenTabsPanel*)screenTabs)->names;
+ ScreenManager_add(this->scr, screenTabs, 20);
+ ScreenManager_add(this->scr, screenNames, -1);
+}
+#endif
+
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
Settings* settings = this->host->settings;
Panel* screens = (Panel*) ScreensPanel_new(settings);
Panel* columns = (Panel*) ((ScreensPanel*)screens)->columns;
- Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns, settings->dynamicColumns);
+ Panel* availableColumns = (Panel*) ((ScreensPanel*)screens)->availableColumns;
ScreenManager_add(this->scr, screens, 20);
ScreenManager_add(this->scr, columns, 20);
ScreenManager_add(this->scr, availableColumns, -1);
@@ -94,10 +105,13 @@ typedef struct CategoriesPanelPage_ {
CategoriesPanel_makePageFunc ctor;
} CategoriesPanelPage;
-static const CategoriesPanelPage categoriesPanelPages[] = {
+static CategoriesPanelPage categoriesPanelPages[] = {
{ .name = "Display options", .ctor = CategoriesPanel_makeDisplayOptionsPage },
{ .name = "Header layout", .ctor = CategoriesPanel_makeHeaderOptionsPage },
{ .name = "Meters", .ctor = CategoriesPanel_makeMetersPage },
+#if defined(HTOP_PCP) /* all platforms supporting dynamic screens */
+ { .name = "Screen tabs", .ctor = CategoriesPanel_makeScreenTabsPage },
+#endif
{ .name = "Screens", .ctor = CategoriesPanel_makeScreensPage },
{ .name = "Colors", .ctor = CategoriesPanel_makeColorsPage },
};
diff --git a/ColumnsPanel.c b/ColumnsPanel.c
index ecae36f7..e3445a00 100644
--- a/ColumnsPanel.c
+++ b/ColumnsPanel.c
@@ -128,9 +128,8 @@ static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns)
if (!column) {
name = NULL;
} else {
- name = column->caption ? column->caption : column->heading;
- if (!name)
- name = column->name; /* name is a mandatory field */
+ /* heading preferred here but name is always available */
+ name = column->heading ? column->heading : column->name;
}
}
if (name == NULL)
diff --git a/CommandLine.c b/CommandLine.c
index 848c7ae7..2cd90516 100644
--- a/CommandLine.c
+++ b/CommandLine.c
@@ -25,6 +25,7 @@ in the source distribution for its full text.
#include "CRT.h"
#include "DynamicColumn.h"
#include "DynamicMeter.h"
+#include "DynamicScreen.h"
#include "Hashtable.h"
#include "Header.h"
#include "IncSet.h"
@@ -337,15 +338,12 @@ int CommandLine_run(int argc, char** argv) {
UsersTable* ut = UsersTable_new();
Hashtable* dm = DynamicMeters_new();
Hashtable* dc = DynamicColumns_new();
- if (!dc)
- dc = Hashtable_new(0, true);
+ Hashtable* ds = DynamicScreens_new();
Machine* host = Machine_new(ut, flags.userId);
ProcessList* pl = ProcessList_new(host, flags.pidMatchList);
- Settings* settings = Settings_new(host->activeCPUs, dm, dc);
-
- host->settings = settings;
- Machine_addTable(host, &pl->super, true);
+ Settings* settings = Settings_new(host->activeCPUs, dm, dc, ds);
+ Machine_populateTablesFromSettings(host, settings, &pl->super);
Header* header = Header_new(host, 2);
Header_populateFromSettings(header);
@@ -377,7 +375,7 @@ int CommandLine_run(int argc, char** argv) {
CRT_init(settings, flags.allowUnicode, flags.iterationsRemaining != -1);
MainPanel* panel = MainPanel_new();
- Table_setPanel(&pl->super, (Panel*) panel);
+ Machine_setTablesPanel(host, (Panel*) panel);
MainPanel_updateLabels(panel, settings->ss->treeView, flags.commFilter);
@@ -435,6 +433,7 @@ int CommandLine_run(int argc, char** argv) {
Settings_delete(settings);
DynamicColumns_delete(dc);
DynamicMeters_delete(dm);
+ DynamicScreens_delete(ds);
return 0;
}
diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c
index 326d33b1..e74409fc 100644
--- a/DisplayOptionsPanel.c
+++ b/DisplayOptionsPanel.c
@@ -104,12 +104,12 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
#define TABMSG "For current screen tab: \0"
char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG;
- strncat(tabheader, settings->ss->name, SCREEN_NAME_LEN);
+ strncat(tabheader, settings->ss->heading, SCREEN_NAME_LEN);
Panel_add(super, (Object*) TextItem_new(tabheader));
#undef TABMSG
Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView)));
- Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by ID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByID)));
+ Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID)));
Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed)));
Panel_add(super, (Object*) TextItem_new("Global options:"));
Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs)));
diff --git a/DynamicColumn.c b/DynamicColumn.c
index bd038df4..7c0ed3ad 100644
--- a/DynamicColumn.c
+++ b/DynamicColumn.c
@@ -19,7 +19,10 @@ in the source distribution for its full text.
Hashtable* DynamicColumns_new(void) {
- return Platform_dynamicColumns();
+ Hashtable* dynamics = Platform_dynamicColumns();
+ if (!dynamics)
+ dynamics = Hashtable_new(0, true);
+ return dynamics;
}
void DynamicColumns_delete(Hashtable* dynamics) {
@@ -29,8 +32,14 @@ void DynamicColumns_delete(Hashtable* dynamics) {
}
}
-const char* DynamicColumn_init(unsigned int key) {
- return Platform_dynamicColumnInit(key);
+const char* DynamicColumn_name(unsigned int key) {
+ return Platform_dynamicColumnName(key);
+}
+
+void DynamicColumn_done(DynamicColumn* this) {
+ free(this->heading);
+ free(this->caption);
+ free(this->description);
}
typedef struct {
diff --git a/DynamicColumn.h b/DynamicColumn.h
index 4760e6ea..3b0336a9 100644
--- a/DynamicColumn.h
+++ b/DynamicColumn.h
@@ -1,29 +1,40 @@
#ifndef HEADER_DynamicColumn
#define HEADER_DynamicColumn
+/*
+htop - DynamicColumn.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
#include <stdbool.h>
#include "Hashtable.h"
#include "Process.h"
#include "RichString.h"
+#include "Table.h"
-#define DYNAMIC_MAX_COLUMN_WIDTH 28
+#define DYNAMIC_MAX_COLUMN_WIDTH 64
#define DYNAMIC_DEFAULT_COLUMN_WIDTH -5
typedef struct DynamicColumn_ {
- char name[32]; /* unique, internal-only name */
- char* heading; /* displayed in main screen */
- char* caption; /* displayed in setup menu (short name) */
- char* description; /* displayed in setup menu (detail) */
- int width; /* display width +/- for value alignment */
+ char name[32]; /* unique, internal-only name */
+ char* heading; /* displayed in main screen */
+ char* caption; /* displayed in setup menu (short name) */
+ char* description; /* displayed in setup menu (detail) */
+ int width; /* display width +/- for value alignment */
+ bool enabled; /* false == ignore this column (until enabled) */
+ Table* table; /* pointer to DynamicScreen or ProcessList */
} DynamicColumn;
Hashtable* DynamicColumns_new(void);
void DynamicColumns_delete(Hashtable* dynamics);
-const char* DynamicColumn_init(unsigned int key);
+const char* DynamicColumn_name(unsigned int key);
+
+void DynamicColumn_done(DynamicColumn* this);
const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key);
diff --git a/DynamicScreen.c b/DynamicScreen.c
new file mode 100644
index 00000000..35eb4ee6
--- /dev/null
+++ b/DynamicScreen.c
@@ -0,0 +1,65 @@
+/*
+htop - DynamicScreen.c
+(C) 2022 Sohaib Mohammed
+(C) 2022-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "DynamicScreen.h"
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "Hashtable.h"
+#include "Platform.h"
+#include "XUtils.h"
+
+
+Hashtable* DynamicScreens_new(void) {
+ return Platform_dynamicScreens();
+}
+
+void DynamicScreens_delete(Hashtable* screens) {
+ if (screens) {
+ Platform_dynamicScreensDone(screens);
+ Hashtable_delete(screens);
+ }
+}
+
+void DynamicScreen_done(DynamicScreen* this) {
+ free(this->caption);
+ free(this->fields);
+ free(this->heading);
+ free(this->sortKey);
+ free(this->columnKeys);
+}
+
+typedef struct {
+ ht_key_t key;
+ const char* name;
+ bool found;
+} DynamicIterator;
+
+static void DynamicScreen_compare(ht_key_t key, void* value, void* data) {
+ const DynamicScreen* screen = (const DynamicScreen*)value;
+ DynamicIterator* iter = (DynamicIterator*)data;
+ if (String_eq(iter->name, screen->name)) {
+ iter->found = true;
+ iter->key = key;
+ }
+}
+
+bool DynamicScreen_search(Hashtable* screens, const char* name, ht_key_t* key) {
+ DynamicIterator iter = { .key = 0, .name = name, .found = false };
+ if (screens)
+ Hashtable_foreach(screens, DynamicScreen_compare, &iter);
+ if (key)
+ *key = iter.key;
+ return iter.found;
+}
+
+const char* DynamicScreen_lookup(Hashtable* screens, ht_key_t key) {
+ const DynamicScreen* screen = Hashtable_get(screens, key);
+ return screen ? screen->name : NULL;
+}
diff --git a/DynamicScreen.h b/DynamicScreen.h
new file mode 100644
index 00000000..76b3d428
--- /dev/null
+++ b/DynamicScreen.h
@@ -0,0 +1,39 @@
+#ifndef HEADER_DynamicScreen
+#define HEADER_DynamicScreen
+/*
+htop - DynamicColumn.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include <stdbool.h>
+
+#include "Hashtable.h"
+#include "Panel.h"
+#include "Settings.h"
+
+
+typedef struct DynamicScreen_ {
+ char name[32]; /* unique name cannot contain any spaces */
+ char* heading; /* user-settable more readable name */
+ char* caption; /* explanatory text for screen */
+ char* fields;
+ char* sortKey;
+ char* columnKeys;
+ int direction;
+} DynamicScreen;
+
+Hashtable* DynamicScreens_new(void);
+
+void DynamicScreens_delete(Hashtable* dynamics);
+
+void DynamicScreen_done(DynamicScreen* this);
+
+void DynamicScreens_addAvailableColumns(Panel* availableColumns, char* screen);
+
+const char* DynamicScreen_lookup(Hashtable* screens, unsigned int key);
+
+bool DynamicScreen_search(Hashtable* screens, const char* name, unsigned int* key);
+
+#endif
diff --git a/Machine.c b/Machine.c
index 8846aed7..c7b98c9f 100644
--- a/Machine.c
+++ b/Machine.c
@@ -56,15 +56,15 @@ void Machine_done(Machine* this) {
hwloc_topology_destroy(this->topology);
}
#endif
- for (size_t i = 0; i < this->tableCount; i++) {
- Object_delete(&this->tables[i]->super);
- }
+ Object_delete(this->processTable);
+ free(this->tables);
}
-void Machine_addTable(Machine* this, Table* table, bool processes) {
- if (processes)
- this->processTable = table;
- this->activeTable = table;
+static void Machine_addTable(Machine* this, Table* table) {
+ /* check that this table has not been seen previously */
+ for (size_t i = 0; i < this->tableCount; i++)
+ if (this->tables[i] == table)
+ return;
size_t nmemb = this->tableCount + 1;
Table** tables = xReallocArray(this->tables, nmemb, sizeof(Table*));
@@ -73,6 +73,28 @@ void Machine_addTable(Machine* this, Table* table, bool processes) {
this->tableCount++;
}
+void Machine_populateTablesFromSettings(Machine* this, Settings* settings, Table* processTable) {
+ this->settings = settings;
+ this->processTable = processTable;
+
+ for (size_t i = 0; i < settings->nScreens; i++) {
+ ScreenSettings* ss = settings->screens[i];
+ Table* table = ss->table;
+ if (!table)
+ table = ss->table = processTable;
+ if (i == 0)
+ this->activeTable = table;
+
+ Machine_addTable(this, table);
+ }
+}
+
+void Machine_setTablesPanel(Machine* this, Panel* panel) {
+ for (size_t i = 0; i < this->tableCount; i++) {
+ Table_setPanel(this->tables[i], panel);
+ }
+}
+
void Machine_scanTables(Machine* this) {
// set scan timestamp
static bool firstScanDone = false;
diff --git a/Machine.h b/Machine.h
index a1c49e24..6c60050d 100644
--- a/Machine.h
+++ b/Machine.h
@@ -17,6 +17,7 @@ in the source distribution for its full text.
#include <sys/types.h>
#include "Hashtable.h"
+#include "Panel.h"
#include "Settings.h"
#include "Table.h"
#include "UsersTable.h"
@@ -38,8 +39,6 @@ in the source distribution for its full text.
typedef unsigned long long int memory_t;
#define MEMORY_MAX ULLONG_MAX
-struct Settings_;
-
typedef struct Machine_ {
struct Settings_* settings;
@@ -90,7 +89,9 @@ void Machine_done(Machine* this);
bool Machine_isCPUonline(const Machine* this, unsigned int id);
-void Machine_addTable(Machine* this, Table *table, bool processes);
+void Machine_populateTablesFromSettings(Machine* this, Settings* settings, Table* processTable);
+
+void Machine_setTablesPanel(Machine* host, Panel* panel);
void Machine_scan(Machine* this);
diff --git a/MainPanel.c b/MainPanel.c
index 54127fe9..7ca7b201 100644
--- a/MainPanel.c
+++ b/MainPanel.c
@@ -47,7 +47,7 @@ static void MainPanel_idSearch(MainPanel* this, int ch) {
}
static const char* MainPanel_getValue(Panel* this, int i) {
- const Row* row = (const Row*) Panel_get(this, i);
+ Row* row = (Row*) Panel_get(this, i);
return Row_sortKeyString(row);
}
@@ -78,7 +78,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
int x = EVENT_HEADER_CLICK_GET_X(ch);
int hx = super->scrollH + x + 1;
RowField field = RowField_keyAt(settings, hx);
- if (ss->treeView && ss->treeViewAlwaysByID) {
+ if (ss->treeView && ss->treeViewAlwaysByPID) {
ss->treeView = false;
ss->direction = 1;
reaction |= Action_setSortKey(settings, field);
@@ -91,7 +91,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
result = HANDLED;
} else if (EVENT_IS_SCREEN_TAB_CLICK(ch)) {
int x = EVENT_SCREEN_TAB_GET_X(ch);
- reaction |= Action_setScreenTab(settings, x);
+ reaction |= Action_setScreenTab(this->state, x);
result = HANDLED;
} else if (ch != ERR && this->inc->active) {
bool filterChanged = IncSet_handleKey(this->inc, ch, super, MainPanel_getValue, NULL);
@@ -208,9 +208,12 @@ const PanelClass MainPanel_class = {
MainPanel* MainPanel_new(void) {
MainPanel* this = AllocThis(MainPanel);
- Panel_init((Panel*) this, 1, 1, 1, 1, Class(Row), false, FunctionBar_new(Settings_isReadonly() ? MainFunctions_ro : MainFunctions, NULL, NULL));
+ this->processBar = FunctionBar_new(MainFunctions, NULL, NULL);
+ this->readonlyBar = FunctionBar_new(MainFunctions_ro, NULL, NULL);
+ FunctionBar* activeBar = Settings_isReadonly() ? this->readonlyBar : this->processBar;
+ Panel_init((Panel*) this, 1, 1, 1, 1, Class(Row), false, activeBar);
this->keys = xCalloc(KEY_MAX, sizeof(Htop_Action));
- this->inc = IncSet_new(MainPanel_getFunctionBar(this));
+ this->inc = IncSet_new(activeBar);
Action_setBindings(this->keys);
Platform_setBindings(this->keys);
@@ -222,9 +225,16 @@ void MainPanel_setState(MainPanel* this, State* state) {
this->state = state;
}
+void MainPanel_setFunctionBar(MainPanel* this, bool readonly) {
+ this->super.defaultBar = readonly ? this->readonlyBar : this->processBar;
+ this->inc->defaultBar = this->super.defaultBar;
+}
+
void MainPanel_delete(Object* object) {
Panel* super = (Panel*) object;
MainPanel* this = (MainPanel*) object;
+ MainPanel_setFunctionBar(this, false);
+ FunctionBar_delete(this->readonlyBar);
Panel_done(super);
IncSet_delete(this->inc);
free(this->keys);
diff --git a/MainPanel.h b/MainPanel.h
index d062616d..19229d59 100644
--- a/MainPanel.h
+++ b/MainPanel.h
@@ -25,6 +25,8 @@ typedef struct MainPanel_ {
State* state;
IncSet* inc;
Htop_Action* keys;
+ FunctionBar* processBar; /* function bar with process-specific actions */
+ FunctionBar* readonlyBar; /* function bar without process actions (ro) */
unsigned int idSearch;
} MainPanel;
@@ -45,6 +47,8 @@ MainPanel* MainPanel_new(void);
void MainPanel_setState(MainPanel* this, State* state);
+void MainPanel_setFunctionBar(MainPanel* this, bool readonly);
+
void MainPanel_delete(Object* object);
#endif
diff --git a/Makefile.am b/Makefile.am
index a05c7ea9..b7d3cca3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,7 @@ myhtopsources = \
DisplayOptionsPanel.c \
DynamicColumn.c \
DynamicMeter.c \
+ DynamicScreen.c \
EnvScreen.c \
FileDescriptorMeter.c \
FunctionBar.c \
@@ -79,6 +80,7 @@ myhtopsources = \
Scheduling.c \
ScreenManager.c \
ScreensPanel.c \
+ ScreenTabsPanel.c \
Settings.c \
SignalsPanel.c \
SwapMeter.c \
@@ -113,6 +115,7 @@ myhtopheaders = \
DisplayOptionsPanel.h \
DynamicColumn.h \
DynamicMeter.h \
+ DynamicScreen.h \
EnvScreen.h \
FileDescriptorMeter.h \
FunctionBar.h \
@@ -148,6 +151,7 @@ myhtopheaders = \
Scheduling.h \
ScreenManager.h \
ScreensPanel.h \
+ ScreenTabsPanel.h \
Settings.h \
SignalsPanel.h \
SwapMeter.h \
@@ -408,11 +412,15 @@ endif
# --------------------------
pcp_platform_headers = \
+ linux/CGroupUtils.h \
linux/PressureStallMeter.h \
linux/ZramMeter.h \
linux/ZramStats.h \
pcp/PCPDynamicColumn.h \
pcp/PCPDynamicMeter.h \
+ pcp/PCPDynamicScreen.h \
+ pcp/Instance.h \
+ pcp/InDomTable.h \
pcp/PCPMachine.h \
pcp/PCPMetric.h \
pcp/PCPProcess.h \
@@ -424,10 +432,14 @@ pcp_platform_headers = \
zfs/ZfsCompressedArcMeter.h
pcp_platform_sources = \
+ linux/CGroupUtils.c \
linux/PressureStallMeter.c \
linux/ZramMeter.c \
pcp/PCPDynamicColumn.c \
pcp/PCPDynamicMeter.c \
+ pcp/PCPDynamicScreen.c \
+ pcp/Instance.c \
+ pcp/InDomTable.c \
pcp/PCPMachine.c \
pcp/PCPMetric.c \
pcp/PCPProcess.c \
diff --git a/Process.c b/Process.c
index 6f74e014..6c4fb7ad 100644
--- a/Process.c
+++ b/Process.c
@@ -758,7 +758,7 @@ void Process_writeField(const Process* this, RichString* str, RowField field) {
}
void Process_done(Process* this) {
- assert (this != NULL);
+ assert(this != NULL);
free(this->cmdline);
free(this->procComm);
free(this->procExe);
@@ -784,7 +784,7 @@ static const char* Process_getSortKey(const Process* this) {
return Process_getCommand(this);
}
-const char* Process_rowGetSortKey(const Row* super) {
+const char* Process_rowGetSortKey(Row* super) {
const Process* this = (const Process*) super;
assert(Object_isA((const Object*) this, (const ObjectClass*) &Process_class));
return Process_getSortKey(this);
diff --git a/Process.h b/Process.h
index c6cdb995..92908155 100644
--- a/Process.h
+++ b/Process.h
@@ -290,7 +290,7 @@ extern const ProcessClass Process_class;
void Process_init(Process* this, const struct Machine_* host);
-const char* Process_rowGetSortKey(const Row* super);
+const char* Process_rowGetSortKey(Row* super);
bool Process_rowSetPriority(Row* super, int priority);
diff --git a/Row.c b/Row.c
index 09a32069..67893d39 100644
--- a/Row.c
+++ b/Row.c
@@ -40,6 +40,11 @@ void Row_init(Row* this, const Machine* host) {
this->updated = false;
}
+void Row_done(Row* this) {
+ assert(this != NULL);
+ (void) this;
+}
+
static inline bool Row_isNew(const Row* this) {
const Machine* host = this->host;
if (host->monotonicMs < this->seenStampMs)
@@ -56,7 +61,7 @@ static inline bool Row_isTomb(const Row* this) {
void Row_display(const Object* cast, RichString* out) {
const Row* this = (const Row*) cast;
const Settings* settings = this->host->settings;
- const ProcessField* fields = settings->ss->fields;
+ const RowField* fields = settings->ss->fields;
for (int i = 0; fields[i]; i++)
As_Row(this)->writeField(this, out, fields[i]);
@@ -127,7 +132,7 @@ static const char* alignedTitleDynamicColumn(const Settings* settings, int key,
if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
- xSnprintf(titleBuffer, titleBufferSize, "%*s", width, column->heading);
+ xSnprintf(titleBuffer, titleBufferSize, "%*s ", width, column->heading);
return titleBuffer;
}
@@ -430,7 +435,7 @@ void Row_printLeftAlignedField(RichString* str, int attr, const char* content, u
RichString_appendChr(str, attr, ' ', width + 1 - columns);
}
-void Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr) {
+int Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr) {
if (isNonnegative(val)) {
if (val < 0.05F)
*attr = CRT_colors[PROCESS_SHADOW];
@@ -445,11 +450,11 @@ void Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int*
val = 100.0F;
}
- xSnprintf(buffer, n, "%*.*f ", width, precision, val);
- } else {
- *attr = CRT_colors[PROCESS_SHADOW];
- xSnprintf(buffer, n, "%*.*s ", width, width, "N/A");
+ return xSnprintf(buffer, n, "%*.*f ", width, precision, val);
}
+
+ *attr = CRT_colors[PROCESS_SHADOW];
+ return xSnprintf(buffer, n, "%*.*s ", width, width, "N/A");
}
void Row_toggleTag(Row* this) {
diff --git a/Row.h b/Row.h
index 5cdb3fe7..c3ae56f0 100644
--- a/Row.h
+++ b/Row.h
@@ -81,7 +81,7 @@ typedef void (*Row_WriteField)(const Row*, RichString*, RowField);
typedef bool (*Row_IsHighlighted)(const Row*);
typedef bool (*Row_IsVisible)(const Row*, const struct Table_*);
typedef bool (*Row_MatchesFilter)(const Row*, const struct Table_*);
-typedef const char* (*Row_SortKeyString)(const Row*);
+typedef const char* (*Row_SortKeyString)(Row*);
typedef int (*Row_CompareByParent)(const Row*, const Row*);
int Row_compare(const void* v1, const void* v2);
@@ -120,6 +120,8 @@ extern const RowClass Row_class;
void Row_init(Row* this, const struct Machine_* host);
+void Row_done(Row* this);
+
void Row_display(const Object* cast, RichString* out);
void Row_toggleTag(Row* this);
@@ -155,7 +157,7 @@ void Row_printTime(RichString* str, unsigned long long totalHundredths, bool col
/* Takes rate in bare unit (base 1024) per second. Prints 12 columns. */
void Row_printRate(RichString* str, double rate, bool coloring);
-void Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr);
+int Row_printPercentage(float val, char* buffer, size_t n, uint8_t width, int* attr);
void Row_display(const Object* cast, RichString* out);
diff --git a/ScreenManager.c b/ScreenManager.c
index e39c4f06..6c1dd12e 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -193,7 +193,7 @@ static void ScreenManager_drawScreenTabs(ScreenManager* this) {
}
for (int s = 0; screens[s]; s++) {
- bool ok = drawTab(&y, &x, l, screens[s]->name, s == cur);
+ bool ok = drawTab(&y, &x, l, screens[s]->heading, s == cur);
if (!ok) {
break;
}
diff --git a/ScreenTabsPanel.c b/ScreenTabsPanel.c
new file mode 100644
index 00000000..f61745e0
--- /dev/null
+++ b/ScreenTabsPanel.c
@@ -0,0 +1,372 @@
+/*
+htop - ScreenTabsPanel.c
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "ScreenTabsPanel.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "CRT.h"
+#include "FunctionBar.h"
+#include "Hashtable.h"
+#include "ProvideCurses.h"
+#include "Settings.h"
+#include "XUtils.h"
+
+
+static HandlerResult ScreenNamesPanel_eventHandlerNormal(Panel* super, int ch);
+
+ObjectClass ScreenTabListItem_class = {
+ .extends = Class(ListItem),
+ .display = ListItem_display,
+ .delete = ListItem_delete,
+ .compare = ListItem_compare
+};
+
+static void ScreenNamesPanel_fill(ScreenNamesPanel* this, DynamicScreen* ds) {
+ const Settings* settings = this->settings;
+ Panel* super = (Panel*) this;
+ Panel_prune(super);
+
+ for (unsigned int i = 0; i < settings->nScreens; i++) {
+ const ScreenSettings* ss = settings->screens[i];
+
+ if (ds == NULL) {
+ if (ss->dynamic != NULL)
+ continue;
+ /* built-in (processes, not dynamic) - e.g. Main or I/O */
+ } else {
+ if (ss->dynamic == NULL)
+ continue;
+ if (!String_eq(ds->name, ss->dynamic))
+ continue;
+ /* matching dynamic screen found, add it into the Panel */
+ }
+ Panel_add(super, (Object*) ListItem_new(ss->heading, i));
+ }
+
+ this->ds = ds;
+}
+
+static void ScreenTabsPanel_delete(Object* object) {
+ Panel* super = (Panel*) object;
+ ScreenTabsPanel* this = (ScreenTabsPanel*) object;
+
+ Panel_done(super);
+ free(this);
+}
+
+static HandlerResult ScreenTabsPanel_eventHandler(Panel* super, int ch) {
+ ScreenTabsPanel* const this = (ScreenTabsPanel* const) super;
+
+ HandlerResult result = IGNORED;
+
+ int selected = Panel_getSelectedIndex(super);
+ switch (ch) {
+ case EVENT_SET_SELECTED:
+ result = HANDLED;
+ break;
+ case KEY_F(5):
+ case KEY_CTRL('N'):
+ /* pass onto the Names panel for creating new screen */
+ return ScreenNamesPanel_eventHandlerNormal(&this->names->super, ch);
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_NPAGE:
+ case KEY_PPAGE:
+ case KEY_HOME:
+ case KEY_END: {
+ int previous = selected;
+ Panel_onKey(super, ch);
+ selected = Panel_getSelectedIndex(super);
+ if (previous != selected)
+ result = HANDLED;
+ break;
+ }
+ default:
+ {
+ if (ch < 255 && isalpha(ch))
+ result = Panel_selectByTyping(super, ch);
+ if (result == BREAK_LOOP)
+ result = IGNORED;
+ break;
+ }
+ }
+ if (result == HANDLED) {
+ ScreenTabListItem* focus = (ScreenTabListItem*) Panel_getSelected(super);
+ ScreenNamesPanel_fill(this->names, focus->ds);
+ }
+ return result;
+}
+
+PanelClass ScreenTabsPanel_class = {
+ .super = {
+ .extends = Class(Panel),
+ .delete = ScreenTabsPanel_delete,
+ },
+ .eventHandler = ScreenTabsPanel_eventHandler
+};
+
+static ScreenTabListItem* ScreenTabListItem_new(const char* value, DynamicScreen* ds) {
+ ScreenTabListItem* this = AllocThis(ScreenTabListItem);
+ ListItem_init((ListItem*)this, value, 0);
+ this->ds = ds;
+ return this;
+}
+
+static void addDynamicScreen(ATTR_UNUSED ht_key_t key, void* value, void* userdata) {
+ DynamicScreen* screen = (DynamicScreen*) value;
+ Panel* super = (Panel*) userdata;
+ const char* name = screen->heading ? screen->heading : screen->name;
+
+ Panel_add(super, (Object*) ScreenTabListItem_new(name, screen));
+}
+
+static const char* const ScreenTabsFunctions[] = {" ", " ", " ", " ", "New ", " ", " ", " ", " ", "Done ", NULL};
+
+ScreenTabsPanel* ScreenTabsPanel_new(Settings* settings) {
+ ScreenTabsPanel* this = AllocThis(ScreenTabsPanel);
+ Panel* super = (Panel*) this;
+ FunctionBar* fuBar = FunctionBar_new(ScreenTabsFunctions, NULL, NULL);
+ Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
+
+ this->settings = settings;
+ this->names = ScreenNamesPanel_new(settings);
+ super->cursorOn = false;
+ this->cursor = 0;
+ Panel_setHeader(super, "Screen tabs");
+
+ assert(settings->dynamicScreens != NULL);
+ Panel_add(super, (Object*) ScreenTabListItem_new("Processes", NULL));
+ Hashtable_foreach(settings->dynamicScreens, addDynamicScreen, super);
+
+ return this;
+}
+
+// -------------
+
+ObjectClass ScreenNameListItem_class = {
+ .extends = Class(ListItem),
+ .display = ListItem_display,
+ .delete = ListItem_delete,
+ .compare = ListItem_compare
+};
+
+ScreenNameListItem* ScreenNameListItem_new(const char* value, ScreenSettings* ss) {
+ ScreenNameListItem* this = AllocThis(ScreenNameListItem);
+ ListItem_init((ListItem*)this, value, 0);
+ this->ss = ss;
+ return this;
+}
+
+static const char* const ScreenNamesFunctions[] = {" ", " ", " ", " ", "New ", " ", " ", " ", " ", "Done ", NULL};
+
+static void ScreenNamesPanel_delete(Object* object) {
+ Panel* super = (Panel*) object;
+ ScreenNamesPanel* this = (ScreenNamesPanel*) object;
+
+ /* do not delete screen settings still in use */
+ int n = Panel_size(super);
+ for (int i = 0; i < n; i++) {
+ ScreenNameListItem* item = (ScreenNameListItem*) Panel_get(super, i);
+ item->ss = NULL;
+ }
+
+ /* during renaming the ListItem's value points to our static buffer */
+ if (this->renamingItem)
+ this->renamingItem->value = this->saved;
+
+ Panel_done(super);
+ free(this);
+}
+
+static void renameScreenSettings(ScreenNamesPanel* this, const ListItem* item) {
+ const ScreenNameListItem* nameItem = (const ScreenNameListItem*) item;
+
+ ScreenSettings* ss = nameItem->ss;
+ free_and_xStrdup(&ss->heading, item->value);
+
+ Settings* settings = this->settings;
+ settings->changed = true;
+ settings->lastUpdate++;
+}
+
+static HandlerResult ScreenNamesPanel_eventHandlerRenaming(Panel* super, int ch) {
+ ScreenNamesPanel* const this = (ScreenNamesPanel*) super;
+
+ if (ch >= 32 && ch < 127 && ch != '=') {
+ if (this->cursor < SCREEN_NAME_LEN - 1) {
+ this->buffer[this->cursor] = (char)ch;
+ this->cursor++;
+ super->selectedLen = strlen(this->buffer);
+ Panel_setCursorToSelection(super);
+ }
+ } else {
+ switch (ch) {
+ case 127:
+ case KEY_BACKSPACE:
+ {
+ if (this->cursor > 0) {
+ this->cursor--;
+ this->buffer[this->cursor] = '\0';
+ super->selectedLen = strlen(this->buffer);
+ Panel_setCursorToSelection(super);
+ }
+ break;
+ }
+ case '\n':
+ case '\r':
+ case KEY_ENTER:
+ {
+ ListItem* item = (ListItem*) Panel_getSelected(super);
+ if (!item)
+ break;
+ assert(item == this->renamingItem);
+ free(this->saved);
+ item->value = xStrdup(this->buffer);
+ this->renamingItem = NULL;
+ super->cursorOn = false;
+ Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
+ renameScreenSettings(this, item);
+ break;
+ }
+ case 27: // Esc
+ {
+ ListItem* item = (ListItem*) Panel_getSelected(super);
+ if (!item)
+ break;
+ assert(item == this->renamingItem);
+ item->value = this->saved;
+ this->renamingItem = NULL;
+ super->cursorOn = false;
+ Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
+ break;
+ }
+ }
+ }
+ return HANDLED;
+}
+
+static void startRenaming(Panel* super) {
+ ScreenNamesPanel* const this = (ScreenNamesPanel*) super;
+
+ ListItem* item = (ListItem*) Panel_getSelected(super);
+ if (item == NULL)
+ return;
+ this->renamingItem = item;
+ super->cursorOn = true;
+ char* name = item->value;
+ this->saved = name;
+ strncpy(this->buffer, name, SCREEN_NAME_LEN);
+ this->buffer[SCREEN_NAME_LEN] = '\0';
+ this->cursor = strlen(this->buffer);
+ item->value = this->buffer;
+ Panel_setSelectionColor(super, PANEL_EDIT);
+ super->selectedLen = strlen(this->buffer);
+ Panel_setCursorToSelection(super);
+}
+
+static void addNewScreen(Panel* super, DynamicScreen* ds) {
+ ScreenNamesPanel* const this = (ScreenNamesPanel*) super;
+ const char* name = "New";
+ ScreenSettings* ss = (ds != NULL) ? Settings_newDynamicScreen(this->settings, name, ds, NULL) : Settings_newScreen(this->settings, &(const ScreenDefaults) { .name = name, .columns = "PID Command", .sortKey = "PID" });
+ ScreenNameListItem* item = ScreenNameListItem_new(name, ss);
+ int idx = Panel_getSelectedIndex(super);
+ Panel_insert(super, idx + 1, (Object*) item);
+ Panel_setSelected(super, idx + 1);
+}
+
+static HandlerResult ScreenNamesPanel_eventHandlerNormal(Panel* super, int ch) {
+ ScreenNamesPanel* const this = (ScreenNamesPanel*) super;
+ ScreenNameListItem* oldFocus = (ScreenNameListItem*) Panel_getSelected(super);
+ HandlerResult result = IGNORED;
+ switch (ch) {
+ case '\n':
+ case '\r':
+ case KEY_ENTER:
+ case KEY_MOUSE:
+ case KEY_RECLICK:
+ {
+ Panel_setSelectionColor(super, PANEL_SELECTION_FOCUS);
+ result = HANDLED;
+ break;
+ }
+ case EVENT_SET_SELECTED:
+ result = HANDLED;
+ break;
+ case KEY_NPAGE:
+ case KEY_PPAGE:
+ case KEY_HOME:
+ case KEY_END:
+ {
+ Panel_onKey(super, ch);
+ break;
+ }
+ case KEY_F(5):
+ case KEY_CTRL('N'):
+ {
+ addNewScreen(super, this->ds);
+ startRenaming(super);
+ result = HANDLED;
+ break;
+ }
+ default:
+ {
+ if (ch < 255 && isalpha(ch))
+ result = Panel_selectByTyping(super, ch);
+ if (result == BREAK_LOOP)
+ result = IGNORED;
+ break;
+ }
+ }
+ ScreenNameListItem* newFocus = (ScreenNameListItem*) Panel_getSelected(super);
+ if (newFocus && oldFocus != newFocus)
+ result = HANDLED;
+ return result;
+}
+
+static HandlerResult ScreenNamesPanel_eventHandler(Panel* super, int ch) {
+ ScreenNamesPanel* const this = (ScreenNamesPanel*) super;
+
+ if (!this->renamingItem)
+ return ScreenNamesPanel_eventHandlerNormal(super, ch);
+ return ScreenNamesPanel_eventHandlerRenaming(super, ch);
+}
+
+PanelClass ScreenNamesPanel_class = {
+ .super = {
+ .extends = Class(Panel),
+ .delete = ScreenNamesPanel_delete
+ },
+ .eventHandler = ScreenNamesPanel_eventHandler
+};
+
+ScreenNamesPanel* ScreenNamesPanel_new(Settings* settings) {
+ ScreenNamesPanel* this = AllocThis(ScreenNamesPanel);
+ Panel* super = (Panel*) this;
+ FunctionBar* fuBar = FunctionBar_new(ScreenNamesFunctions, NULL, NULL);
+ Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
+
+ this->settings = settings;
+ this->renamingItem = NULL;
+ memset(this->buffer, 0, sizeof(this->buffer));
+ this->ds = NULL;
+ this->saved = NULL;
+ this->cursor = 0;
+ super->cursorOn = false;
+ Panel_setHeader(super, "Screens");
+
+ for (unsigned int i = 0; i < settings->nScreens; i++) {
+ ScreenSettings* ss = settings->screens[i];
+ /* initially show only for Processes tabs (selected) */
+ if (ss->dynamic)
+ continue;
+ Panel_add(super, (Object*) ScreenNameListItem_new(ss->heading, ss));
+ }
+ return this;
+}
diff --git a/ScreenTabsPanel.h b/ScreenTabsPanel.h
new file mode 100644
index 00000000..3b89ffc2
--- /dev/null
+++ b/ScreenTabsPanel.h
@@ -0,0 +1,60 @@
+#ifndef HEADER_ScreenTabsPanel
+#define HEADER_ScreenTabsPanel
+/*
+htop - ScreenTabsPanel.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "DynamicScreen.h"
+#include "ListItem.h"
+#include "Panel.h"
+#include "ScreensPanel.h"
+#include "ScreenManager.h"
+#include "Settings.h"
+
+
+typedef struct ScreenNamesPanel_ {
+ Panel super;
+
+ ScreenManager* scr;
+ Settings* settings;
+ char buffer[SCREEN_NAME_LEN + 1];
+ DynamicScreen* ds;
+ char* saved;
+ int cursor;
+ ListItem* renamingItem;
+} ScreenNamesPanel;
+
+typedef struct ScreenNameListItem_ {
+ ListItem super;
+ ScreenSettings* ss;
+} ScreenNameListItem;
+
+typedef struct ScreenTabsPanel_ {
+ Panel super;
+
+ ScreenManager* scr;
+ Settings* settings;
+ ScreenNamesPanel* names;
+ int cursor;
+} ScreenTabsPanel;
+
+typedef struct ScreenTabListItem_ {
+ ListItem super;
+ DynamicScreen* ds;
+} ScreenTabListItem;
+
+
+ScreenTabsPanel* ScreenTabsPanel_new(Settings* settings);
+
+extern ObjectClass ScreenNameListItem_class;
+
+ScreenNameListItem* ScreenNameListItem_new(const char* value, ScreenSettings* ss);
+
+extern PanelClass ScreenNamesPanel_class;
+
+ScreenNamesPanel* ScreenNamesPanel_new(Settings* settings);
+
+#endif
diff --git a/ScreensPanel.c b/ScreensPanel.c
index cb664ac4..d0038809 100644
--- a/ScreensPanel.c
+++ b/ScreensPanel.c
@@ -1,7 +1,7 @@
/*
htop - ScreensPanel.c
(C) 2004-2011 Hisham H. Muhammad
-(C) 2020-2022 htop dev team
+(C) 2020-2023 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include <ctype.h>
#include <string.h>
+#include "AvailableColumnsPanel.h"
#include "CRT.h"
#include "FunctionBar.h"
#include "Hashtable.h"
@@ -43,6 +44,7 @@ ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss) {
}
static const char* const ScreensFunctions[] = {" ", "Rename", " ", " ", "New ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
+static const char* const DynamicFunctions[] = {" ", "Rename", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
static void ScreensPanel_delete(Object* object) {
Panel* super = (Panel*) object;
@@ -55,11 +57,6 @@ static void ScreensPanel_delete(Object* object) {
item->ss = NULL;
}
- /* during renaming the ListItem's value points to our static buffer */
- if (this->renamingItem)
- this->renamingItem->value = this->saved;
-
- Panel_done(super);
free(this);
}
@@ -212,6 +209,8 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
case KEY_F(5):
case KEY_CTRL('N'):
{
+ if (this->settings->dynamicScreens)
+ break;
addNewScreen(super);
startRenaming(super);
shouldRebuildArray = true;
@@ -272,7 +271,9 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
}
ScreenListItem* newFocus = (ScreenListItem*) Panel_getSelected(super);
if (newFocus && oldFocus != newFocus) {
- ColumnsPanel_fill(this->columns, newFocus->ss, this->settings->dynamicColumns);
+ Hashtable* dynamicColumns = this->settings->dynamicColumns;
+ ColumnsPanel_fill(this->columns, newFocus->ss, dynamicColumns);
+ AvailableColumnsPanel_fill(this->availableColumns, newFocus->ss->dynamic, dynamicColumns);
result = HANDLED;
}
if (shouldRebuildArray)
@@ -304,11 +305,12 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
ScreensPanel* this = AllocThis(ScreensPanel);
Panel* super = (Panel*) this;
Hashtable* columns = settings->dynamicColumns;
- FunctionBar* fuBar = FunctionBar_new(ScreensFunctions, NULL, NULL);
+ FunctionBar* fuBar = FunctionBar_new(settings->dynamicScreens ? DynamicFunctions : ScreensFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
this->settings = settings;
this->columns = ColumnsPanel_new(settings->screens[0], columns, &(settings->changed));
+ this->availableColumns = AvailableColumnsPanel_new((Panel*) this->columns, columns);
this->moving = false;
this->renamingItem = NULL;
super->cursorOn = false;
@@ -317,7 +319,7 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
for (unsigned int i = 0; i < settings->nScreens; i++) {
ScreenSettings* ss = settings->screens[i];
- char* name = ss->name;
+ char* name = ss->heading;
Panel_add(super, (Object*) ScreenListItem_new(name, ss));
}
return this;
@@ -332,9 +334,8 @@ void ScreensPanel_update(Panel* super) {
for (int i = 0; i < size; i++) {
ScreenListItem* item = (ScreenListItem*) Panel_get(super, i);
ScreenSettings* ss = item->ss;
- free(ss->name);
+ free_and_xStrdup(&ss->heading, ((ListItem*) item)->value);
this->settings->screens[i] = ss;
- ss->name = xStrdup(((ListItem*) item)->value);
}
this->settings->screens[size] = NULL;
}
diff --git a/ScreensPanel.h b/ScreensPanel.h
index 60aaf2a2..0be0b824 100644
--- a/ScreensPanel.h
+++ b/ScreensPanel.h
@@ -10,7 +10,9 @@ in the source distribution for its full text.
#include <stdbool.h>
+#include "AvailableColumnsPanel.h"
#include "ColumnsPanel.h"
+#include "DynamicScreen.h"
#include "ListItem.h"
#include "Object.h"
#include "Panel.h"
@@ -27,6 +29,7 @@ typedef struct ScreensPanel_ {
ScreenManager* scr;
Settings* settings;
ColumnsPanel* columns;
+ AvailableColumnsPanel* availableColumns;
char buffer[SCREEN_NAME_LEN + 1];
char* saved;
int cursor;
@@ -36,6 +39,7 @@ typedef struct ScreensPanel_ {
typedef struct ScreenListItem_ {
ListItem super;
+ DynamicScreen* ds;
ScreenSettings* ss;
} ScreenListItem;
@@ -44,8 +48,6 @@ extern ObjectClass ScreenListItem_class;
ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss);
-extern PanelClass ScreensPanel_class;
-
ScreensPanel* ScreensPanel_new(Settings* settings);
void ScreensPanel_update(Panel* super);
diff --git a/Settings.c b/Settings.c
index b772f091..5265ce4d 100644
--- a/Settings.c
+++ b/Settings.c
@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "CRT.h"
#include "DynamicColumn.h"
+#include "DynamicScreen.h"
#include "Macros.h"
#include "Meter.h"
#include "Platform.h"
@@ -203,13 +204,25 @@ static void Settings_defaultMeters(Settings* this, unsigned int initialCpuCount)
this->hColumns[1].modes[r++] = TEXT_METERMODE;
}
-static const char* toFieldName(Hashtable* columns, int id) {
- if (id < 0)
+static const char* toFieldName(Hashtable* columns, int id, bool* enabled) {
+ if (id < 0) {
+ if (enabled)
+ *enabled = false;
return NULL;
+ }
if (id >= ROW_DYNAMIC_FIELDS) {
const DynamicColumn* column = DynamicColumn_lookup(columns, id);
+ if (!column) {
+ if (enabled)
+ *enabled = false;
+ return NULL;
+ }
+ if (enabled)
+ *enabled = column->enabled;
return column->name;
}
+ if (enabled)
+ *enabled = true;
return Process_fields[id].name;
}
@@ -217,7 +230,7 @@ static int toFieldIndex(Hashtable* columns, const char* str) {
if (isdigit(str[0])) {
// This "+1" is for compatibility with the older enum format.
int id = atoi(str) + 1;
- if (toFieldName(columns, id)) {
+ if (toFieldName(columns, id, NULL)) {
return id;
}
} else {
@@ -237,7 +250,7 @@ static int toFieldIndex(Hashtable* columns, const char* str) {
}
// Fallback to iterative scan of table of fields by-name.
for (int p = 1; p < LAST_PROCESSFIELD; p++) {
- const char* pName = toFieldName(columns, p);
+ const char* pName = toFieldName(columns, p, NULL);
if (pName && strcmp(pName, str) == 0)
return p;
}
@@ -269,34 +282,57 @@ static void ScreenSettings_readFields(ScreenSettings* ss, Hashtable* columns, co
String_freeArray(ids);
}
+static ScreenSettings* Settings_initScreenSettings(ScreenSettings* ss, Settings* this, const char *columns) {
+ ScreenSettings_readFields(ss, this->dynamicColumns, columns);
+ this->screens[this->nScreens] = ss;
+ this->nScreens++;
+ this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1));
+ this->screens[this->nScreens] = NULL;
+ return ss;
+}
+
ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults) {
int sortKey = defaults->sortKey ? toFieldIndex(this->dynamicColumns, defaults->sortKey) : PID;
+ int treeSortKey = defaults->treeSortKey ? toFieldIndex(this->dynamicColumns, defaults->treeSortKey) : PID;
int sortDesc = (sortKey >= 0 && sortKey < LAST_PROCESSFIELD) ? Process_fields[sortKey].defaultSortDesc : 1;
ScreenSettings* ss = xMalloc(sizeof(ScreenSettings));
*ss = (ScreenSettings) {
- .name = xStrdup(defaults->name),
+ .heading = xStrdup(defaults->name),
+ .dynamic = NULL,
+ .table = NULL,
.fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)),
.flags = 0,
.direction = sortDesc ? -1 : 1,
.treeDirection = 1,
.sortKey = sortKey,
- .treeSortKey = PID,
+ .treeSortKey = treeSortKey,
.treeView = false,
- .treeViewAlwaysByID = false,
+ .treeViewAlwaysByPID = false,
.allBranchesCollapsed = false,
};
+ return Settings_initScreenSettings(ss, this, defaults->columns);
+}
- ScreenSettings_readFields(ss, this->dynamicColumns, defaults->columns);
- this->screens[this->nScreens] = ss;
- this->nScreens++;
- this->screens = xRealloc(this->screens, sizeof(ScreenSettings*) * (this->nScreens + 1));
- this->screens[this->nScreens] = NULL;
- return ss;
+ScreenSettings* Settings_newDynamicScreen(Settings* this, const char* tab, const DynamicScreen* screen, Table* table) {
+ int sortKey = toFieldIndex(this->dynamicColumns, screen->columnKeys);
+
+ ScreenSettings* ss = xMalloc(sizeof(ScreenSettings));
+ *ss = (ScreenSettings) {
+ .heading = xStrdup(tab),
+ .dynamic = xStrdup(screen->name),
+ .table = table,
+ .fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)),
+ .direction = screen->direction,
+ .treeDirection = 1,
+ .sortKey = sortKey,
+ };
+ return Settings_initScreenSettings(ss, this, screen->columnKeys);
}
void ScreenSettings_delete(ScreenSettings* this) {
- free(this->name);
+ free(this->heading);
+ free(this->dynamic);
free(this->fields);
free(this);
}
@@ -308,6 +344,7 @@ static ScreenSettings* Settings_defaultScreens(Settings* this) {
const ScreenDefaults* defaults = &Platform_defaultScreens[i];
Settings_newScreen(this, defaults);
}
+ Platform_defaultDynamicScreens(this);
return this->screens[0];
}
@@ -372,7 +409,7 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
} else if (String_eq(option[0], "tree_view_always_by_pid") && this->config_version <= 2) {
// old (no screen) naming also supported for backwards compatibility
screen = Settings_defaultScreens(this);
- screen->treeViewAlwaysByID = atoi(option[1]);
+ screen->treeViewAlwaysByPID = atoi(option[1]);
} else if (String_eq(option[0], "all_branches_collapsed") && this->config_version <= 2) {
// old (no screen) naming also supported for backwards compatibility
screen = Settings_defaultScreens(this);
@@ -501,10 +538,14 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
screen->treeView = atoi(option[1]);
} else if (String_eq(option[0], ".tree_view_always_by_pid")) {
if (screen)
- screen->treeViewAlwaysByID = atoi(option[1]);
+ screen->treeViewAlwaysByPID = atoi(option[1]);
} else if (String_eq(option[0], ".all_branches_collapsed")) {
if (screen)
screen->allBranchesCollapsed = atoi(option[1]);
+ } else if (String_eq(option[0], ".dynamic")) {
+ if (screen)
+ free_and_xStrdup(&screen->dynamic, option[1]);
+ Platform_addDynamicScreen(screen);
}
String_freeArray(option);
}
@@ -520,11 +561,13 @@ static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns
const char* sep = "";
for (unsigned int i = 0; fields[i]; i++) {
if (fields[i] < LAST_PROCESSFIELD && byName) {
- const char* pName = toFieldName(columns, fields[i]);
+ const char* pName = toFieldName(columns, fields[i], NULL);
fprintf(fd, "%s%s", sep, pName);
} else if (fields[i] >= LAST_PROCESSFIELD && byName) {
- const char* pName = toFieldName(columns, fields[i]);
- fprintf(fd, " Dynamic(%s)", pName);
+ bool enabled;
+ const char* pName = toFieldName(columns, fields[i], &enabled);
+ if (enabled)
+ fprintf(fd, "%sDynamic(%s)", sep, pName);
} else {
// This "-1" is for compatibility with the older enum format.
fprintf(fd, "%s%d", sep, (int) fields[i] - 1);
@@ -634,17 +677,28 @@ int Settings_write(const Settings* this, bool onCrash) {
printSettingInteger("tree_sort_key", this->screens[0]->treeSortKey - 1);
printSettingInteger("sort_direction", this->screens[0]->direction);
printSettingInteger("tree_sort_direction", this->screens[0]->treeDirection);
- printSettingInteger("tree_view_always_by_pid", this->screens[0]->treeViewAlwaysByID);
+ printSettingInteger("tree_view_always_by_pid", this->screens[0]->treeViewAlwaysByPID);
printSettingInteger("all_branches_collapsed", this->screens[0]->allBranchesCollapsed);
for (unsigned int i = 0; i < this->nScreens; i++) {
ScreenSettings* ss = this->screens[i];
- fprintf(fd, "screen:%s=", ss->name);
+ const char* sortKey = toFieldName(this->dynamicColumns, ss->sortKey, NULL);
+ const char* treeSortKey = toFieldName(this->dynamicColumns, ss->treeSortKey, NULL);
+
+ fprintf(fd, "screen:%s=", ss->heading);
writeFields(fd, ss->fields, this->dynamicColumns, true, separator);
- printSettingString(".sort_key", toFieldName(this->dynamicColumns, ss->sortKey));
- printSettingString(".tree_sort_key", toFieldName(this->dynamicColumns, ss->treeSortKey));
+ if (ss->dynamic) {
+ printSettingString(".dynamic", ss->dynamic);
+ if (ss->sortKey && ss->sortKey != PID)
+ fprintf(fd, "%s=Dynamic(%s)%c", ".sort_key", sortKey, separator);
+ if (ss->treeSortKey && ss->treeSortKey != PID)
+ fprintf(fd, "%s=Dynamic(%s)%c", ".tree_sort_key", treeSortKey, separator);
+ } else {
+ printSettingString(".sort_key", sortKey);
+ printSettingString(".tree_sort_key", treeSortKey);
+ printSettingInteger(".tree_view_always_by_pid", ss->treeViewAlwaysByPID);
+ }
printSettingInteger(".tree_view", ss->treeView);
- printSettingInteger(".tree_view_always_by_pid", ss->treeViewAlwaysByID);
printSettingInteger(".sort_direction", ss->direction);
printSettingInteger(".tree_sort_direction", ss->treeDirection);
printSettingInteger(".all_branches_collapsed", ss->allBranchesCollapsed);
@@ -667,9 +721,10 @@ int Settings_write(const Settings* this, bool onCrash) {
return r;
}
-Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, Hashtable* dynamicColumns) {
+Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* dynamicScreens) {
Settings* this = xCalloc(1, sizeof(Settings));
+ this->dynamicScreens = dynamicScreens;
this->dynamicColumns = dynamicColumns;
this->dynamicMeters = dynamicMeters;
this->hLayout = HF_TWO_50_50;
@@ -787,7 +842,7 @@ void ScreenSettings_invertSortOrder(ScreenSettings* this) {
}
void ScreenSettings_setSortKey(ScreenSettings* this, ProcessField sortKey) {
- if (this->treeViewAlwaysByID || !this->treeView) {
+ if (this->treeViewAlwaysByPID || !this->treeView) {
this->sortKey = sortKey;
this->direction = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1;
this->treeView = false;
diff --git a/Settings.h b/Settings.h
index 3caaab28..0c202f8a 100644
--- a/Settings.h
+++ b/Settings.h
@@ -21,10 +21,14 @@ in the source distribution for its full text.
#define CONFIG_READER_MIN_VERSION 3
+struct DynamicScreen_;
+struct Table_;
+
typedef struct {
const char* name;
const char* columns;
const char* sortKey;
+ const char* treeSortKey;
} ScreenDefaults;
typedef struct {
@@ -34,7 +38,9 @@ typedef struct {
} MeterColumnSetting;
typedef struct ScreenSettings_ {
- char* name;
+ char* heading; /* user-editable screen name (pretty) */
+ char* dynamic; /* from DynamicScreen config (fixed) */
+ struct Table_* table;
RowField* fields;
uint32_t flags;
int direction;
@@ -42,7 +48,7 @@ typedef struct ScreenSettings_ {
RowField sortKey;
RowField treeSortKey;
bool treeView;
- bool treeViewAlwaysByID;
+ bool treeViewAlwaysByPID;
bool allBranchesCollapsed;
} ScreenSettings;
@@ -53,6 +59,7 @@ typedef struct Settings_ {
MeterColumnSetting* hColumns;
Hashtable* dynamicColumns; /* runtime-discovered columns */
Hashtable* dynamicMeters; /* runtime-discovered meters */
+ Hashtable* dynamicScreens; /* runtime-discovered screens */
ScreenSettings** screens;
unsigned int nScreens;
@@ -106,7 +113,7 @@ typedef struct Settings_ {
static inline RowField ScreenSettings_getActiveSortKey(const ScreenSettings* this) {
return (this->treeView)
- ? (this->treeViewAlwaysByID ? 1 : this->treeSortKey)
+ ? (this->treeViewAlwaysByPID ? 1 : this->treeSortKey)
: this->sortKey;
}
@@ -118,10 +125,12 @@ void Settings_delete(Settings* this);
int Settings_write(const Settings* this, bool onCrash);
-Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, Hashtable* dynamicColumns);
+Settings* Settings_new(unsigned int initialCpuCount, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* dynamicScreens);
ScreenSettings* Settings_newScreen(Settings* this, const ScreenDefaults* defaults);
+ScreenSettings* Settings_newDynamicScreen(Settings* this, const char* tab, const struct DynamicScreen_* screen, struct Table_* table);
+
void ScreenSettings_delete(ScreenSettings* this);
void ScreenSettings_invertSortOrder(ScreenSettings* this);
diff --git a/Table.c b/Table.c
index dcb48677..aecc7e6d 100644
--- a/Table.c
+++ b/Table.c
@@ -192,6 +192,7 @@ static void Table_buildTree(Table* this) {
void Table_updateDisplayList(Table* this) {
const Settings* settings = this->host->settings;
+
if (settings->ss->treeView) {
if (this->needsSort)
Table_buildTree(this);
@@ -294,7 +295,7 @@ void Table_printHeader(const Settings* settings, RichString* header) {
for (int i = 0; fields[i]; i++) {
int color;
- if (ss->treeView && ss->treeViewAlwaysByID) {
+ if (ss->treeView && ss->treeViewAlwaysByPID) {
color = CRT_colors[PANEL_HEADER_FOCUS];
} else if (key == fields[i]) {
color = CRT_colors[PANEL_SELECTION_FOCUS];
diff --git a/darwin/Platform.h b/darwin/Platform.h
index 5cd67297..cf00919f 100644
--- a/darwin/Platform.h
+++ b/darwin/Platform.h
@@ -118,7 +118,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -126,4 +126,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h
index b37cea2a..91616d4f 100644
--- a/dragonflybsd/Platform.h
+++ b/dragonflybsd/Platform.h
@@ -111,7 +111,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -119,4 +119,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/freebsd/Platform.h b/freebsd/Platform.h
index 849f7ddf..cc864569 100644
--- a/freebsd/Platform.h
+++ b/freebsd/Platform.h
@@ -109,7 +109,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
return NULL;
}
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -119,4 +119,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/linux/Platform.h b/linux/Platform.h
index 1621d562..a64e54a7 100644
--- a/linux/Platform.h
+++ b/linux/Platform.h
@@ -132,7 +132,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -140,4 +140,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/netbsd/Platform.h b/netbsd/Platform.h
index a75c766c..ae34198c 100644
--- a/netbsd/Platform.h
+++ b/netbsd/Platform.h
@@ -115,7 +115,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -123,4 +123,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/openbsd/Platform.h b/openbsd/Platform.h
index f357006c..790dc473 100644
--- a/openbsd/Platform.h
+++ b/openbsd/Platform.h
@@ -109,7 +109,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -117,4 +117,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/pcp/InDomTable.c b/pcp/InDomTable.c
new file mode 100644
index 00000000..12059922
--- /dev/null
+++ b/pcp/InDomTable.c
@@ -0,0 +1,97 @@
+/*
+htop - InDomTable.c
+(C) 2023 htop dev team
+(C) 2022-2023 Sohaib Mohammed
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "InDomTable.h"
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "CRT.h"
+#include "DynamicColumn.h"
+#include "Hashtable.h"
+#include "Macros.h"
+#include "Platform.h"
+#include "Table.h"
+#include "Vector.h"
+#include "XUtils.h"
+
+#include "pcp/Instance.h"
+#include "pcp/PCPDynamicColumn.h"
+#include "pcp/PCPMetric.h"
+
+
+InDomTable* InDomTable_new(Machine* host, pmInDom indom, int metricKey) {
+ InDomTable* this = xCalloc(1, sizeof(InDomTable));
+ Object_setClass(this, Class(InDomTable));
+ this->metricKey = metricKey;
+ this->id = indom;
+
+ Table* super = &this->super;
+ Table_init(super, Class(Row), host);
+
+ return this;
+}
+
+void InDomTable_done(InDomTable* this) {
+ Table_done(&this->super);
+}
+
+static void InDomTable_delete(Object* cast) {
+ InDomTable* this = (InDomTable*) cast;
+ InDomTable_done(this);
+ free(this);
+}
+
+static Instance* InDomTable_getInstance(InDomTable* this, int id, bool* preExisting) {
+ const Table* super = &this->super;
+ Instance* inst = (Instance*) Hashtable_get(super->table, id);
+ *preExisting = inst != NULL;
+ if (inst) {
+ assert(Vector_indexOf(super->rows, inst, Row_idEqualCompare) != -1);
+ assert(Instance_getId(inst) == id);
+ } else {
+ inst = Instance_new(super->host, this);
+ assert(inst->name == NULL);
+ Instance_setId(inst, id);
+ }
+ return inst;
+}
+
+static void InDomTable_goThroughEntries(InDomTable* this) {
+ Table* super = &this->super;
+
+ /* for every instance ... */
+ int instid = -1, offset = -1;
+ while (PCPMetric_iterate(this->metricKey, &instid, &offset)) {
+ bool preExisting;
+ Instance* inst = InDomTable_getInstance(this, instid, &preExisting);
+ inst->offset = offset >= 0 ? offset : 0;
+
+ Row* row = &inst->super;
+ if (!preExisting)
+ Table_add(super, row);
+ row->updated = true;
+ row->show = true;
+ }
+}
+
+static void InDomTable_iterateEntries(Table* super) {
+ InDomTable* this = (InDomTable*) super;
+ InDomTable_goThroughEntries(this);
+}
+
+const TableClass InDomTable_class = {
+ .super = {
+ .extends = Class(Table),
+ .delete = InDomTable_delete,
+ },
+ .prepare = Table_prepareEntries,
+ .iterate = InDomTable_iterateEntries,
+ .cleanup = Table_cleanupEntries,
+};
diff --git a/pcp/InDomTable.h b/pcp/InDomTable.h
new file mode 100644
index 00000000..7d848d57
--- /dev/null
+++ b/pcp/InDomTable.h
@@ -0,0 +1,36 @@
+#ifndef HEADER_InDomTable
+#define HEADER_InDomTable
+/*
+htop - InDomTable.h
+(C) 2023 htop dev team
+(C) 2022-2023 Sohaib Mohammed
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+#include "Platform.h"
+#include "Table.h"
+
+
+typedef struct InDomTable_ {
+ Table super;
+ pmInDom id; /* shared by metrics in the table */
+ unsigned int metricKey; /* representative metric using this indom */
+} InDomTable;
+
+extern const TableClass InDomTable_class;
+
+InDomTable* InDomTable_new(Machine* host, pmInDom indom, int metricKey);
+
+void InDomTable_done(InDomTable* this);
+
+RowField RowField_keyAt(const Settings* settings, int at);
+
+void InDomTable_scan(Table* super);
+
+#endif
diff --git a/pcp/Instance.c b/pcp/Instance.c
new file mode 100644
index 00000000..1d56c108
--- /dev/null
+++ b/pcp/Instance.c
@@ -0,0 +1,160 @@
+/*
+htop - Instance.c
+(C) 2022-2023 Sohaib Mohammed
+(C) 2022-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "pcp/Instance.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+
+#include "CRT.h"
+#include "DynamicColumn.h"
+#include "DynamicScreen.h"
+#include "Hashtable.h"
+#include "Machine.h"
+#include "Macros.h"
+#include "PCPDynamicColumn.h"
+#include "PCPDynamicScreen.h"
+#include "PCPMetric.h"
+#include "Platform.h"
+#include "Row.h"
+#include "RichString.h"
+#include "XUtils.h"
+
+#include "pcp/InDomTable.h"
+#include "pcp/PCPMetric.h"
+
+
+Instance* Instance_new(const Machine* host, const InDomTable* indom) {
+ Instance* this = xCalloc(1, sizeof(Instance));
+ Object_setClass(this, Class(Instance));
+
+ Row* super = &this->super;
+ Row_init(super, host);
+
+ this->indom = indom;
+
+ return this;
+}
+
+void Instance_done(Instance* this) {
+ if (this->name)
+ free(this->name);
+ Row_done(&this->super);
+}
+
+static void Instance_delete(Object* cast) {
+ Instance* this = (Instance*) cast;
+ Instance_done(this);
+ free(this);
+}
+
+static void Instance_writeField(const Row* super, RichString* str, RowField field) {
+ const Instance* this = (const Instance*) super;
+ int instid = Instance_getId(this);
+
+ const Settings* settings = super->host->settings;
+ DynamicColumn* column = Hashtable_get(settings->dynamicColumns, field);
+ PCPDynamicColumn* cp = (PCPDynamicColumn*) column;
+ const pmDesc* descp = PCPMetric_desc(cp->id);
+
+ pmAtomValue atom;
+ pmAtomValue *ap = &atom;
+ if (!PCPMetric_instance(cp->id, instid, this->offset, ap, descp->type))
+ ap = NULL;
+
+ PCPDynamicColumn_writeAtomValue(cp, str, settings, cp->id, instid, descp, ap);
+
+ if (ap && descp->type == PM_TYPE_STRING)
+ free(ap->cp);
+}
+
+static const char* Instance_externalName(Row* super) {
+ Instance* this = (Instance*) super;
+
+ if (!this->name)
+ pmNameInDom(InDom_getId(this), Instance_getId(this), &this->name);
+ return this->name;
+}
+
+static int Instance_compareByKey(const Row* v1, const Row* v2, int key) {
+ const Instance* i1 = (const Instance*)v1;
+ const Instance* i2 = (const Instance*)v2;
+
+ if (key < 0)
+ return 0;
+
+ Hashtable* dc = Platform_dynamicColumns();
+ const PCPDynamicColumn* column = Hashtable_get(dc, key);
+ if (!column)
+ return -1;
+
+ size_t metric = column->id;
+ unsigned int type = PCPMetric_type(metric);
+
+ pmAtomValue atom1 = {0}, atom2 = {0};
+ if (!PCPMetric_instance(metric, i1->offset, i1->offset, &atom1, type) ||
+ !PCPMetric_instance(metric, i2->offset, i2->offset, &atom2, type)) {
+ if (type == PM_TYPE_STRING) {
+ free(atom1.cp);
+ free(atom2.cp);
+ }
+ return -1;
+ }
+
+ switch (type) {
+ case PM_TYPE_STRING: {
+ int cmp = SPACESHIP_NULLSTR(atom2.cp, atom1.cp);
+ free(atom2.cp);
+ free(atom1.cp);
+ return cmp;
+ }
+ case PM_TYPE_32:
+ return SPACESHIP_NUMBER(atom2.l, atom1.l);
+ case PM_TYPE_U32:
+ return SPACESHIP_NUMBER(atom2.ul, atom1.ul);
+ case PM_TYPE_64:
+ return SPACESHIP_NUMBER(atom2.ll, atom1.ll);
+ case PM_TYPE_U64:
+ return SPACESHIP_NUMBER(atom2.ull, atom1.ull);
+ case PM_TYPE_FLOAT:
+ return SPACESHIP_NUMBER(atom2.f, atom1.f);
+ case PM_TYPE_DOUBLE:
+ return SPACESHIP_NUMBER(atom2.d, atom1.d);
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+static int Instance_compare(const void* v1, const void* v2) {
+ const Instance* i1 = (const Instance*)v1;
+ const Instance* i2 = (const Instance*)v2;
+ const ScreenSettings* ss = i1->super.host->settings->ss;
+ RowField key = ScreenSettings_getActiveSortKey(ss);
+ int result = Instance_compareByKey(v1, v2, key);
+
+ // Implement tie-breaker (needed to make tree mode more stable)
+ if (!result)
+ return SPACESHIP_NUMBER(Instance_getId(i1), Instance_getId(i2));
+
+ return (ScreenSettings_getActiveDirection(ss) == 1) ? result : -result;
+}
+
+const RowClass Instance_class = {
+ .super = {
+ .extends = Class(Row),
+ .display = Row_display,
+ .delete = Instance_delete,
+ .compare = Instance_compare,
+ },
+ .sortKeyString = Instance_externalName,
+ .writeField = Instance_writeField,
+};
diff --git a/pcp/Instance.h b/pcp/Instance.h
new file mode 100644
index 00000000..c7d688fc
--- /dev/null
+++ b/pcp/Instance.h
@@ -0,0 +1,37 @@
+#ifndef HEADER_Instance
+#define HEADER_Instance
+/*
+htop - Instance.h
+(C) 2022-2023 htop dev team
+(C) 2022-2023 Sohaib Mohammed
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "Hashtable.h"
+#include "Object.h"
+#include "Platform.h"
+#include "Row.h"
+
+
+typedef struct Instance_ {
+ Row super;
+
+ char *name; /* external instance name */
+ const struct InDomTable_* indom; /* instance domain */
+
+ /* default result offset to use for searching metrics with instances */
+ unsigned int offset;
+} Instance;
+
+#define InDom_getId(i_) ((i_)->indom->id)
+#define Instance_getId(i_) ((i_)->super.id)
+#define Instance_setId(i_, id_) ((i_)->super.id = (id_))
+
+extern const RowClass Instance_class;
+
+Instance* Instance_new(const Machine* host, const struct InDomTable_* indom);
+
+void Instance_done(Instance* this);
+
+#endif
diff --git a/pcp/PCPDynamicColumn.c b/pcp/PCPDynamicColumn.c
index 88b4dbd5..99e0d8f1 100644
--- a/pcp/PCPDynamicColumn.c
+++ b/pcp/PCPDynamicColumn.c
@@ -1,8 +1,7 @@
/*
htop - PCPDynamicColumn.c
-(C) 2021 Sohaib Mohammed
-(C) 2021 htop dev team
-(C) 2021 Red Hat, Inc.
+(C) 2021-2023 Sohaib Mohammed
+(C) 2021-2023 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@@ -28,6 +27,7 @@ in the source distribution for its full text.
#include "RichString.h"
#include "XUtils.h"
+#include "linux/CGroupUtils.h"
#include "pcp/PCPProcess.h"
#include "pcp/PCPMetric.h"
@@ -49,6 +49,11 @@ static bool PCPDynamicColumn_addMetric(PCPDynamicColumns* columns, PCPDynamicCol
}
static void PCPDynamicColumn_parseMetric(PCPDynamicColumns* columns, PCPDynamicColumn* column, const char* path, unsigned int line, char* value) {
+ /* pmLookupText */
+ if (!column->super.description) {
+ PCPMetric_lookupText(value, &column->super.description);
+ }
+
/* lookup a dynamic metric with this name, else create */
if (PCPDynamicColumn_addMetric(columns, column) == false)
return;
@@ -108,6 +113,10 @@ static bool PCPDynamicColumn_uniqueName(char* key, PCPDynamicColumns* columns) {
static PCPDynamicColumn* PCPDynamicColumn_new(PCPDynamicColumns* columns, const char* name) {
PCPDynamicColumn* column = xCalloc(1, sizeof(*column));
String_safeStrncpy(column->super.name, name, sizeof(column->super.name));
+ column->super.enabled = false;
+ column->percent = false;
+ column->instances = false;
+ column->defaultEnabled = true;
size_t id = columns->count + LAST_PROCESSFIELD;
Hashtable_put(columns->table, id, column);
@@ -160,6 +169,14 @@ static void PCPDynamicColumn_parseFile(PCPDynamicColumns* columns, const char* p
free_and_xStrdup(&column->super.description, value);
} else if (value && column && String_eq(key, "width")) {
column->super.width = strtoul(value, NULL, 10);
+ } else if (value && column && String_eq(key, "format")) {
+ free_and_xStrdup(&column->format, value);
+ } else if (value && column && String_eq(key, "instances")) {
+ if (String_eq(value, "True") || String_eq(value, "true"))
+ column->instances = true;
+ } else if (value && column && (String_eq(key, "default") || String_eq(key, "enabled"))) {
+ if (String_eq(value, "False") || String_eq(value, "false"))
+ column->defaultEnabled = false;
} else if (value && column && String_eq(key, "metric")) {
PCPDynamicColumn_parseMetric(columns, column, path, lineno, value);
}
@@ -233,74 +250,222 @@ void PCPDynamicColumns_init(PCPDynamicColumns* columns) {
free(path);
}
+void PCPDynamicColumn_done(PCPDynamicColumn* this) {
+ DynamicColumn_done(&this->super);
+ free(this->metricName);
+ free(this->format);
+}
+
static void PCPDynamicColumns_free(ATTR_UNUSED ht_key_t key, void* value, ATTR_UNUSED void* data) {
PCPDynamicColumn* column = (PCPDynamicColumn*) value;
- free(column->metricName);
- free(column->super.heading);
- free(column->super.caption);
- free(column->super.description);
+ PCPDynamicColumn_done(column);
}
void PCPDynamicColumns_done(Hashtable* table) {
Hashtable_foreach(table, PCPDynamicColumns_free, NULL);
}
-void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, RichString* str) {
- const PCPProcess* pp = (const PCPProcess*) proc;
- unsigned int type = PCPMetric_type(this->id);
+static void PCPDynamicColumn_setupWidth(ATTR_UNUSED ht_key_t key, void* value, ATTR_UNUSED void* data) {
+ PCPDynamicColumn* column = (PCPDynamicColumn*) value;
- pmAtomValue atom;
- if (!PCPMetric_instance(this->id, Process_getPid(proc), pp->offset, &atom, type)) {
- RichString_appendAscii(str, CRT_colors[METER_VALUE_ERROR], "no data");
+ /* calculate column size based on config file and metric units */
+ const pmDesc* desc = PCPMetric_desc(column->id);
+
+ if (column->instances || desc->type == PM_TYPE_STRING) {
+ column->super.width = column->width;
+ if (column->super.width == 0)
+ column->super.width = -16;
return;
}
- int width = this->super.width;
- if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
- width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
- int abswidth = abs(width);
- if (abswidth > DYNAMIC_MAX_COLUMN_WIDTH) {
- abswidth = DYNAMIC_MAX_COLUMN_WIDTH;
- width = -abswidth;
+ if (column->format) {
+ if (strcmp(column->format, "percent") == 0) {
+ column->super.width = 5;
+ return;
+ }
+ if (strcmp(column->format, "process") == 0) {
+ column->super.width = Process_pidDigits;
+ return;
+ }
}
- char buffer[DYNAMIC_MAX_COLUMN_WIDTH + /* space */ 1 + /* null terminator */ + 1];
- int attr = CRT_colors[DEFAULT_COLOR];
+ if (column->width) {
+ column->super.width = column->width;
+ return;
+ }
+
+ pmUnits units = desc->units;
+ if (units.dimSpace && units.dimTime)
+ column->super.width = 11; // Row_printRate
+ else if (units.dimSpace)
+ column->super.width = 5; // Row_printBytes
+ else if (units.dimCount && units.dimTime)
+ column->super.width = 11; // Row_printCount
+ else if (units.dimTime)
+ column->super.width = 8; // Row_printTime
+ else
+ column->super.width = 11; // Row_printCount
+}
+
+void PCPDynamicColumns_setupWidths(PCPDynamicColumns* columns) {
+ Hashtable_foreach(columns->table, PCPDynamicColumn_setupWidth, NULL);
+}
+
+/* normalize output units to bytes and seconds */
+static int PCPDynamicColumn_normalize(const pmDesc* desc, const pmAtomValue* ap, double* value) {
+ /* form normalized units based on the original metric units */
+ pmUnits units = desc->units;
+ if (units.dimTime)
+ units.scaleTime = PM_TIME_SEC;
+ if (units.dimSpace)
+ units.scaleSpace = PM_SPACE_BYTE;
+ if (units.dimCount)
+ units.scaleCount = PM_COUNT_ONE;
+
+ pmAtomValue atom;
+ int sts, type = desc->type;
+ if ((sts = pmConvScale(type, ap, &desc->units, &atom, &units)) < 0)
+ return sts;
+
switch (type) {
- case PM_TYPE_STRING:
- attr = CRT_colors[PROCESS_SHADOW];
- Row_printLeftAlignedField(str, attr, atom.cp, abswidth);
- free(atom.cp);
- break;
case PM_TYPE_32:
- xSnprintf(buffer, sizeof(buffer), "%*d ", width, atom.l);
- RichString_appendAscii(str, attr, buffer);
+ *value = (double) atom.l;
break;
case PM_TYPE_U32:
- xSnprintf(buffer, sizeof(buffer), "%*u ", width, atom.ul);
- RichString_appendAscii(str, attr, buffer);
+ *value = (double) atom.ul;
break;
case PM_TYPE_64:
- xSnprintf(buffer, sizeof(buffer), "%*lld ", width, (long long) atom.ll);
- RichString_appendAscii(str, attr, buffer);
+ *value = (double) atom.ll;
break;
case PM_TYPE_U64:
- xSnprintf(buffer, sizeof(buffer), "%*llu ", width, (unsigned long long) atom.ull);
- RichString_appendAscii(str, attr, buffer);
+ *value = (double) atom.ull;
break;
case PM_TYPE_FLOAT:
- xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, (double) atom.f);
- RichString_appendAscii(str, attr, buffer);
+ *value = (double) atom.f;
break;
case PM_TYPE_DOUBLE:
- xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, atom.d);
- RichString_appendAscii(str, attr, buffer);
+ *value = atom.d;
break;
default:
- attr = CRT_colors[METER_VALUE_ERROR];
- RichString_appendAscii(str, attr, "no type");
- break;
+ return PM_ERR_CONV;
+ }
+ return 0;
+}
+
+void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str, const struct Settings_* settings, int metric, int instance, const pmDesc* desc, const void* atom) {
+ const pmAtomValue* atomvalue = (const pmAtomValue*) atom;
+ char buffer[DYNAMIC_MAX_COLUMN_WIDTH + /*space*/ 1 + /*null*/ 1];
+ int attr = CRT_colors[DEFAULT_COLOR];
+ int width = column->super.width;
+ int n;
+
+ if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
+ width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
+ int abswidth = abs(width);
+ if (abswidth > DYNAMIC_MAX_COLUMN_WIDTH) {
+ abswidth = DYNAMIC_MAX_COLUMN_WIDTH;
+ width = -abswidth;
+ }
+
+ if (atomvalue == NULL) {
+ n = xSnprintf(buffer, sizeof(buffer), "%*.*s ", width, abswidth, "N/A");
+ RichString_appendnAscii(str, CRT_colors[PROCESS_SHADOW], buffer, n);
+ return;
+ }
+
+ /* deal with instance names and metrics with string values first */
+ if (column->instances || desc->type == PM_TYPE_STRING) {
+ char* value = NULL;
+ char* dupd1 = NULL;
+ if (column->instances) {
+ attr = CRT_colors[DYNAMIC_GRAY];
+ PCPMetric_externalName(metric, instance, &dupd1);
+ value = dupd1;
+ } else {
+ attr = CRT_colors[DYNAMIC_GREEN];
+ value = atomvalue->cp;
+ }
+ if (column->format && value) {
+ char* dupd2 = NULL;
+ if (strcmp(column->format, "command") == 0)
+ attr = CRT_colors[PROCESS_COMM];
+ else if (strcmp(column->format, "process") == 0)
+ attr = CRT_colors[PROCESS_SHADOW];
+ else if (strcmp(column->format, "device") == 0 && strncmp(value, "/dev/", 5) == 0)
+ value += 5;
+ else if (strcmp(column->format, "cgroup") == 0 && (dupd2 = CGroup_filterName(value)))
+ value = dupd2;
+ n = xSnprintf(buffer, sizeof(buffer), "%*.*s ", width, abswidth, value);
+ if (dupd2)
+ free(dupd2);
+ } else if (value) {
+ n = xSnprintf(buffer, sizeof(buffer), "%*.*s ", width, abswidth, value);
+ } else {
+ n = xSnprintf(buffer, sizeof(buffer), "%*.*s ", width, abswidth, "N/A");
+ }
+ if (dupd1)
+ free(dupd1);
+ RichString_appendnAscii(str, attr, buffer, n);
+ return;
+ }
+
+ /* deal with any numeric value - first, normalize units to bytes/seconds */
+ double value;
+ if (PCPDynamicColumn_normalize(desc, atomvalue, &value) < 0) {
+ n = xSnprintf(buffer, sizeof(buffer), "%*.*s ", width, abswidth, "no conv");
+ RichString_appendnAscii(str, CRT_colors[METER_VALUE_ERROR], buffer, n);
+ return;
+ }
+
+ if (column->format) {
+ if (strcmp(column->format, "percent") == 0) {
+ n = Row_printPercentage(value, buffer, sizeof(buffer), width, &attr);
+ RichString_appendnAscii(str, attr, buffer, n);
+ return;
+ }
+ if (strcmp(column->format, "process") == 0) {
+ n = xSnprintf(buffer, sizeof(buffer), "%*d ", Row_pidDigits, (int)value);
+ RichString_appendnAscii(str, attr, buffer, n);
+ return;
+ }
}
+
+ /* width overrides unit suffix and coloring; too complex for a corner case */
+ if (column->width) {
+ if (value - (unsigned long long)value > 0) /* display floating point */
+ n = xSnprintf(buffer, sizeof(buffer), "%*.2f ", width, value);
+ else /* display as integer */
+ n = xSnprintf(buffer, sizeof(buffer), "%*llu ", width, (unsigned long long)value);
+ RichString_appendnAscii(str, CRT_colors[PROCESS], buffer, n);
+ return;
+ }
+
+ bool coloring = settings->highlightMegabytes;
+ pmUnits units = desc->units;
+ if (units.dimSpace && units.dimTime)
+ Row_printRate(str, value, coloring);
+ else if (units.dimSpace)
+ Row_printBytes(str, value, coloring);
+ else if (units.dimCount)
+ Row_printCount(str, value, coloring);
+ else if (units.dimTime)
+ Row_printTime(str, value / 10 /* hundreds of a second */, coloring);
+ else
+ Row_printCount(str, value, 0); /* e.g. PID */
+}
+
+void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, RichString* str) {
+ const Settings* settings = proc->super.host->settings;
+ const PCPProcess* pp = (const PCPProcess*) proc;
+ const pmDesc* desc = PCPMetric_desc(this->id);
+ pid_t pid = Process_getPid(proc);
+
+ pmAtomValue atom;
+ pmAtomValue *ap = &atom;
+ if (!PCPMetric_instance(this->id, pid, pp->offset, ap, desc->type))
+ ap = NULL;
+
+ PCPDynamicColumn_writeAtomValue(this, str, settings, this->id, pid, desc, ap);
}
int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, ProcessField key) {
diff --git a/pcp/PCPDynamicColumn.h b/pcp/PCPDynamicColumn.h
index d0ffe719..ade782b7 100644
--- a/pcp/PCPDynamicColumn.h
+++ b/pcp/PCPDynamicColumn.h
@@ -1,5 +1,11 @@
#ifndef HEADER_PCPDynamicColumn
#define HEADER_PCPDynamicColumn
+/*
+htop - PCPDynamicColumn.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
#include <stddef.h>
@@ -11,15 +17,22 @@
#include "pcp/PCPProcess.h"
+struct pmDesc;
+
typedef struct PCPDynamicColumn_ {
DynamicColumn super;
char* metricName;
+ char* format;
size_t id; /* identifier for metric array lookups */
+ int width; /* optional width from configuration file */
+ bool defaultEnabled; /* default enabled in dynamic screen */
+ bool percent;
+ bool instances; /* an instance *names* column, not values */
} PCPDynamicColumn;
typedef struct PCPDynamicColumns_ {
Hashtable* table;
- size_t count; /* count of dynamic meters discovered by scan */
+ size_t count; /* count of dynamic columns discovered by scan */
size_t offset; /* start offset into the Platform metric array */
size_t cursor; /* identifier allocator for each new metric used */
} PCPDynamicColumns;
@@ -28,8 +41,14 @@ void PCPDynamicColumns_init(PCPDynamicColumns* columns);
void PCPDynamicColumns_done(Hashtable* table);
+void PCPDynamicColumns_setupWidths(PCPDynamicColumns* columns);
+
void PCPDynamicColumn_writeField(PCPDynamicColumn* this, const Process* proc, RichString* str);
+void PCPDynamicColumn_writeAtomValue(PCPDynamicColumn* column, RichString* str, const struct Settings_* settings, int metric, int instance, const struct pmDesc* desc, const void* atomvalue);
+
int PCPDynamicColumn_compareByKey(const PCPProcess* p1, const PCPProcess* p2, ProcessField key);
+void PCPDynamicColumn_done(PCPDynamicColumn* this);
+
#endif
diff --git a/pcp/PCPDynamicMeter.h b/pcp/PCPDynamicMeter.h
index 0e5ddd2b..3a72d13c 100644
--- a/pcp/PCPDynamicMeter.h
+++ b/pcp/PCPDynamicMeter.h
@@ -1,5 +1,11 @@
#ifndef HEADER_PCPDynamicMeter
#define HEADER_PCPDynamicMeter
+/*
+htop - PCPDynamicMeter.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
#include <stddef.h>
diff --git a/pcp/PCPDynamicScreen.c b/pcp/PCPDynamicScreen.c
new file mode 100644
index 00000000..573bc427
--- /dev/null
+++ b/pcp/PCPDynamicScreen.c
@@ -0,0 +1,405 @@
+/*
+htop - PCPDynamicScreen.c
+(C) 2022 Sohaib Mohammed
+(C) 2022-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "pcp/PCPDynamicScreen.h"
+
+#include <ctype.h>
+#include <dirent.h>
+#include <stdbool.h>
+#include <pcp/pmapi.h>
+
+#include "AvailableColumnsPanel.h"
+#include "Macros.h"
+#include "Platform.h"
+#include "Settings.h"
+#include "XUtils.h"
+
+#include "pcp/InDomTable.h"
+#include "pcp/PCPDynamicColumn.h"
+
+
+static char* formatFields(PCPDynamicScreen* screen) {
+ char* columns = strdup("");
+
+ for (size_t j = 0; j < screen->totalColumns; j++) {
+ const PCPDynamicColumn* column = screen->columns[j];
+ if (column->super.enabled == false)
+ continue;
+ char* prefix = columns;
+ xAsprintf(&columns, "%s Dynamic(%s)", prefix, column->super.name);
+ free(prefix);
+ }
+
+ return columns;
+}
+
+static void PCPDynamicScreens_appendDynamicColumns(PCPDynamicScreens* screens, PCPDynamicColumns* columns) {
+ for (size_t i = 0; i < screens->count; i++) {
+ PCPDynamicScreen *screen = Hashtable_get(screens->table, i);
+ if (!screen)
+ return;
+
+ /* setup default fields (columns) based on configuration */
+ for (size_t j = 0; j < screen->totalColumns; j++) {
+ PCPDynamicColumn* column = screen->columns[j];
+
+ column->id = columns->offset + columns->cursor;
+ columns->cursor++;
+ Platform_addMetric(column->id, column->metricName);
+
+ size_t id = columns->count + LAST_PROCESSFIELD;
+ Hashtable_put(columns->table, id, column);
+ columns->count++;
+
+ if (j == 0) {
+ const pmDesc* desc = PCPMetric_desc(column->id);
+ assert(desc->indom != PM_INDOM_NULL);
+ screen->indom = desc->indom;
+ screen->key = column->id;
+ }
+ }
+ screen->super.columnKeys = formatFields(screen);
+ }
+}
+
+static PCPDynamicColumn* PCPDynamicScreen_lookupMetric(PCPDynamicScreen* screen, const char* name) {
+ PCPDynamicColumn* column = NULL;
+ size_t bytes = strlen(name) + strlen(screen->super.name) + 1; /* colon */
+ if (bytes >= sizeof(column->super.name))
+ return NULL;
+
+ bytes += 16; /* prefix, dots and terminator */
+ char* metricName = xMalloc(bytes);
+ xSnprintf(metricName, bytes, "htop.screen.%s.%s", screen->super.name, name);
+
+ for (size_t i = 0; i < screen->totalColumns; i++) {
+ column = screen->columns[i];
+ if (String_eq(column->metricName, metricName)) {
+ free(metricName);
+ return column;
+ }
+ }
+
+ /* not an existing column in this screen - create it and add to the list */
+ column = xCalloc(1, sizeof(PCPDynamicColumn));
+ xSnprintf(column->super.name, sizeof(column->super.name), "%s:%s", screen->super.name, name);
+ column->super.table = &screen->table->super;
+ column->metricName = metricName;
+ column->super.enabled = true;
+
+ size_t n = screen->totalColumns + 1;
+ screen->columns = xReallocArray(screen->columns, n, sizeof(PCPDynamicColumn*));
+ screen->columns[n - 1] = column;
+ screen->totalColumns = n;
+
+ return column;
+}
+
+static void PCPDynamicScreen_parseColumn(PCPDynamicScreen* screen, const char* path, unsigned int line, char* key, char* value) {
+ PCPDynamicColumn* column;
+ char* p;
+
+ if ((p = strchr(key, '.')) == NULL)
+ return;
+ *p++ = '\0'; /* end the name, p is now the attribute, e.g. 'label' */
+
+ /* lookup a dynamic column with this name, else create */
+ column = PCPDynamicScreen_lookupMetric(screen, key);
+
+ if (String_eq(p, "metric")) {
+ char* error;
+ if (pmRegisterDerivedMetric(column->metricName, value, &error) < 0) {
+ char* note;
+ xAsprintf(&note,
+ "%s: failed to parse expression in %s at line %u\n%s\n",
+ pmGetProgname(), path, line, error);
+ free(error);
+ errno = EINVAL;
+ CRT_fatalError(note);
+ free(note);
+ }
+
+ /* pmLookupText - add optional metric help text */
+ if (!column->super.description && !column->instances)
+ PCPMetric_lookupText(value, &column->super.description);
+
+ } else {
+ /* this is a property of a dynamic column - the column expression */
+ /* may not have been observed yet; i.e. we allow for any ordering */
+
+ if (String_eq(p, "caption")) {
+ free_and_xStrdup(&column->super.caption, value);
+ } else if (String_eq(p, "heading")) {
+ free_and_xStrdup(&column->super.heading, value);
+ } else if (String_eq(p, "description")) {
+ free_and_xStrdup(&column->super.description, value);
+ } else if (String_eq(p, "width")) {
+ column->width = strtoul(value, NULL, 10);
+ } else if (String_eq(p, "format")) {
+ free_and_xStrdup(&column->format, value);
+ } else if (String_eq(p, "instances")) {
+ if (String_eq(value, "True") || String_eq(value, "true"))
+ column->instances = true;
+ free_and_xStrdup(&column->super.description, screen->super.caption);
+ } else if (String_eq(p, "default")) { /* displayed by default */
+ if (String_eq(value, "False") || String_eq(value, "false"))
+ column->defaultEnabled = column->super.enabled = false;
+ }
+ }
+}
+
+static bool PCPDynamicScreen_validateScreenName(char* key, const char* path, unsigned int line) {
+ char* p = key;
+ char* end = strrchr(key, ']');
+
+ if (end) {
+ *end = '\0';
+ } else {
+ fprintf(stderr,
+ "%s: no closing brace on screen name at %s line %u\n\"%s\"",
+ pmGetProgname(), path, line, key);
+ return false;
+ }
+
+ while (*p) {
+ if (p == key) {
+ if (!isalpha(*p) && *p != '_')
+ break;
+ } else {
+ if (!isalnum(*p) && *p != '_')
+ break;
+ }
+ p++;
+ }
+ if (*p != '\0') { /* badness */
+ fprintf(stderr,
+ "%s: invalid screen name at %s line %u\n\"%s\"",
+ pmGetProgname(), path, line, key);
+ return false;
+ }
+ return true;
+}
+
+/* Ensure a screen name has not been defined previously */
+static bool PCPDynamicScreen_uniqueName(char* key, PCPDynamicScreens* screens) {
+ return !DynamicScreen_search(screens->table, key, NULL);
+}
+
+static PCPDynamicScreen* PCPDynamicScreen_new(PCPDynamicScreens* screens, const char* name) {
+ PCPDynamicScreen* screen = xCalloc(1, sizeof(*screen));
+ String_safeStrncpy(screen->super.name, name, sizeof(screen->super.name));
+ screen->defaultEnabled = true;
+
+ size_t id = screens->count;
+ Hashtable_put(screens->table, id, screen);
+ screens->count++;
+
+ return screen;
+}
+
+static void PCPDynamicScreen_parseFile(PCPDynamicScreens* screens, const char* path) {
+ FILE* file = fopen(path, "r");
+ if (!file)
+ return;
+
+ PCPDynamicScreen* screen = NULL;
+ unsigned int lineno = 0;
+ bool ok = true;
+ for (;;) {
+ char* line = String_readLine(file);
+ if (!line)
+ break;
+ lineno++;
+
+ /* cleanup whitespace, skip comment lines */
+ char* trimmed = String_trim(line);
+ free(line);
+ if (!trimmed || !trimmed[0] || trimmed[0] == '#') {
+ free(trimmed);
+ continue;
+ }
+
+ size_t n;
+ char** config = String_split(trimmed, '=', &n);
+ free(trimmed);
+ if (config == NULL)
+ continue;
+
+ char* key = String_trim(config[0]);
+ char* value = n > 1 ? String_trim(config[1]) : NULL;
+ if (key[0] == '[') { /* new section name - i.e. new screen */
+ ok = PCPDynamicScreen_validateScreenName(key + 1, path, lineno);
+ if (ok)
+ ok = PCPDynamicScreen_uniqueName(key + 1, screens);
+ if (ok)
+ screen = PCPDynamicScreen_new(screens, key + 1);
+ if (pmDebugOptions.appl0)
+ fprintf(stderr, "[%s] screen: %s\n", path, key+1);
+ } else if (!ok) {
+ ; /* skip this one, we're looking for a new header */
+ } else if (!value || !screen) {
+ ; /* skip this one as we always need value strings */
+ } else if (String_eq(key, "heading")) {
+ free_and_xStrdup(&screen->super.heading, value);
+ } else if (String_eq(key, "caption")) {
+ free_and_xStrdup(&screen->super.caption, value);
+ } else if (String_eq(key, "sortKey")) {
+ free_and_xStrdup(&screen->super.sortKey, value);
+ } else if (String_eq(key, "sortDirection")) {
+ screen->super.direction = strtoul(value, NULL, 10);
+ } else if (String_eq(key, "default") || String_eq(key, "enabled")) {
+ if (String_eq(value, "False") || String_eq(value, "false"))
+ screen->defaultEnabled = false;
+ else if (String_eq(value, "True") || String_eq(value, "true"))
+ screen->defaultEnabled = true; /* also default */
+ } else {
+ PCPDynamicScreen_parseColumn(screen, path, lineno, key, value);
+ }
+ String_freeArray(config);
+ free(value);
+ free(key);
+ }
+ fclose(file);
+}
+
+static void PCPDynamicScreen_scanDir(PCPDynamicScreens* screens, char* path) {
+ DIR* dir = opendir(path);
+ if (!dir)
+ return;
+
+ struct dirent* dirent;
+ while ((dirent = readdir(dir)) != NULL) {
+ if (dirent->d_name[0] == '.')
+ continue;
+
+ char* file = String_cat(path, dirent->d_name);
+ PCPDynamicScreen_parseFile(screens, file);
+ free(file);
+ }
+ closedir(dir);
+}
+
+void PCPDynamicScreens_init(PCPDynamicScreens* screens, PCPDynamicColumns* columns) {
+ const char* share = pmGetConfig("PCP_SHARE_DIR");
+ const char* sysconf = pmGetConfig("PCP_SYSCONF_DIR");
+ const char* xdgConfigHome = getenv("XDG_CONFIG_HOME");
+ const char* override = getenv("PCP_HTOP_DIR");
+ const char* home = getenv("HOME");
+ char* path;
+
+ screens->table = Hashtable_new(0, true);
+
+ /* developer paths - PCP_HTOP_DIR=./pcp ./pcp-htop */
+ if (override) {
+ path = String_cat(override, "/screens/");
+ PCPDynamicScreen_scanDir(screens, path);
+ free(path);
+ }
+
+ /* next, search in home directory alongside htoprc */
+ if (xdgConfigHome)
+ path = String_cat(xdgConfigHome, "/htop/screens/");
+ else if (home)
+ path = String_cat(home, "/.config/htop/screens/");
+ else
+ path = NULL;
+ if (path) {
+ PCPDynamicScreen_scanDir(screens, path);
+ free(path);
+ }
+
+ /* next, search in the system screens directory */
+ path = String_cat(sysconf, "/htop/screens/");
+ PCPDynamicScreen_scanDir(screens, path);
+ free(path);
+
+ /* next, try the readonly system screens directory */
+ path = String_cat(share, "/htop/screens/");
+ PCPDynamicScreen_scanDir(screens, path);
+ free(path);
+
+ /* establish internal metric identifier mappings */
+ PCPDynamicScreens_appendDynamicColumns(screens, columns);
+}
+
+static void PCPDynamicScreen_done(PCPDynamicScreen* ds) {
+ DynamicScreen_done(&ds->super);
+ Object_delete(ds->table);
+ free(ds->columns);
+}
+
+static void PCPDynamicScreens_free(ATTR_UNUSED ht_key_t key, void* value, ATTR_UNUSED void* data) {
+ PCPDynamicScreen* ds = (PCPDynamicScreen*) value;
+ PCPDynamicScreen_done(ds);
+}
+
+void PCPDynamicScreens_done(Hashtable* table) {
+ Hashtable_foreach(table, PCPDynamicScreens_free, NULL);
+}
+
+void PCPDynamicScreen_appendTables(PCPDynamicScreens* screens, Machine* host) {
+ PCPDynamicScreen* ds;
+
+ for (size_t i = 0; i < screens->count; i++) {
+ if ((ds = (PCPDynamicScreen*)Hashtable_get(screens->table, i)) == NULL)
+ continue;
+ ds->table = InDomTable_new(host, ds->indom, ds->key);
+ }
+}
+
+void PCPDynamicScreen_appendScreens(PCPDynamicScreens* screens, Settings* settings) {
+ PCPDynamicScreen* ds;
+
+ for (size_t i = 0; i < screens->count; i++) {
+ if ((ds = (PCPDynamicScreen*)Hashtable_get(screens->table, i)) == NULL)
+ continue;
+ if (ds->defaultEnabled == false)
+ continue;
+ const char* tab = ds->super.heading;
+ Settings_newDynamicScreen(settings, tab, &ds->super, &ds->table->super);
+ }
+}
+
+/* called when htoprc .dynamic line is parsed for a dynamic screen */
+void PCPDynamicScreen_addDynamicScreen(PCPDynamicScreens* screens, ScreenSettings* ss) {
+ PCPDynamicScreen* ds;
+
+ for (size_t i = 0; i < screens->count; i++) {
+ if ((ds = (PCPDynamicScreen*)Hashtable_get(screens->table, i)) == NULL)
+ continue;
+ if (String_eq(ss->dynamic, ds->super.name) == false)
+ continue;
+ ss->table = &ds->table->super;
+ }
+}
+
+void PCPDynamicScreens_addAvailableColumns(Panel* availableColumns, Hashtable* screens, const char* screen) {
+ Vector_prune(availableColumns->items);
+
+ bool success;
+ unsigned int key;
+ success = DynamicScreen_search(screens, screen, &key);
+ if (!success)
+ return;
+
+ PCPDynamicScreen* dynamicScreen = Hashtable_get(screens, key);
+ if (!screen)
+ return;
+
+ for (unsigned int j = 0; j < dynamicScreen->totalColumns; j++) {
+ PCPDynamicColumn* column = dynamicScreen->columns[j];
+ const char* title = column->super.heading ? column->super.heading : column->super.name;
+ const char* text = column->super.description ? column->super.description : column->super.caption;
+ char description[256];
+ if (text)
+ xSnprintf(description, sizeof(description), "%s - %s", title, text);
+ else
+ xSnprintf(description, sizeof(description), "%s", title);
+ Panel_add(availableColumns, (Object*) ListItem_new(description, j));
+ }
+}
diff --git a/pcp/PCPDynamicScreen.h b/pcp/PCPDynamicScreen.h
new file mode 100644
index 00000000..73535925
--- /dev/null
+++ b/pcp/PCPDynamicScreen.h
@@ -0,0 +1,56 @@
+#ifndef HEADER_PCPDynamicScreen
+#define HEADER_PCPDynamicScreen
+/*
+htop - PCPDynamicScreen.h
+(C) 2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include <stddef.h>
+#include <stdbool.h>
+
+#include "CRT.h"
+#include "DynamicScreen.h"
+#include "Hashtable.h"
+#include "Machine.h"
+#include "Panel.h"
+#include "Settings.h"
+
+
+struct InDomTable_;
+struct PCPDynamicColumn_;
+struct PCPDynamicColumns_;
+
+typedef struct PCPDynamicScreen_ {
+ DynamicScreen super;
+
+ struct InDomTable_ *table;
+ struct PCPDynamicColumn_** columns;
+ size_t totalColumns;
+
+ unsigned int indom; /* instance domain number */
+ unsigned int key; /* PCPMetric identifier */
+
+ bool defaultEnabled; /* enabled setting from configuration file */
+ /* at runtime enabled screens have entries in settings->screens */
+} PCPDynamicScreen;
+
+typedef struct PCPDynamicScreens_ {
+ Hashtable* table;
+ size_t count; /* count of dynamic screens discovered from scan */
+} PCPDynamicScreens;
+
+void PCPDynamicScreens_init(PCPDynamicScreens* screens, struct PCPDynamicColumns_* columns);
+
+void PCPDynamicScreens_done(Hashtable* table);
+
+void PCPDynamicScreen_appendTables(PCPDynamicScreens* screens, Machine* host);
+
+void PCPDynamicScreen_appendScreens(PCPDynamicScreens* screens, Settings* settings);
+
+void PCPDynamicScreen_addDynamicScreen(PCPDynamicScreens* screens, ScreenSettings* ss);
+
+void PCPDynamicScreens_addAvailableColumns(Panel* availableColumns, Hashtable* screens, const char* screen);
+
+#endif
diff --git a/pcp/PCPMachine.c b/pcp/PCPMachine.c
index 59e05624..726218d9 100644
--- a/pcp/PCPMachine.c
+++ b/pcp/PCPMachine.c
@@ -307,6 +307,8 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
this->cpu = xCalloc(CPU_METRIC_COUNT, sizeof(pmAtomValue));
PCPMachine_updateCPUcount(this);
+ Platform_updateTables(super);
+
return super;
}
diff --git a/pcp/PCPMetric.c b/pcp/PCPMetric.c
index 606a5df0..ebb453d3 100644
--- a/pcp/PCPMetric.c
+++ b/pcp/PCPMetric.c
@@ -10,6 +10,7 @@ in the source distribution for its full text.
#include "pcp/PCPMetric.h"
+#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -178,3 +179,21 @@ bool PCPMetric_fetch(struct timeval* timestamp) {
*timestamp = pcp->result->timestamp;
return true;
}
+
+void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName) {
+ const pmDesc* desc = &pcp->descs[metric];
+ pmNameInDom(desc->indom, inst, externalName);
+}
+
+int PCPMetric_lookupText(const char* metric, char** desc) {
+ pmID pmid;
+ int sts;
+
+ sts = pmLookupName(1, &metric, &pmid);
+ if (sts < 0)
+ return sts;
+
+ if (pmLookupText(pmid, PM_TEXT_ONELINE, desc) >= 0)
+ (*desc)[0] = toupper((*desc)[0]); /* UI consistency */
+ return 0;
+}
diff --git a/pcp/PCPMetric.h b/pcp/PCPMetric.h
index e89a0a4c..b53b82de 100644
--- a/pcp/PCPMetric.h
+++ b/pcp/PCPMetric.h
@@ -180,4 +180,8 @@ int PCPMetric_instanceOffset(PCPMetric metric, int inst);
pmAtomValue* PCPMetric_instance(PCPMetric metric, int inst, int offset, pmAtomValue* atom, int type);
+void PCPMetric_externalName(PCPMetric metric, int inst, char** externalName);
+
+int PCPMetric_lookupText(const char* metric, char** desc);
+
#endif
diff --git a/pcp/Platform.c b/pcp/Platform.c
index 87a2ec1f..53336197 100644
--- a/pcp/Platform.c
+++ b/pcp/Platform.c
@@ -25,6 +25,7 @@ in the source distribution for its full text.
#include "DiskIOMeter.h"
#include "DynamicColumn.h"
#include "DynamicMeter.h"
+#include "DynamicScreen.h"
#include "FileDescriptorMeter.h"
#include "HostnameMeter.h"
#include "LoadAverageMeter.h"
@@ -46,6 +47,7 @@ in the source distribution for its full text.
#include "linux/ZramStats.h"
#include "pcp/PCPDynamicColumn.h"
#include "pcp/PCPDynamicMeter.h"
+#include "pcp/PCPDynamicScreen.h"
#include "pcp/PCPMachine.h"
#include "pcp/PCPMetric.h"
#include "pcp/PCPProcessList.h"
@@ -355,6 +357,7 @@ bool Platform_init(void) {
pcp->columns.offset = PCP_METRIC_COUNT + pcp->meters.cursor;
PCPDynamicColumns_init(&pcp->columns);
+ PCPDynamicScreens_init(&pcp->screens, &pcp->columns);
sts = pmLookupName(pcp->totalMetrics, pcp->names, pcp->pmids);
if (sts < 0) {
@@ -386,6 +389,7 @@ bool Platform_init(void) {
PCPMetric_enable(PCP_UNAME_MACHINE, true);
PCPMetric_enable(PCP_UNAME_DISTRO, true);
+ /* enable metrics for all dynamic columns (including those from dynamic screens) */
for (size_t i = pcp->columns.offset; i < pcp->columns.offset + pcp->columns.count; i++)
PCPMetric_enable(i, true);
@@ -417,6 +421,10 @@ void Platform_dynamicMetersDone(Hashtable* meters) {
PCPDynamicMeters_done(meters);
}
+void Platform_dynamicScreensDone(Hashtable* screens) {
+ PCPDynamicScreens_done(screens);
+}
+
void Platform_done(void) {
pmDestroyContext(pcp->context);
if (pcp->result)
@@ -850,7 +858,7 @@ Hashtable* Platform_dynamicColumns(void) {
return pcp->columns.table;
}
-const char* Platform_dynamicColumnInit(unsigned int key) {
+const char* Platform_dynamicColumnName(unsigned int key) {
PCPDynamicColumn* this = Hashtable_get(pcp->columns.table, key);
if (this) {
PCPMetric_enable(this->id, true);
@@ -871,3 +879,25 @@ bool Platform_dynamicColumnWriteField(const Process* proc, RichString* str, unsi
}
return false;
}
+
+Hashtable* Platform_dynamicScreens(void) {
+ return pcp->screens.table;
+}
+
+void Platform_defaultDynamicScreens(Settings* settings) {
+ PCPDynamicScreen_appendScreens(&pcp->screens, settings);
+}
+
+void Platform_addDynamicScreen(ScreenSettings* ss) {
+ PCPDynamicScreen_addDynamicScreen(&pcp->screens, ss);
+}
+
+void Platform_addDynamicScreenAvailableColumns(Panel* availableColumns, const char* screen) {
+ Hashtable* screens = pcp->screens.table;
+ PCPDynamicScreens_addAvailableColumns(availableColumns, screens, screen);
+}
+
+void Platform_updateTables(Machine* host) {
+ PCPDynamicScreen_appendTables(&pcp->screens, host);
+ PCPDynamicColumns_setupWidths(&pcp->columns);
+}
diff --git a/pcp/Platform.h b/pcp/Platform.h
index f90e2813..f2e8a49d 100644
--- a/pcp/Platform.h
+++ b/pcp/Platform.h
@@ -38,6 +38,7 @@ in the source distribution for its full text.
#include "pcp/PCPDynamicColumn.h"
#include "pcp/PCPDynamicMeter.h"
+#include "pcp/PCPDynamicScreen.h"
#include "pcp/PCPMetric.h"
@@ -51,6 +52,7 @@ typedef struct Platform_ {
pmResult* result; /* sample values result indexed by Metric */
PCPDynamicMeters meters; /* dynamic meters via configuration files */
PCPDynamicColumns columns; /* dynamic columns via configuration files */
+ PCPDynamicScreens screens; /* dynamic screens via configuration files */
struct timeval offset; /* time offset used in archive mode only */
long long btime; /* boottime in seconds since the epoch */
char* release; /* uname and distro from this context */
@@ -151,8 +153,20 @@ Hashtable* Platform_dynamicColumns(void);
void Platform_dynamicColumnsDone(Hashtable* columns);
-const char* Platform_dynamicColumnInit(unsigned int key);
+const char* Platform_dynamicColumnName(unsigned int key);
bool Platform_dynamicColumnWriteField(const Process* proc, RichString* str, unsigned int key);
+Hashtable* Platform_dynamicScreens(void);
+
+void Platform_defaultDynamicScreens(Settings* settings);
+
+void Platform_addDynamicScreen(ScreenSettings* ss);
+
+void Platform_addDynamicScreenAvailableColumns(Panel* availableColumns, const char* screen);
+
+void Platform_dynamicScreensDone(Hashtable* screens);
+
+void Platform_updateTables(Machine* host);
+
#endif
diff --git a/pcp/screens/biosnoop b/pcp/screens/biosnoop
new file mode 100644
index 00000000..e6cdf894
--- /dev/null
+++ b/pcp/screens/biosnoop
@@ -0,0 +1,41 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[biosnoop]
+heading = BioSnoop
+caption = BPF block I/O snoop
+default = false
+
+pid.heading = PID
+pid.caption = Process identifier
+pid.metric = bpf.biosnoop.pid
+pid.format = process
+
+disk.heading = DISK
+disk.caption = Device name
+disk.width = -7
+disk.metric = bpf.biosnoop.disk
+
+rwbs.heading = TYPE
+rwbs.caption = I/O type string
+rwbs.width = -4
+rwbs.metric = bpf.biosnoop.rwbs
+
+bytes.heading = BYTES
+bytes.caption = I/O size in bytes
+bytes.metric = bpf.biosnoop.bytes
+
+lat.heading = LAT
+lat.caption = I/O latency
+lat.metric = bpf.biosnoop.lat
+
+sector.heading = SECTOR
+sector.caption = Device sector
+sector.metric = bpf.biosnoop.sector
+
+comm.heading = Command
+comm.caption = Process command name
+comm.width = -16
+comm.metric = bpf.biosnoop.comm
+comm.format = process
diff --git a/pcp/screens/cgroups b/pcp/screens/cgroups
new file mode 100644
index 00000000..0ddc65c4
--- /dev/null
+++ b/pcp/screens/cgroups
@@ -0,0 +1,45 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[cgroups]
+heading = CGroups
+caption = Control Groups
+default = true
+
+user_cpu.heading = UTIME
+user_cpu.caption = User CPU Time
+user_cpu.metric = 1000 * rate(cgroup.cpu.stat.user)
+user_cpu.width = 6
+
+system_cpu.heading = STIME
+system_cpu.caption = Kernel CPU Time
+system_cpu.metric = 1000 * rate(cgroup.cpu.stat.system)
+system_cpu.width = 6
+
+cpu_usage.heading = CPU%
+cpu_usage.caption = CPU Utilization
+cpu_usage.metric = 100 * (rate(cgroup.cpu.stat.usage) / hinv.ncpu)
+cpu_usage.format = percent
+
+cpu_psi.heading = CPU-PSI
+cpu_psi.caption = CPU Pressure Stall Information
+cpu_psi.metric = 1000 * rate(cgroup.pressure.cpu.some.total)
+cpu_psi.width = 7
+
+mem_psi.heading = MEM-PSI
+mem_psi.caption = Memory Pressure Stall Information
+mem_psi.metric = 1000 * rate(cgroup.pressure.memory.some.total)
+mem_psi.width = 7
+
+io_psi.heading = I/O-PSI
+io_psi.caption = I/O Pressure Stall Information
+io_psi.metric = 1000 * rate(cgroup.pressure.io.some.total)
+io_psi.width = 7
+
+name.heading = Control group
+name.caption = Control group name
+name.width = -64
+name.metric = cgroup.cpu.stat.system
+name.instances = true
+name.format = cgroup
diff --git a/pcp/screens/cgroupsio b/pcp/screens/cgroupsio
new file mode 100644
index 00000000..3a431db5
--- /dev/null
+++ b/pcp/screens/cgroupsio
@@ -0,0 +1,49 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[cgroupsio]
+heading = CGroupsIO
+caption = Control Groups I/O
+default = false
+
+iops.heading = IOPS
+iops.caption = I/O operations
+iops.metric = rate(cgroup.io.stat.rios) + rate(cgroup.io.stat.wios) + rate(cgroup.io.stat.dios)
+
+readops.heading = RDIO
+readops.caption = Read operations
+readops.metric = rate(cgroup.io.stat.rios)
+readops.default = false
+
+writeops.heading = WRIO
+writeops.caption = Write operations
+writeops.metric = rate(cgroup.io.stat.wios)
+writeops.default = false
+
+directops.heading = DIO
+directops.caption = Direct I/O operations
+directops.metric = rate(cgroup.io.stat.dios)
+directops.default = false
+
+totalbytes.heading = R/W/D
+totalbytes.caption = Disk throughput
+totalbytes.metric = rate(cgroup.io.stat.rbytes) + rate(cgroup.io.stat.wbytes) + rate(cgroup.io.stat.dbytes)
+
+readbytes.heading = RBYTE
+readbytes.caption = Disk read throughput
+readbytes.metric = rate(cgroup.io.stat.rbytes)
+
+writebytes.heading = WBYTE
+writebytes.caption = Disk throughput
+writebytes.metric = rate(cgroup.io.stat.wbytes)
+
+directio.heading = DBYTE
+directio.caption = Direct I/O throughput
+directio.metric = rate(cgroup.io.stat.dbytes)
+
+name.heading = Control group device
+name.caption = Control group device
+name.width = -64
+name.metric = cgroup.io.stat.rbytes
+name.instances = true
diff --git a/pcp/screens/cgroupsmem b/pcp/screens/cgroupsmem
new file mode 100644
index 00000000..17bc1e38
--- /dev/null
+++ b/pcp/screens/cgroupsmem
@@ -0,0 +1,48 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[cgroupsmem]
+heading = CGroupsMem
+caption = Control Groups Memory
+default = false
+
+current.heading = MEM
+current.caption = Current memory
+current.metric = cgroup.memory.current
+
+usage.heading = USAGE
+usage.caption = Memory usage
+usage.metric = cgroup.memory.usage
+
+container.heading = CONTAINER
+container.caption = Container Name
+container.metric = cgroup.memory.id.container
+
+resident.heading = RSS
+resident.metric = cgroup.memory.stat.rss
+
+cresident.heading = CRSS
+cresident.metric = cgroup.memory.stat.total.rss
+
+anonmem.heading = ANON
+anonmem.metric = cgroup.memory.stat.anon
+
+filemem.heading = FILE
+filemem.metric = cgroup.memory.stat.file
+
+shared.heading = SHMEM
+shared.metric = cgroup.memory.stat.shmem
+
+swap.heading = SWAP
+swap.metric = cgroup.memory.stat.swap
+
+pgfault.heading = FAULTS
+pgfault.metric = cgroup.memory.stat.pgfaults
+
+name.heading = Control group
+name.caption = Control group name
+name.width = -64
+name.metric = cgroup.memory.current
+name.instances = true
+name.format = cgroup
diff --git a/pcp/screens/devices b/pcp/screens/devices
new file mode 100644
index 00000000..f9f6bc0c
--- /dev/null
+++ b/pcp/screens/devices
@@ -0,0 +1,114 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[disks]
+heading = Disks
+caption = Disk devices
+
+diskdev.heading = Device
+diskdev.metric = disk.dev.read
+diskdev.instances = true
+diskdev.format = device
+diskdev.width = -8
+
+total.heading = TPS
+total.metric = rate(disk.dev.read) + rate(disk.dev.write) + rate(disk.dev.discard)
+total.caption = Rate of read requests
+
+read.heading = RR/S
+read.metric = rate(disk.dev.read)
+read.caption = Rate of read requests
+
+read_bytes.heading = RRB/S
+read_bytes.metric = rate(disk.dev.read_bytes)
+read_bytes.caption = Read throughput from the device
+
+read_merge.heading = RRQM/S
+read_merge.metric = rate(disk.dev.read_merge)
+read_merge.caption = Rate reads merged before queued
+read_merge.default = false
+
+read_merge_pct.heading = RRQM%
+read_merge_pct.metric = 100 * rate(disk.dev.read_merge) / rate(disk.dev.read)
+read_merge_pct.caption = Percentage reads merged before queued
+read_merge_pct.format = percent
+
+read_await.heading = RAWAIT
+read_await.metric = disk.dev.r_await
+read_await.default = false
+
+read_avqsz.heading = RARQSZ
+read_avqsz.metric = disk.dev.r_avg_rqsz
+read_avqsz.default = false
+
+write.heading = WR/S
+write.metric = rate(disk.dev.write)
+write.caption = Rate of write requests
+
+write_bytes.heading = WRB/S
+write_bytes.metric = rate(disk.dev.write_bytes)
+write_bytes.caption = Write throughput to the device
+
+write_merge.heading = WRQM/S
+write_merge.metric = rate(disk.dev.write_merge)
+write_merge.caption = Rate writes merged before queued
+write_merge.default = false
+
+write_merge_pct.heading = WRQM%
+write_merge_pct.metric = 100 * rate(disk.dev.write_merge) / rate(disk.dev.write)
+write_merge_pct.caption = Percentage writes merged before queued
+write_merge_pct.format = percent
+
+write_await.heading = WAWAIT
+write_await.metric = disk.dev.w_await
+write_await.default = false
+
+write_avqsz.heading = WARQSZ
+write_avqsz.metric = disk.dev.w_avg_rqsz
+write_avqsz.default = false
+
+discard.heading = DR/S
+discard.metric = rate(disk.dev.discard)
+discard.caption = Rate of discard requests
+
+discard_bytes.heading = DRB/S
+discard_bytes.metric = rate(disk.dev.discard_bytes)
+discard_bytes.caption = Discard request throughput
+discard_bytes.default = false
+
+discard_merge.heading = DRQM/S
+discard_merge.metric = rate(disk.dev.discard_merge)
+discard_merge.caption = Rate discards merged before queued
+discard_merge.default = false
+
+discard_merge_pct.heading = DRQM%
+discard_merge_pct.metric = 100 * rate(disk.dev.discard_merge) / rate(disk.dev.discard)
+discard_merge_pct.caption = Percentage discards merged before queued
+discard_merge_pct.format = percent
+discard_merge_pct.default = false
+
+discard_await.heading = DAWAIT
+discard_await.metric = disk.dev.d_await
+discard_await.default = false
+
+discard_avqsz.heading = DARQSZ
+discard_avqsz.metric = disk.dev.d_avg_rqsz
+discard_avqsz.default = false
+
+flush.heading = F/S
+flush.metric = rate(disk.dev.flush)
+flush.default = false
+flush.caption = Flushes per second
+
+flush_await.heading = FAWAIT
+flush_await.metric = disk.dev.f_await
+flush_await.default = false
+
+qlen.heading = AQU-SZ
+qlen.metric = disk.dev.avg_qlen
+
+util.heading = UTIL%
+util.metric = 100 * disk.dev.util
+util.caption = Perentage device utilitization
+util.format = percent
diff --git a/pcp/screens/execsnoop b/pcp/screens/execsnoop
new file mode 100644
index 00000000..d706e764
--- /dev/null
+++ b/pcp/screens/execsnoop
@@ -0,0 +1,37 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[execsnoop]
+heading = ExecSnoop
+caption = BPF exec(2) syscall snoop
+default = false
+
+pid.heading = PID
+pid.caption = Process Identifier
+pid.metric = bpf.execsnoop.pid
+pid.format = process
+
+ppid.heading = PPID
+ppid.caption = Parent Process
+ppid.metric = bpf.execsnoop.ppid
+ppid.format = process
+
+uid.heading = UID
+uid.caption = User Identifier
+uid.metric = bpf.execsnoop.uid
+
+comm.heading = COMM
+comm.caption = Command
+comm.width = -16
+comm.metric = bpf.execsnoop.comm
+comm.format = command
+
+ret.heading = RET
+ret.caption = Return Code
+ret.metric = bpf.execsnoop.ret
+
+path.heading = Arguments
+path.caption = Arguments
+path.width = -12
+path.metric = bpf.execsnoop.args
diff --git a/pcp/screens/exitsnoop b/pcp/screens/exitsnoop
new file mode 100644
index 00000000..6c6b867c
--- /dev/null
+++ b/pcp/screens/exitsnoop
@@ -0,0 +1,48 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[exitsnoop]
+heading = ExitSnoop
+caption = BPF process exit(2) snoop
+default = false
+
+pid.heading = PID
+pid.caption = Process Identifier
+pid.metric = bpf.exitsnoop.pid
+pid.format = process
+
+ppid.heading = PPID
+ppid.caption = Parent Process
+ppid.metric = bpf.exitsnoop.ppid
+ppid.format = process
+
+tid.heading = TID
+tid.caption = Task Identifier
+tid.metric = bpf.exitsnoop.tid
+tid.format = process
+tid.default = false
+
+signal.heading = SIG
+signal.caption = Signal number
+signal.metric = bpf.exitsnoop.sig
+
+exit.heading = EXIT
+exit.caption = Exit Code
+exit.metric = bpf.exitsnoop.exit_code
+
+core.heading = CORE
+core.caption = Dumped core
+core.metric = bpf.exitsnoop.coredump
+core.default = false
+
+age.heading = AGE
+age.caption = Process age
+age.metric = bpf.exitsnoop.age
+age.default = false
+
+comm.heading = Command
+comm.caption = COMM
+comm.width = -16
+comm.metric = bpf.exitsnoop.comm
+comm.format = command
diff --git a/pcp/screens/filesystems b/pcp/screens/filesystems
new file mode 100644
index 00000000..06f3bf23
--- /dev/null
+++ b/pcp/screens/filesystems
@@ -0,0 +1,50 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[filesystems]
+heading = Filesystems
+caption = Mounted block device filesystems
+
+blockdev.heading = Device
+blockdev.metric = filesys.mountdir
+blockdev.instances = true
+blockdev.width = -14
+
+blocksize.heading = BSIZE
+blocksize.metric = filesys.blocksize
+blocksize.default = false
+
+capacity.heading = SIZE
+capacity.metric = filesys.capacity
+
+used.heading = USED
+used.metric = filesys.used
+
+free.heading = FREE
+free.metric = filesys.free
+free.default = false
+
+avail.heading = AVAIL
+avail.metric = filesys.avail
+
+full.heading = USE%
+full.metric = filesys.full
+full.format = percent
+
+usedfiles.heading = USEDF
+usedfiles.metric = filesys.usedfiles
+usedfiles.default = false
+
+freefiles.heading = FREEF
+freefiles.metric = filesys.freefiles
+freefiles.default = false
+
+maxfiles.heading = MAXF
+maxfiles.metric = filesys.maxfiles
+maxfiles.default = false
+
+mountdir.heading = Mount point
+mountdir.metric = filesys.mountdir
+mountdir.format = path
+mountdir.width = -33
diff --git a/pcp/screens/opensnoop b/pcp/screens/opensnoop
new file mode 100644
index 00000000..ec209b03
--- /dev/null
+++ b/pcp/screens/opensnoop
@@ -0,0 +1,27 @@
+#
+# pcp-htop(1) configuration file - see pcp-htop(5)
+#
+
+[opensnoop]
+heading = OpenSnoop
+caption = BPF open(2) syscall snoop
+default = false
+
+pid.heading = PID
+pid.metric = bpf.opensnoop.pid
+pid.format = process
+
+comm.heading = COMM
+comm.metric = bpf.opensnoop.comm
+comm.format = command
+
+fd.heading = FD
+fd.metric = bpf.opensnoop.fd
+
+err.heading = ERR
+err.metric = bpf.opensnoop.err
+
+file.heading = File name
+file.width = -32
+file.metric = bpf.opensnoop.fname
+file.format = path
diff --git a/solaris/Platform.h b/solaris/Platform.h
index 3dc6e3b5..00bc5832 100644
--- a/solaris/Platform.h
+++ b/solaris/Platform.h
@@ -150,7 +150,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -158,4 +158,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif
diff --git a/unsupported/Platform.h b/unsupported/Platform.h
index a718ca09..8e08dc23 100644
--- a/unsupported/Platform.h
+++ b/unsupported/Platform.h
@@ -98,7 +98,7 @@ static inline Hashtable* Platform_dynamicColumns(void) {
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
-static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) {
+static inline const char* Platform_dynamicColumnName(ATTR_UNUSED unsigned int key) {
return NULL;
}
@@ -106,4 +106,16 @@ static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* p
return false;
}
+static inline Hashtable* Platform_dynamicScreens(void) {
+ return NULL;
+}
+
+static inline void Platform_defaultDynamicScreens(ATTR_UNUSED Settings* settings) { }
+
+static inline void Platform_addDynamicScreen(ATTR_UNUSED ScreenSettings* ss) { }
+
+static inline void Platform_addDynamicScreenAvailableColumns(ATTR_UNUSED Panel* availableColumns, ATTR_UNUSED const char* screen) { }
+
+static inline void Platform_dynamicScreensDone(ATTR_UNUSED Hashtable* screens) { }
+
#endif

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