Split process and thread counts in tasks meter

This commit is contained in:
Hisham Muhammad 2010-11-23 13:28:47 +00:00
parent d8e1480a27
commit 831538b0f9
5 changed files with 35 additions and 6 deletions

1
CRT.c
View File

@ -58,7 +58,6 @@ typedef enum ColorElements_ {
LED_COLOR, LED_COLOR,
UPTIME, UPTIME,
BATTERY, BATTERY,
TASKS_TOTAL,
TASKS_RUNNING, TASKS_RUNNING,
SWAP, SWAP,
PROCESS, PROCESS,

1
CRT.h
View File

@ -60,7 +60,6 @@ typedef enum ColorElements_ {
LED_COLOR, LED_COLOR,
UPTIME, UPTIME,
BATTERY, BATTERY,
TASKS_TOTAL,
TASKS_RUNNING, TASKS_RUNNING,
SWAP, SWAP,
PROCESS, PROCESS,

View File

@ -94,6 +94,8 @@ typedef struct ProcessList_ {
int cpuCount; int cpuCount;
int totalTasks; int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks; int runningTasks;
CPUData* cpus; CPUData* cpus;
@ -635,6 +637,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
if (! ProcessList_readCmdlineFile(process, dirname, name)) if (! ProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
} }
if (Process_isKernelThread(process)) {
this->kernelThreads++;
} else {
this->userlandThreads++;
}
} }
this->totalTasks++; this->totalTasks++;
@ -772,6 +779,8 @@ void ProcessList_scan(ProcessList* this) {
} }
this->totalTasks = 0; this->totalTasks = 0;
this->userlandThreads = 0;
this->kernelThreads = 0;
this->runningTasks = 0; this->runningTasks = 0;
ProcessList_processEntries(this, PROCDIR, NULL, period); ProcessList_processEntries(this, PROCDIR, NULL, period);

View File

@ -94,6 +94,8 @@ typedef struct ProcessList_ {
int cpuCount; int cpuCount;
int totalTasks; int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks; int runningTasks;
CPUData* cpus; CPUData* cpus;

View File

@ -19,17 +19,37 @@ int TasksMeter_attributes[] = {
}; };
static void TasksMeter_setValues(Meter* this, char* buffer, int len) { static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
this->total = this->pl->totalTasks; ProcessList* pl = this->pl;
this->values[0] = this->pl->runningTasks; this->total = pl->totalTasks;
this->values[0] = pl->runningTasks;
snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total); snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
} }
static void TasksMeter_display(Object* cast, RichString* out) { static void TasksMeter_display(Object* cast, RichString* out) {
Meter* this = (Meter*)cast; Meter* this = (Meter*)cast;
ProcessList* pl = this->pl;
char buffer[20]; char buffer[20];
sprintf(buffer, "%d", (int)this->total); sprintf(buffer, "%d", (int)(this->total - pl->userlandThreads - pl->kernelThreads));
RichString_write(out, CRT_colors[METER_VALUE], buffer); RichString_write(out, CRT_colors[METER_VALUE], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " total, "); 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], "; ");
sprintf(buffer, "%d", (int)this->values[0]); sprintf(buffer, "%d", (int)this->values[0]);
RichString_append(out, CRT_colors[TASKS_RUNNING], buffer); RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
RichString_append(out, CRT_colors[METER_TEXT], " running"); RichString_append(out, CRT_colors[METER_TEXT], " running");