summaryrefslogtreecommitdiffstats
path: root/DynamicColumn.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 /DynamicColumn.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 'DynamicColumn.c')
-rw-r--r--DynamicColumn.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/DynamicColumn.c b/DynamicColumn.c
new file mode 100644
index 00000000..62b38238
--- /dev/null
+++ b/DynamicColumn.c
@@ -0,0 +1,60 @@
+/*
+htop - DynamicColumn.c
+(C) 2021 Sohaib Mohammed
+(C) 2021 htop dev team
+(C) 2021 Red Hat, Inc. All Rights Reserved.
+Released under the GNU GPLv2, see the COPYING file
+in the source distribution for its full text.
+*/
+
+#include "config.h" // IWYU pragma: keep
+
+#include "DynamicColumn.h"
+
+#include <stddef.h>
+
+#include "Platform.h"
+#include "ProcessList.h"
+#include "RichString.h"
+#include "XUtils.h"
+
+
+Hashtable* DynamicColumns_new(void) {
+ return Platform_dynamicColumns();
+}
+
+const char* DynamicColumn_init(unsigned int key) {
+ return Platform_dynamicColumnInit(key);
+}
+
+typedef struct {
+ const char* name;
+ const DynamicColumn* data;
+ unsigned int key;
+} DynamicIterator;
+
+static void DynamicColumn_compare(ht_key_t key, void* value, void* data) {
+ const DynamicColumn* column = (const DynamicColumn*)value;
+ DynamicIterator* iter = (DynamicIterator*)data;
+ if (String_eq(iter->name, column->name)) {
+ iter->data = column;
+ iter->key = key;
+ }
+}
+
+const DynamicColumn* DynamicColumn_search(Hashtable* dynamics, const char* name, unsigned int* key) {
+ DynamicIterator iter = { .key = 0, .data = NULL, .name = name };
+ if (dynamics)
+ Hashtable_foreach(dynamics, DynamicColumn_compare, &iter);
+ if (key)
+ *key = iter.key;
+ return iter.data;
+}
+
+const DynamicColumn* DynamicColumn_lookup(Hashtable* dynamics, unsigned int key) {
+ return (const DynamicColumn*) Hashtable_get(dynamics, key);
+}
+
+bool DynamicColumn_writeField(const Process* proc, RichString* str, unsigned int key) {
+ return Platform_dynamicColumnWriteField(proc, str, key);
+}

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