diff options
author | Sohaib Mohamed <sohaib.amhmd@gmail.com> | 2023-08-22 16:46:59 +1000 |
---|---|---|
committer | Nathan Scott <nathans@redhat.com> | 2023-08-30 13:11:57 +1000 |
commit | 53bdcab942298e0e452d62237bc18e3a4cd551cf (patch) | |
tree | e7a62910b9f4a1a58560a4ded2e6f7e83d0b631e /AvailableColumnsPanel.c | |
parent | 0f751e991d399769fb8d7800f7c4bccec2ca7f60 (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>
Diffstat (limited to 'AvailableColumnsPanel.c')
-rw-r--r-- | AvailableColumnsPanel.c | 48 |
1 files changed, 34 insertions, 14 deletions
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; } |