summaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-11-16 12:13:47 +0100
committerDaniel Lange <DLange@git.local>2020-11-16 12:55:07 +0100
commit0951090fa45255cd0ae0df907240868c31689014 (patch)
tree8d923fa842a2a0be65ff2d786bcd6a01cfbcf66a /ProcessList.c
parent0411fdbcef51c1b2a39d9eeaa140a5b7c00bd3d2 (diff)
parenta83f515f0fb75a079601be0d2e0e24b9402c9e15 (diff)
Merge branch 'hili-new-old' of adsr/htop into highlight-new-old-processes
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 457761a2..a88c1e7b 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -9,6 +9,7 @@ in the source distribution for its full text.
#include <assert.h>
#include <string.h>
+#include <time.h>
#include "CRT.h"
#include "XUtils.h"
@@ -27,6 +28,9 @@ ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, Users
// set later by platform-specific code
this->cpuCount = 0;
+ this->scanTs = 0;
+ this->firstScanTs = 0;
+
#ifdef HAVE_LIBHWLOC
this->topologyOk = false;
if (hwloc_topology_init(&this->topology) == 0) {
@@ -85,6 +89,14 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) {
void ProcessList_add(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
assert(Hashtable_get(this->processTable, p->pid) == NULL);
+ p->processList = this;
+
+ if (this->scanTs == this->firstScanTs) {
+ // prevent highlighting processes found in first scan
+ p->seenTs = this->firstScanTs - this->settings->highlightDelaySecs - 1;
+ } else {
+ p->seenTs = this->scanTs;
+ }
Vector_add(this->processes, p);
Hashtable_put(this->processTable, p->pid, p);
@@ -145,10 +157,10 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
Vector_insert(this->processes2, 0, process);
}
- assert(Vector_size(this->processes2) == s + 1); (void)s;
+ assert(Vector_size(this->processes2) == s+1); (void)s;
int nextIndent = indent | (1 << level);
- ProcessList_buildTree(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false);
+ ProcessList_buildTree(this, process->pid, level+1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false);
if (i == size - 1) {
process->indent = -nextIndent;
@@ -160,8 +172,8 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
}
static long ProcessList_treeProcessCompare(const void* v1, const void* v2) {
- const Process* p1 = (const Process*)v1;
- const Process* p2 = (const Process*)v2;
+ const Process *p1 = (const Process*)v1;
+ const Process *p2 = (const Process*)v2;
return p1->pid - p2->pid;
}
@@ -304,6 +316,7 @@ Process* ProcessList_getProcess(ProcessList* this, pid_t pid, bool* preExisting,
}
void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
+ struct timespec now;
// in pause mode only gather global data for meters (CPU/memory/...)
if (pauseProcessUpdate) {
@@ -315,6 +328,7 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
for (int i = 0; i < Vector_size(this->processes); i++) {
Process* p = (Process*) Vector_get(this->processes, i);
p->updated = false;
+ p->wasShown = p->show;
p->show = true;
}
@@ -323,12 +337,33 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) {
this->kernelThreads = 0;
this->runningTasks = 0;
+
+ // set scanTs
+ if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) {
+ if (this->firstScanTs == 0) {
+ this->firstScanTs = now.tv_sec;
+ }
+ this->scanTs = now.tv_sec;
+ }
+
ProcessList_goThroughEntries(this, false);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
Process* p = (Process*) Vector_get(this->processes, i);
- if (p->updated == false) {
+ if (p->tombTs > 0) {
+ // remove tombed process
+ if (this->scanTs >= p->tombTs) {
ProcessList_remove(this, p);
+ }
+ } else if (p->updated == false) {
+ // process no longer exists
+ if (this->settings->highlightChanges && p->wasShown) {
+ // mark tombed
+ p->tombTs = this->scanTs + this->settings->highlightDelaySecs;
+ } else {
+ // immediately remove
+ ProcessList_remove(this, p);
+ }
} else {
p->updated = false;
}

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