summaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorAdam Saponara <as@php.net>2020-10-30 21:56:16 -0400
committerAdam Saponara <as@php.net>2020-10-30 21:56:16 -0400
commitdde71c6637905e1707bd1020c93e930f4b0a480b (patch)
treeef65023b640f292ac50a7e0db38babbb78ef8eea /ProcessList.c
parentbbf01054bf943db4394027d77915f9625ebde81e (diff)
Highlight new and old processes (#74)
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/ProcessList.c b/ProcessList.c
index dac86cb8..1ae7b9cc 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -9,11 +9,11 @@ in the source distribution for its full text.
#include <assert.h>
#include <string.h>
+#include <time.h>
#include "CRT.h"
#include "XUtils.h"
-
ProcessList* ProcessList_init(ProcessList* this, const ObjectClass* klass, UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) {
this->processes = Vector_new(klass, true, DEFAULT_SIZE);
this->processTable = Hashtable_new(140, false);
@@ -27,6 +27,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) {
@@ -81,6 +84,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);
@@ -283,6 +294,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) {
@@ -302,13 +314,35 @@ 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)
- ProcessList_remove(this, p);
- else
+ 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) {
+ // 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