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"
|
|
|
|
|
|
|
|
#include "ProcessList.h"
|
|
|
|
#include "CRT.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
/*{
|
|
|
|
#include "Meter.h"
|
|
|
|
}*/
|
|
|
|
|
2006-06-06 20:41:01 +00:00
|
|
|
int TasksMeter_attributes[] = {
|
|
|
|
TASKS_RUNNING
|
|
|
|
};
|
2006-04-10 20:40:38 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
|
2010-11-23 13:28:47 +00:00
|
|
|
ProcessList* pl = this->pl;
|
|
|
|
this->total = pl->totalTasks;
|
|
|
|
this->values[0] = pl->runningTasks;
|
2006-04-10 20:40:38 +00:00
|
|
|
snprintf(buffer, len, "%d/%d", (int) this->values[0], (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;
|
2010-11-23 13:28:47 +00:00
|
|
|
ProcessList* pl = this->pl;
|
2006-03-04 18:16:49 +00:00
|
|
|
char buffer[20];
|
2010-11-23 13:28:47 +00:00
|
|
|
sprintf(buffer, "%d", (int)(this->total - pl->userlandThreads - pl->kernelThreads));
|
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];
|
|
|
|
if (pl->highlightThreads) {
|
|
|
|
threadValueColor = CRT_colors[PROCESS_THREAD_BASENAME];
|
|
|
|
threadCaptionColor = CRT_colors[PROCESS_THREAD];
|
|
|
|
}
|
|
|
|
if (!pl->hideUserlandThreads) {
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
|
|
|
sprintf(buffer, "%d", (int)pl->userlandThreads);
|
|
|
|
RichString_append(out, threadValueColor, buffer);
|
|
|
|
RichString_append(out, threadCaptionColor, " thr");
|
|
|
|
}
|
|
|
|
if (!pl->hideKernelThreads) {
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], ", ");
|
|
|
|
sprintf(buffer, "%d", (int)pl->kernelThreads);
|
|
|
|
RichString_append(out, threadValueColor, buffer);
|
|
|
|
RichString_append(out, threadCaptionColor, " kthr");
|
|
|
|
}
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], "; ");
|
2006-03-04 18:16:49 +00:00
|
|
|
sprintf(buffer, "%d", (int)this->values[0]);
|
|
|
|
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
|
|
|
|
RichString_append(out, CRT_colors[METER_TEXT], " running");
|
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
|
|
|
MeterType TasksMeter = {
|
|
|
|
.setValues = TasksMeter_setValues,
|
|
|
|
.display = TasksMeter_display,
|
|
|
|
.mode = TEXT_METERMODE,
|
|
|
|
.items = 1,
|
|
|
|
.total = 100.0,
|
|
|
|
.attributes = TasksMeter_attributes,
|
|
|
|
.name = "Tasks",
|
|
|
|
.uiName = "Task counter",
|
|
|
|
.caption = "Tasks: "
|
|
|
|
};
|