diff options
author | Benny Baumann <BenBE@geshi.org> | 2023-11-20 22:58:23 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-12-11 09:35:48 +0100 |
commit | d5b155649724644e0e91e345baf34a2dd8652f3f (patch) | |
tree | 2d6dc28bc4c7e115852883a11444ecc1ca72c357 /linux | |
parent | 1069e069ab43029f7ac7e0e6b87a907c6d1f2cf0 (diff) |
Add column for process container name
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LinuxProcess.c | 5 | ||||
-rw-r--r-- | linux/LinuxProcess.h | 1 | ||||
-rw-r--r-- | linux/LinuxProcessTable.c | 21 | ||||
-rw-r--r-- | linux/ProcessField.h | 3 |
4 files changed, 29 insertions, 1 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8c11f23a..4655d91b 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -82,6 +82,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [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, .autoWidth = true, }, [CCGROUP] = { .name = "CCGROUP", .title = "CGROUP (compressed)", .description = "Which cgroup the process is in (condensed to essentials)", .flags = PROCESS_FLAG_LINUX_CGROUP, .autoWidth = true, }, + [CONTAINER] = { .name = "CONTAINER", .title = "CONTAINER", .description = "Name of the container the process is in (guessed by heuristics)", .flags = PROCESS_FLAG_LINUX_CGROUP, .autoWidth = true, }, [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, .defaultSortDesc = true, }, [IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, }, #ifdef HAVE_DELAYACCT @@ -114,6 +115,7 @@ Process* LinuxProcess_new(const Machine* host) { void Process_delete(Object* cast) { LinuxProcess* this = (LinuxProcess*) cast; Process_done((Process*)cast); + free(this->container_short); free(this->cgroup_short); free(this->cgroup); #ifdef HAVE_OPENVZ @@ -271,6 +273,7 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces #endif case CGROUP: xSnprintf(buffer, n, "%-*.*s ", Row_fieldWidths[CGROUP], Row_fieldWidths[CGROUP], lp->cgroup ? lp->cgroup : "N/A"); break; case CCGROUP: xSnprintf(buffer, n, "%-*.*s ", Row_fieldWidths[CCGROUP], Row_fieldWidths[CCGROUP], lp->cgroup_short ? lp->cgroup_short : (lp->cgroup ? lp->cgroup : "N/A")); break; + case CONTAINER: xSnprintf(buffer, n, "%-*.*s ", Row_fieldWidths[CONTAINER], Row_fieldWidths[CONTAINER], lp->container_short ? lp->container_short : "N/A"); break; case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break; case IO_PRIORITY: { int klass = IOPriority_class(lp->ioPriority); @@ -391,6 +394,8 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce 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); #ifdef HAVE_DELAYACCT diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index d4d67cb5..6419c04a 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -91,6 +91,7 @@ typedef struct LinuxProcess_ { #endif char* cgroup; char* cgroup_short; + char* container_short; unsigned int oom; #ifdef HAVE_DELAYACCT unsigned long long int delay_read_time; diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c index 293925a1..a4eb0264 100644 --- a/linux/LinuxProcessTable.c +++ b/linux/LinuxProcessTable.c @@ -847,6 +847,10 @@ static void LinuxProcessTable_readCGroupFile(LinuxProcess* process, openat_arg_t free(process->cgroup_short); process->cgroup_short = NULL; } + if (process->container_short) { + free(process->container_short); + process->container_short = NULL; + } return; } char output[PROC_LINE_LENGTH + 1]; @@ -892,6 +896,11 @@ static void LinuxProcessTable_readCGroupFile(LinuxProcess* process, openat_arg_t //CCGROUP is alias to normal CGROUP if shortening fails Row_updateFieldWidth(CCGROUP, strlen(process->cgroup)); } + if (process->container_short) { + Row_updateFieldWidth(CONTAINER, strlen(process->container_short)); + } else { + Row_updateFieldWidth(CONTAINER, strlen("N/A")); + } return; } @@ -906,6 +915,18 @@ static void LinuxProcessTable_readCGroupFile(LinuxProcess* process, openat_arg_t free(process->cgroup_short); process->cgroup_short = NULL; } + + char* container_short = CGroup_filterContainer(process->cgroup); + if (container_short) { + Row_updateFieldWidth(CONTAINER, strlen(container_short)); + free_and_xStrdup(&process->container_short, container_short); + free(container_short); + } else { + //CONTAINER is just "N/A" if shortening fails + Row_updateFieldWidth(CONTAINER, strlen("N/A")); + free(process->container_short); + process->container_short = NULL; + } } static void LinuxProcessTable_readOomData(LinuxProcess* process, openat_arg_t procFd) { diff --git a/linux/ProcessField.h b/linux/ProcessField.h index 9adaeacf..581a982e 100644 --- a/linux/ProcessField.h +++ b/linux/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 |