summaryrefslogtreecommitdiffstats
path: root/DynamicScreen.c
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 /DynamicScreen.c
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>
Diffstat (limited to 'DynamicScreen.c')
-rw-r--r--DynamicScreen.c65
1 files changed, 65 insertions, 0 deletions
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;
+}

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