2006-03-04 18:16:49 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - TasksMeter.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2006-03-04 18:16:49 +00:00
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TasksMeter.h"
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "Platform.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
#include "CRT.h"
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2020-09-28 10:23:07 +00:00
|
|
|
static const int TasksMeter_attributes[] = {
|
|
|
|
CPU_SYSTEM,
|
|
|
|
PROCESS_THREAD,
|
|
|
|
PROCESS,
|
|
|
|
TASKS_RUNNING
|
2006-06-06 20:41:01 +00:00
|
|
|
};
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2016-05-04 05:39:26 +00:00
|
|
|
static void TasksMeter_updateValues(Meter* this, char* buffer, int len) {
|
2015-03-17 02:01:48 +00:00
|
|
|
ProcessList* pl = this->pl;
|
|
|
|
this->values[0] = pl->kernelThreads;
|
|
|
|
this->values[1] = pl->userlandThreads;
|
|
|
|
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
2020-09-09 06:56:04 +00:00
|
|
|
this->values[3] = MINIMUM(pl->runningTasks, pl->cpuCount);
|
2015-03-17 02:01:48 +00:00
|
|
|
if (pl->totalTasks > this->total) {
|
|
|
|
this->total = pl->totalTasks;
|
|
|
|
}
|
2015-01-23 05:08:21 +00:00
|
|
|
if (this->pl->settings->hideKernelThreads) {
|
|
|
|
this->values[0] = 0;
|
|
|
|
}
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, len, "%d/%d", (int) this->values[3], (int) this->total);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void TasksMeter_display(Object* cast, RichString* out) {
|
2006-03-04 18:16:49 +00:00
|
|
|
Meter* this = (Meter*)cast;
|
2015-01-22 01:27:31 +00:00
|
|
|
Settings* settings = this->pl->settings;
|
2006-03-04 18:16:49 +00:00
|
|
|
char buffer[20];
|
2019-10-31 16:39:12 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
int processes = (int) this->values[2];
|
2019-10-31 16:39:12 +00:00
|
|
|
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%d", processes);
|
2010-11-22 12:40:20 +00:00
|
|
|
RichString_write(out, CRT_colors[METER_VALUE], buffer);
|
2010-11-23 13:28:47 +00:00
|
|
|
int threadValueColor = CRT_colors[METER_VALUE];
|
|
|
|
int threadCaptionColor = CRT_colors[METER_TEXT];
|
2015-01-22 01:27:31 +00:00
|
|
|
if (settings->highlightThreads) {
|
2010-11-23 13:28:47 +00:00
|
|
|
threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME];
|
|
|
|
threadCaptionColor = CRT_colors[PROCESS_THREAD];
|
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
if (!settings->hideUserlandThreads) {
|
2010-11-23 13:28:47 +00:00
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[1]);
|
2010-11-23 13:28:47 +00:00
|
|
|
RichString_append(out, threadValueColor, buffer);
|
|
|
|
RichString_append(out, threadCaptionColor, " thr");
|
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
if (!settings->hideKernelThreads) {
|
2010-11-23 13:28:47 +00:00
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[0]);
|
2010-11-23 13:28:47 +00:00
|
|
|
RichString_append(out, threadValueColor, buffer);
|
|
|
|
RichString_append(out, threadCaptionColor, " kthr");
|
|
|
|
}
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], "; ");
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[3]);
|
2006-03-04 18:16:49 +00:00
|
|
|
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
MeterClass TasksMeter_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete,
|
|
|
|
.display = TasksMeter_display,
|
|
|
|
},
|
2016-05-04 05:39:26 +00:00
|
|
|
.updateValues = TasksMeter_updateValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2015-01-22 01:27:31 +00:00
|
|
|
.maxItems = 4,
|
2016-03-11 02:54:34 +00:00
|
|
|
.total = 100.0,
|
2019-10-31 16:39:12 +00:00
|
|
|
.attributes = TasksMeter_attributes,
|
2008-03-09 08:58:38 +00:00
|
|
|
.name = "Tasks",
|
|
|
|
.uiName = "Task counter",
|
|
|
|
.caption = "Tasks: "
|
|
|
|
};
|