From 831538b0f90a2ae6448522dc6c0bbcb73ba12f97 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 23 Nov 2010 13:28:47 +0000 Subject: [PATCH] Split process and thread counts in tasks meter --- CRT.c | 1 - CRT.h | 1 - ProcessList.c | 9 +++++++++ ProcessList.h | 2 ++ TasksMeter.c | 28 ++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CRT.c b/CRT.c index cb5982ce..14af4208 100644 --- a/CRT.c +++ b/CRT.c @@ -58,7 +58,6 @@ typedef enum ColorElements_ { LED_COLOR, UPTIME, BATTERY, - TASKS_TOTAL, TASKS_RUNNING, SWAP, PROCESS, diff --git a/CRT.h b/CRT.h index 3a60a0e8..dcc902f6 100644 --- a/CRT.h +++ b/CRT.h @@ -60,7 +60,6 @@ typedef enum ColorElements_ { LED_COLOR, UPTIME, BATTERY, - TASKS_TOTAL, TASKS_RUNNING, SWAP, PROCESS, diff --git a/ProcessList.c b/ProcessList.c index c37919ba..d94a3fcc 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -94,6 +94,8 @@ typedef struct ProcessList_ { int cpuCount; int totalTasks; + int userlandThreads; + int kernelThreads; int runningTasks; CPUData* cpus; @@ -635,6 +637,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P if (! ProcessList_readCmdlineFile(process, dirname, name)) goto errorReadingProcess; } + if (Process_isKernelThread(process)) { + this->kernelThreads++; + } else { + this->userlandThreads++; + } } this->totalTasks++; @@ -772,6 +779,8 @@ void ProcessList_scan(ProcessList* this) { } this->totalTasks = 0; + this->userlandThreads = 0; + this->kernelThreads = 0; this->runningTasks = 0; ProcessList_processEntries(this, PROCDIR, NULL, period); diff --git a/ProcessList.h b/ProcessList.h index 2442f351..fdbf4202 100644 --- a/ProcessList.h +++ b/ProcessList.h @@ -94,6 +94,8 @@ typedef struct ProcessList_ { int cpuCount; int totalTasks; + int userlandThreads; + int kernelThreads; int runningTasks; CPUData* cpus; diff --git a/TasksMeter.c b/TasksMeter.c index 685489ab..9f177954 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -19,17 +19,37 @@ int TasksMeter_attributes[] = { }; static void TasksMeter_setValues(Meter* this, char* buffer, int len) { - this->total = this->pl->totalTasks; - this->values[0] = this->pl->runningTasks; + ProcessList* pl = this->pl; + this->total = pl->totalTasks; + this->values[0] = pl->runningTasks; snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total); } static void TasksMeter_display(Object* cast, RichString* out) { Meter* this = (Meter*)cast; + ProcessList* pl = this->pl; 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_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]); RichString_append(out, CRT_colors[TASKS_RUNNING], buffer); RichString_append(out, CRT_colors[METER_TEXT], " running");