From f975e7990e8ce897a82cadaca8365a828c483bfe 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 f134be53f..b2eb5a016 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 dfd281355..b2d3482eb 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 49265d6f0..7aaee1104 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 662fb2257..591aeb775 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 4fd02a9b2..3e282a3ec 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 f5ee21bd9..d90c8d1e2 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 b518da246..58e2d52b4 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 e49569e97..713bc137f 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 86bec1765..1b9159b3c 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, },