summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-11-27 09:18:50 +1100
committerNathan Scott <nathans@redhat.com>2023-11-27 14:41:26 +1100
commit29137ccc7c83db98ada5c197b765a65a40b4e41f (patch)
tree327c9a0b5902f3d1d7d9064daa2791bd114ede7f
parent1d3a823d5d87c0966b3001f7ee18285e15506806 (diff)
PCP platform implementation of the compressed cgroup column
-rw-r--r--pcp/PCPProcess.c9
-rw-r--r--pcp/PCPProcess.h1
-rw-r--r--pcp/PCPProcessTable.c18
-rw-r--r--pcp/ProcessField.h1
4 files changed, 27 insertions, 2 deletions
diff --git a/pcp/PCPProcess.c b/pcp/PCPProcess.c
index b5483476..178e17fa 100644
--- a/pcp/PCPProcess.c
+++ b/pcp/PCPProcess.c
@@ -71,7 +71,8 @@ const ProcessFieldData Process_fields[] = {
[IO_READ_RATE] = { .name = "IO_READ_RATE", .title = " DISK READ ", .description = "The I/O rate of read(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
[IO_WRITE_RATE] = { .name = "IO_WRITE_RATE", .title = " DISK WRITE ", .description = "The I/O rate of write(2) in bytes per second for the process", .flags = PROCESS_FLAG_IO, .defaultSortDesc = true, },
[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 ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, },
+ [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, },
[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, },
@@ -98,6 +99,7 @@ Process* PCPProcess_new(const Machine* host) {
void Process_delete(Object* cast) {
PCPProcess* this = (PCPProcess*) cast;
Process_done((Process*)cast);
+ free(this->cgroup_short);
free(this->cgroup);
free(this->secattr);
free(this);
@@ -155,7 +157,8 @@ static void PCPProcess_rowWriteField(const Row* super, RichString* str, ProcessF
case IO_READ_RATE: Row_printRate(str, pp->io_rate_read_bps, coloring); return;
case IO_WRITE_RATE: Row_printRate(str, pp->io_rate_write_bps, coloring); return;
case IO_RATE: Row_printRate(str, PCPProcess_totalIORate(pp), coloring); return;
- case CGROUP: xSnprintf(buffer, n, "%-10s ", pp->cgroup ? pp->cgroup : ""); break;
+ 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 OOM: xSnprintf(buffer, n, "%4u ", pp->oom); break;
case PERCENT_CPU_DELAY:
PCPProcess_printDelay(pp->cpu_delay_percent, buffer, n);
@@ -250,6 +253,8 @@ static int PCPProcess_compareByKey(const Process* v1, const Process* v2, Process
return compareRealNumbers(PCPProcess_totalIORate(p1), PCPProcess_totalIORate(p2));
case CGROUP:
return SPACESHIP_NULLSTR(p1->cgroup, p2->cgroup);
+ case CCGROUP:
+ return SPACESHIP_NULLSTR(p1->cgroup_short, p2->cgroup_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 be33111e..fdec4589 100644
--- a/pcp/PCPProcess.h
+++ b/pcp/PCPProcess.h
@@ -73,6 +73,7 @@ typedef struct PCPProcess_ {
double io_rate_read_bps;
double io_rate_write_bps;
char* cgroup;
+ char* cgroup_short;
long int autogroup_id;
int autogroup_nice;
unsigned int oom;
diff --git a/pcp/PCPProcessTable.c b/pcp/PCPProcessTable.c
index 0355e25a..a4634a1b 100644
--- a/pcp/PCPProcessTable.c
+++ b/pcp/PCPProcessTable.c
@@ -26,6 +26,7 @@ in the source distribution for its full text.
#include "Settings.h"
#include "XUtils.h"
+#include "linux/CGroupUtils.h"
#include "pcp/Metric.h"
#include "pcp/PCPMachine.h"
#include "pcp/PCPProcess.h"
@@ -252,6 +253,23 @@ static void PCPProcessTable_updateTTY(Process* process, int pid, int offset) {
static void PCPProcessTable_readCGroups(PCPProcess* pp, int pid, int offset) {
pp->cgroup = setString(PCP_PROC_CGROUPS, pid, offset, pp->cgroup);
+
+ if (pp->cgroup) {
+ char* cgroup_short = CGroup_filterName(pp->cgroup);
+ if (cgroup_short) {
+ Row_updateFieldWidth(CCGROUP, strlen(cgroup_short));
+ free_and_xStrdup(&pp->cgroup_short, cgroup_short);
+ free(cgroup_short);
+ } else {
+ //CCGROUP is alias to normal CGROUP if shortening fails
+ Row_updateFieldWidth(CCGROUP, strlen(pp->cgroup));
+ free(pp->cgroup_short);
+ pp->cgroup_short = NULL;
+ }
+ } else {
+ free(pp->cgroup_short);
+ pp->cgroup_short = NULL;
+ }
}
static void PCPProcessTable_readSecattrData(PCPProcess* pp, int pid, int offset) {
diff --git a/pcp/ProcessField.h b/pcp/ProcessField.h
index b3ba2657..e601ac8d 100644
--- a/pcp/ProcessField.h
+++ b/pcp/ProcessField.h
@@ -45,6 +45,7 @@ in the source distribution for its full text.
SECATTR = 123, \
AUTOGROUP_ID = 127, \
AUTOGROUP_NICE = 128, \
+ CCGROUP = 129, \
// End of list

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