From 550a1418606f487941b3dddbf81de17c459db66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sun, 2 May 2021 13:29:39 +0200 Subject: [PATCH] Add ELAPSED process column Add process columns showing the elapsed time since the process was started. Similar to STARTTIME, but shows the time passed since the process start instead of the fixed start time of the process. Closes https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=782636 --- Process.c | 4 ++++ Process.h | 1 + darwin/DarwinProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcess.c | 1 + freebsd/FreeBSDProcess.c | 2 +- linux/LinuxProcess.c | 1 + openbsd/OpenBSDProcess.c | 6 ++++++ solaris/SolarisProcess.c | 1 + unsupported/UnsupportedProcess.c | 2 +- 9 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Process.c b/Process.c index f134be53..b2eb5a01 100644 --- a/Process.c +++ b/Process.c @@ -777,6 +777,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field Process_printLeftAlignedField(str, attr, procExe, TASK_COMM_LEN - 1); return; } + case ELAPSED: Process_printTime(str, /* convert to hundreds of a second */ this->processList->realtimeMs / 10 - 100 * this->starttime_ctime, coloring); return; case MAJFLT: Process_printCount(str, this->majflt, coloring); return; case MINFLT: Process_printCount(str, this->minflt, coloring); return; case M_RESIDENT: Process_printKBytes(str, this->m_resident, coloring); return; @@ -1073,6 +1074,9 @@ int Process_compareByKey_Base(const Process* p1, const Process* p2, ProcessField const char *exe2 = p2->procExe ? (p2->procExe + p2->procExeBasenameOffset) : (Process_isKernelThread(p2) ? kthreadID : ""); return SPACESHIP_NULLSTR(exe1, exe2); } + case ELAPSED: + r = -SPACESHIP_NUMBER(p1->starttime_ctime, p2->starttime_ctime); + return r != 0 ? r : SPACESHIP_NUMBER(p1->pid, p2->pid); case MAJFLT: return SPACESHIP_NUMBER(p1->majflt, p2->majflt); case MINFLT: diff --git a/Process.h b/Process.h index dfd28135..b2d3482e 100644 --- a/Process.h +++ b/Process.h @@ -46,6 +46,7 @@ typedef enum ProcessField_ { NLWP = 51, TGID = 52, PERCENT_NORM_CPU = 53, + ELAPSED = 54, PROC_COMM = 124, PROC_EXE = 125, diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 49265d6f..7aaee110 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -33,7 +33,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, - + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 662fb225..591aeb77 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -33,6 +33,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index 4fd02a9b..3e282a3e 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -32,7 +32,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, - + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index f5ee21bd..d90c8d1e 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -50,6 +50,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index b518da24..58e2d52b 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -108,6 +108,12 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { .description = "Time the process was started", .flags = 0, }, + [ELAPSED] = { + .name = "ELAPSED", + .title = "ELAPSED ", + .description = "Time since the process was started", + .flags = 0, + }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", diff --git a/solaris/SolarisProcess.c b/solaris/SolarisProcess.c index e49569e9..713bc137 100644 --- a/solaris/SolarisProcess.c +++ b/solaris/SolarisProcess.c @@ -35,6 +35,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, }, diff --git a/unsupported/UnsupportedProcess.c b/unsupported/UnsupportedProcess.c index 86bec176..1b9159b3 100644 --- a/unsupported/UnsupportedProcess.c +++ b/unsupported/UnsupportedProcess.c @@ -30,7 +30,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", .flags = 0, }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", .flags = 0, }, - + [ELAPSED] = { .name = "ELAPSED", .title = "ELAPSED ", .description = "Time since the process was started", .flags = 0, }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", .flags = 0, }, [M_VIRT] = { .name = "M_VIRT", .title = " VIRT ", .description = "Total program size in virtual memory", .flags = 0, .defaultSortDesc = true, }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", .flags = 0, .defaultSortDesc = true, },