summaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorSohaib Mohamed <sohaib.amhmd@gmail.com>2021-07-11 03:11:29 +0200
committerNathan Scott <nathans@redhat.com>2021-08-13 07:32:57 +0200
commit6f2021f3d95e02fc54e59fdeeb006e34c209b9c3 (patch)
treea31ea1264b871e5a7e7785398a382a7813eb1749 /ProcessList.c
parented82ce6456f0f904a0ab2b346b85d7cf46df109c (diff)
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot metrics with per-process instance domains to form new htop columns. The column-to-metric mappings are setup using configuration files which will be documented via man pages as part of a follow-up commit. We provide an initial set of column configurations so as to provide new capabilities to pcp-htop: including configs for containers, open fd counts, scheduler run queue time, tcp/udp bytes/calls sent/recv, delay acct, virtual machine guests, detailed virtual memory, swap. Note there is a change to the configuration file path resolution algorithm introduced for 'dynamic meters'. First, look in any custom PCP_HTOP_DIR location. Then iterate, in priority order, users home directory, then local sysadmins files in /etc/pcp/htop, then readonly configuration files below /usr/share/pcp/htop. This final location becomes the preferred place for our own shipped meter and column files. The Settings file (htoprc) writing code is updated to not using the numeric identifier for dynamic columns. The same strategy used for dynamic meters is used here where we write Dynamic(name) so the name can be setup once more at start. Regular (static) columns writing to htoprc - i.e. numerically indexed - is unchanged.
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 8ab4d8f6..daf871a7 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include <string.h>
#include "CRT.h"
+#include "DynamicColumn.h"
#include "Hashtable.h"
#include "Macros.h"
#include "Platform.h"
@@ -19,7 +20,7 @@ in the source distribution for its full text.
#include "XUtils.h"
-ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* pidMatchList, uid_t userId) {
+ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* dynamicMeters, Hashtable* dynamicColumns, Hashtable* pidMatchList, uid_t userId) {
this->processes = Vector_new(klass, true, DEFAULT_SIZE);
this->processes2 = Vector_new(klass, true, DEFAULT_SIZE); // tree-view auxiliary buffer
@@ -30,6 +31,7 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users
this->usersTable = usersTable;
this->pidMatchList = pidMatchList;
this->dynamicMeters = dynamicMeters;
+ this->dynamicColumns = dynamicColumns;
this->userId = userId;
@@ -83,7 +85,22 @@ void ProcessList_setPanel(ProcessList* this, Panel* panel) {
this->panel = panel;
}
-static const char* alignedProcessFieldTitle(ProcessField field) {
+static const char* alignedDynamicColumnTitle(const ProcessList* this, int key) {
+ const DynamicColumn* column = Hashtable_get(this->dynamicColumns, key);
+ if (column == NULL)
+ return "- ";
+ static char titleBuffer[DYNAMIC_MAX_COLUMN_WIDTH + /* space */ 1 + /* null terminator */ + 1];
+ int width = column->width;
+ if (!width || abs(width) > DYNAMIC_MAX_COLUMN_WIDTH)
+ width = DYNAMIC_DEFAULT_COLUMN_WIDTH;
+ xSnprintf(titleBuffer, sizeof(titleBuffer), "%*s", width, column->heading);
+ return titleBuffer;
+}
+
+static const char* alignedProcessFieldTitle(const ProcessList* this, ProcessField field) {
+ if (field >= LAST_PROCESSFIELD)
+ return alignedDynamicColumnTitle(this, field);
+
const char* title = Process_fields[field].title;
if (!title)
return "- ";
@@ -115,7 +132,7 @@ void ProcessList_printHeader(const ProcessList* this, RichString* header) {
color = CRT_colors[PANEL_HEADER_FOCUS];
}
- RichString_appendWide(header, color, alignedProcessFieldTitle(fields[i]));
+ RichString_appendWide(header, color, alignedProcessFieldTitle(this, fields[i]));
if (key == fields[i] && RichString_getCharVal(*header, RichString_size(header) - 1) == ' ') {
RichString_rewind(header, 1); // rewind to override space
RichString_appendnWide(header,
@@ -478,7 +495,7 @@ ProcessField ProcessList_keyAt(const ProcessList* this, int at) {
const ProcessField* fields = this->settings->fields;
ProcessField field;
for (int i = 0; (field = fields[i]); i++) {
- int len = strlen(alignedProcessFieldTitle(field));
+ int len = strlen(alignedProcessFieldTitle(this, field));
if (at >= x && at <= x + len) {
return field;
}

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