From e64adcb50bbd7a2817cbfa4e66c5ea2574eb7b2d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 27 Nov 2023 09:29:05 +0100 Subject: Add PCP support --- pcp/PCPProcess.c | 4 ++++ pcp/PCPProcess.h | 1 + pcp/PCPProcessTable.c | 14 ++++++++++++++ pcp/ProcessField.h | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'pcp') diff --git a/pcp/PCPProcess.c b/pcp/PCPProcess.c index af456bb1..df18b6f2 100644 --- a/pcp/PCPProcess.c +++ b/pcp/PCPProcess.c @@ -74,6 +74,7 @@ const ProcessFieldData Process_fields[] = { [IO_RATE] = { .name = "IO_RATE", .title = " DISK R/W ", .description = "Total I/O rate in bytes per second", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, }, [CGROUP] = { .name = "CGROUP", .title = "CGROUP (raw) ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, }, [CCGROUP] = { .name = "CCGROUP", .title = "CGROUP (compressed) ", .description = "Which cgroup the process is in (condensed to essentials)", .flags = PROCESS_FLAG_LINUX_CGROUP, }, + [CONTAINER] = { .name = "CONTAINER", .title = "CONTAINER ", .description = "Name of the container the process is in (guessed by heuristics)", .flags = PROCESS_FLAG_LINUX_CGROUP, }, [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, .defaultSortDesc = true, }, [PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .description = "CPU delay %", .flags = 0, .defaultSortDesc = true, }, [PERCENT_IO_DELAY] = { .name = "PERCENT_IO_DELAY", .title = " IOD% ", .description = "Block I/O delay %", .flags = 0, .defaultSortDesc = true, }, @@ -161,6 +162,7 @@ static void PCPProcess_rowWriteField(const Row* super, RichString* str, ProcessF case IO_RATE: Row_printRate(str, PCPProcess_totalIORate(pp), coloring); return; case CGROUP: xSnprintf(buffer, n, "%-35.35s ", pp->cgroup ? pp->cgroup : "N/A"); break; case CCGROUP: xSnprintf(buffer, n, "%-35.35s ", pp->cgroup_short ? pp->cgroup_short : (pp->cgroup ? pp->cgroup : "N/A")); break; + case CONTAINER: xSnprintf(buffer, n, "%-35.35s ", pp->container_short ? pp->container_short : "N/A"); break; case OOM: xSnprintf(buffer, n, "%4u ", pp->oom); break; case PERCENT_CPU_DELAY: PCPProcess_printDelay(pp->cpu_delay_percent, buffer, n); @@ -259,6 +261,8 @@ static int PCPProcess_compareByKey(const Process* v1, const Process* v2, Process return SPACESHIP_NULLSTR(p1->cgroup, p2->cgroup); case CCGROUP: return SPACESHIP_NULLSTR(p1->cgroup_short, p2->cgroup_short); + case CONTAINER: + return SPACESHIP_NULLSTR(p1->container_short, p2->container_short); case OOM: return SPACESHIP_NUMBER(p1->oom, p2->oom); case PERCENT_CPU_DELAY: diff --git a/pcp/PCPProcess.h b/pcp/PCPProcess.h index c7223b56..aed44eee 100644 --- a/pcp/PCPProcess.h +++ b/pcp/PCPProcess.h @@ -75,6 +75,7 @@ typedef struct PCPProcess_ { double io_rate_write_bps; char* cgroup; char* cgroup_short; + char* container_short; long int autogroup_id; int autogroup_nice; unsigned int oom; diff --git a/pcp/PCPProcessTable.c b/pcp/PCPProcessTable.c index 567ee1b7..07d5805d 100644 --- a/pcp/PCPProcessTable.c +++ b/pcp/PCPProcessTable.c @@ -267,9 +267,23 @@ static void PCPProcessTable_readCGroups(PCPProcess* pp, int pid, int offset) { free(pp->cgroup_short); pp->cgroup_short = NULL; } + + char* container_short = CGroup_filterName(pp->cgroup); + if (container_short) { + Row_updateFieldWidth(CONTAINER, strlen(container_short)); + free_and_xStrdup(&pp->container_short, container_short); + free(container_short); + } else { + Row_updateFieldWidth(CONTAINER, strlen("N/A")); + free(pp->container_short); + pp->container_short = NULL; + } } else { free(pp->cgroup_short); pp->cgroup_short = NULL; + + free(pp->container_short); + pp->container_short = NULL; } } diff --git a/pcp/ProcessField.h b/pcp/ProcessField.h index b2be9926..63425612 100644 --- a/pcp/ProcessField.h +++ b/pcp/ProcessField.h @@ -46,7 +46,8 @@ in the source distribution for its full text. AUTOGROUP_ID = 127, \ AUTOGROUP_NICE = 128, \ CCGROUP = 129, \ - M_PRIV = 130, \ + CONTAINER = 130, \ + M_PRIV = 131, \ // End of list -- cgit v1.2.3