mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Merge branch 'hili-new-old' of adsr/htop into highlight-new-old-processes
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user