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
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TasksMeter.h"
|
|
|
|
|
|
|
|
#include "CRT.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Macros.h"
|
|
|
|
#include "Object.h"
|
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "RichString.h"
|
|
|
|
#include "Settings.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
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
|
|
|
|
2020-10-06 11:13:16 +00:00
|
|
|
static void TasksMeter_updateValues(Meter* this) {
|
2020-10-21 19:25:50 +00:00
|
|
|
const ProcessList* pl = this->pl;
|
2015-03-17 02:01:48 +00:00
|
|
|
this->values[0] = pl->kernelThreads;
|
|
|
|
this->values[1] = pl->userlandThreads;
|
|
|
|
this->values[2] = pl->totalTasks - pl->kernelThreads - pl->userlandThreads;
|
2021-06-12 16:17:28 +00:00
|
|
|
this->values[3] = MINIMUM(pl->runningTasks, pl->activeCPUs);
|
2021-03-28 16:18:56 +00:00
|
|
|
this->total = pl->totalTasks;
|
|
|
|
|
2021-08-14 01:24:35 +00:00
|
|
|
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%u/%u", MINIMUM(pl->runningTasks, pl->activeCPUs), pl->totalTasks);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
static void TasksMeter_display(const Object* cast, RichString* out) {
|
|
|
|
const Meter* this = (const Meter*)cast;
|
|
|
|
const Settings* settings = this->pl->settings;
|
2006-03-04 18:16:49 +00:00
|
|
|
char buffer[20];
|
2021-04-14 18:47:42 +00:00
|
|
|
int len;
|
2019-10-31 16:39:12 +00:00
|
|
|
|
2021-04-14 18:47:42 +00:00
|
|
|
len = xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[2]);
|
|
|
|
RichString_appendnAscii(out, CRT_colors[METER_VALUE], buffer, len);
|
2021-03-28 16:18:56 +00:00
|
|
|
|
|
|
|
RichString_appendAscii(out, settings->hideUserlandThreads ? CRT_colors[METER_SHADOW] : CRT_colors[METER_TEXT], ", ");
|
2021-04-14 18:47:42 +00:00
|
|
|
len = xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[1]);
|
|
|
|
RichString_appendnAscii(out, settings->hideUserlandThreads ? CRT_colors[METER_SHADOW] : CRT_colors[TASKS_RUNNING], buffer, len);
|
2021-03-28 16:18:56 +00:00
|
|
|
RichString_appendAscii(out, settings->hideUserlandThreads ? CRT_colors[METER_SHADOW] : CRT_colors[METER_TEXT], " thr");
|
|
|
|
|
|
|
|
RichString_appendAscii(out, settings->hideKernelThreads ? CRT_colors[METER_SHADOW] : CRT_colors[METER_TEXT], ", ");
|
2021-04-14 18:47:42 +00:00
|
|
|
len = xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[0]);
|
|
|
|
RichString_appendnAscii(out, settings->hideKernelThreads ? CRT_colors[METER_SHADOW] : CRT_colors[TASKS_RUNNING], buffer, len);
|
2021-03-28 16:18:56 +00:00
|
|
|
RichString_appendAscii(out, settings->hideKernelThreads ? CRT_colors[METER_SHADOW] : CRT_colors[METER_TEXT], " kthr");
|
|
|
|
|
2020-12-04 13:44:57 +00:00
|
|
|
RichString_appendAscii(out, CRT_colors[METER_TEXT], "; ");
|
2021-04-14 18:47:42 +00:00
|
|
|
len = xSnprintf(buffer, sizeof(buffer), "%d", (int)this->values[3]);
|
|
|
|
RichString_appendnAscii(out, CRT_colors[TASKS_RUNNING], buffer, len);
|
2020-12-04 13:44:57 +00:00
|
|
|
RichString_appendAscii(out, CRT_colors[METER_TEXT], " running");
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const MeterClass TasksMeter_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.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: "
|
|
|
|
};
|