summaryrefslogtreecommitdiffstats
path: root/Process.c
diff options
context:
space:
mode:
authorNathan Scott <nathans@redhat.com>2023-05-02 09:02:22 +1000
committerNathan Scott <nathans@redhat.com>2023-05-08 13:06:07 +1000
commit0bdade1b6cb40c5bd374a93ac0489058a7421bb5 (patch)
tree0e0225f7dbf6867402c5ed3481a705d01941f42e /Process.c
parente4ebe18b67c366d367231a1123b057c82018cf5b (diff)
Introduce Machine class for host-specific info (split from ProcessList)
First stage in sanitizing the process list structure so that htop can support other types of lists too (cgroups, filesystems, ...), in the not-too-distant future. This introduces struct Machine for system-wide information while keeping process-list information in ProcessList (now much less). Next step is to propogate this separation into each platform, to match these core changes.
Diffstat (limited to 'Process.c')
-rw-r--r--Process.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/Process.c b/Process.c
index c92d01b9..43f7f70d 100644
--- a/Process.c
+++ b/Process.c
@@ -407,7 +407,7 @@ static inline char* stpcpyWithNewlineConversion(char* dstStr, const char* srcStr
*/
void Process_makeCommandStr(Process* this) {
ProcessMergedCommand* mc = &this->mergedCommand;
- const Settings* settings = this->settings;
+ const Settings* settings = this->host->settings;
bool showMergedCommand = settings->showMergedCommand;
bool showProgramPath = settings->showProgramPath;
@@ -675,15 +675,16 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
int strStart = RichString_size(str);
- const bool highlightBaseName = this->settings->highlightBaseName;
+ const Settings* settings = this->host->settings;
+ const bool highlightBaseName = settings->highlightBaseName;
const bool highlightSeparator = true;
- const bool highlightDeleted = this->settings->highlightDeletedExe;
+ const bool highlightDeleted = settings->highlightDeletedExe;
if (!mergedCommand) {
int len = 0;
const char* cmdline = this->cmdline;
- if (highlightBaseName || !this->settings->showProgramPath) {
+ if (highlightBaseName || !settings->showProgramPath) {
int basename = 0;
for (int i = 0; i < this->cmdlineBasenameEnd; i++) {
if (cmdline[i] == '/') {
@@ -694,7 +695,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
}
}
if (len == 0) {
- if (this->settings->showProgramPath) {
+ if (settings->showProgramPath) {
strStart += basename;
} else {
cmdline += basename;
@@ -705,7 +706,7 @@ void Process_writeCommand(const Process* this, int attr, int baseAttr, RichStrin
RichString_appendWide(str, attr, cmdline);
- if (this->settings->highlightBaseName) {
+ if (settings->highlightBaseName) {
RichString_setAttrn(str, baseAttr, strStart, len);
}
@@ -833,16 +834,17 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
char buffer[256];
size_t n = sizeof(buffer);
int attr = CRT_colors[DEFAULT_COLOR];
- bool coloring = this->settings->highlightMegabytes;
+ const Settings* settings = this->host->settings;
+ bool coloring = settings->highlightMegabytes;
switch (field) {
case COMM: {
int baseattr = CRT_colors[PROCESS_BASENAME];
- if (this->settings->highlightThreads && Process_isThread(this)) {
+ if (settings->highlightThreads && Process_isThread(this)) {
attr = CRT_colors[PROCESS_THREAD];
baseattr = CRT_colors[PROCESS_THREAD_BASENAME];
}
- const ScreenSettings* ss = this->settings->ss;
+ const ScreenSettings* ss = settings->ss;
if (!ss->treeView || this->indent == 0) {
Process_writeCommand(this, attr, baseattr, str);
return;
@@ -890,7 +892,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
const char* procExe;
if (this->procExe) {
attr = CRT_colors[Process_isUserlandThread(this) ? PROCESS_THREAD_BASENAME : PROCESS_BASENAME];
- if (this->settings->highlightDeletedExe) {
+ if (settings->highlightDeletedExe) {
if (this->procExeDeleted)
attr = CRT_colors[FAILED_READ];
else if (this->usesDeletedLib)
@@ -920,7 +922,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
return;
}
case ELAPSED: {
- const uint64_t rt = this->processList->realtimeMs;
+ const uint64_t rt = this->host->realtimeMs;
const uint64_t st = this->starttime_ctime * 1000;
const uint64_t dt =
rt < st ? 0 :
@@ -946,7 +948,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
break;
case PERCENT_CPU: Process_printPercentage(this->percent_cpu, buffer, n, Process_fieldWidths[PERCENT_CPU], &attr); break;
case PERCENT_NORM_CPU: {
- float cpuPercentage = this->percent_cpu / this->processList->activeCPUs;
+ float cpuPercentage = this->percent_cpu / this->host->activeCPUs;
Process_printPercentage(cpuPercentage, buffer, n, Process_fieldWidths[PERCENT_CPU], &attr);
break;
}
@@ -960,7 +962,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
else
xSnprintf(buffer, n, "%3ld ", this->priority);
break;
- case PROCESSOR: xSnprintf(buffer, n, "%3d ", Settings_cpuId(this->settings, this->processor)); break;
+ case PROCESSOR: xSnprintf(buffer, n, "%3d ", Settings_cpuId(settings, this->processor)); break;
case SCHEDULERPOLICY: {
const char* schedPolStr = "N/A";
#ifdef SCHEDULER_SUPPORT
@@ -1044,11 +1046,12 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field
void Process_display(const Object* cast, RichString* out) {
const Process* this = (const Process*) cast;
- const ProcessField* fields = this->settings->ss->fields;
+ const Settings* settings = this->host->settings;
+ const ProcessField* fields = settings->ss->fields;
for (int i = 0; fields[i]; i++)
As_Process(this)->writeField(this, out, fields[i]);
- if (this->settings->shadowOtherUsers && this->st_uid != Process_getuid) {
+ if (settings->shadowOtherUsers && this->st_uid != Process_getuid) {
RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]);
}
@@ -1056,7 +1059,7 @@ void Process_display(const Object* cast, RichString* out) {
RichString_setAttr(out, CRT_colors[PROCESS_TAG]);
}
- if (this->settings->highlightChanges) {
+ if (settings->highlightChanges) {
if (Process_isTomb(this)) {
out->highlightAttr = CRT_colors[PROCESS_TOMB];
} else if (Process_isNew(this)) {
@@ -1081,7 +1084,8 @@ void Process_done(Process* this) {
* happens on what is displayed - whether comm, full path, basename, etc.. So
* this follows Process_writeField(COMM) and Process_writeCommand */
const char* Process_getCommand(const Process* this) {
- if ((Process_isUserlandThread(this) && this->settings->showThreadNames) || !this->mergedCommand.str) {
+ const Settings* settings = this->host->settings;
+ if ((Process_isUserlandThread(this) && settings->showThreadNames) || !this->mergedCommand.str) {
return this->cmdline;
}
@@ -1098,8 +1102,8 @@ const ProcessClass Process_class = {
.writeField = Process_writeField,
};
-void Process_init(Process* this, const Settings* settings) {
- this->settings = settings;
+void Process_init(Process* this, const Machine* host) {
+ this->host = host;
this->tag = false;
this->showChildren = true;
this->show = true;
@@ -1117,9 +1121,11 @@ void Process_toggleTag(Process* this) {
}
bool Process_isNew(const Process* this) {
- assert(this->processList);
- if (this->processList->monotonicMs >= this->seenStampMs) {
- return this->processList->monotonicMs - this->seenStampMs <= 1000 * (uint64_t)this->processList->settings->highlightDelaySecs;
+ assert(this->host);
+ const Machine* host = this->host;
+ if (host->monotonicMs >= this->seenStampMs) {
+ const Settings* settings = host->settings;
+ return host->monotonicMs - this->seenStampMs <= 1000 * (uint64_t)settings->highlightDelaySecs;
}
return false;
}
@@ -1153,7 +1159,7 @@ int Process_compare(const void* v1, const void* v2) {
const Process* p1 = (const Process*)v1;
const Process* p2 = (const Process*)v2;
- const Settings* settings = p1->settings;
+ const Settings* settings = p1->host->settings;
const ScreenSettings* ss = settings->ss;
ProcessField key = ScreenSettings_getActiveSortKey(ss);

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