TasksMeter.c 2.18 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
/*
Hisham Muhammad's avatar
Hisham Muhammad committed
2
htop - TasksMeter.c
Hisham Muhammad's avatar
Hisham Muhammad committed
3
(C) 2004-2011 Hisham H. Muhammad
Hisham Muhammad's avatar
Hisham Muhammad committed
4
5
6
7
8
9
10
11
12
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"

Hisham Muhammad's avatar
Hisham Muhammad committed
13
14
15
16
/*{
#include "Meter.h"
}*/

17
18
19
int TasksMeter_attributes[] = {
   TASKS_RUNNING
};
20

21
static void TasksMeter_setValues(Meter* this, char* buffer, int len) {
22
23
24
   ProcessList* pl = this->pl;
   this->total = pl->totalTasks;
   this->values[0] = pl->runningTasks;
25
   snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
Hisham Muhammad's avatar
Hisham Muhammad committed
26
27
}

28
static void TasksMeter_display(Object* cast, RichString* out) {
Hisham Muhammad's avatar
Hisham Muhammad committed
29
   Meter* this = (Meter*)cast;
30
   ProcessList* pl = this->pl;
Hisham Muhammad's avatar
Hisham Muhammad committed
31
   char buffer[20];
32
   sprintf(buffer, "%d", (int)(this->total - pl->userlandThreads - pl->kernelThreads));
33
   RichString_write(out, CRT_colors[METER_VALUE], buffer);
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
   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], "; ");
Hisham Muhammad's avatar
Hisham Muhammad committed
53
54
55
56
   sprintf(buffer, "%d", (int)this->values[0]);
   RichString_append(out, CRT_colors[TASKS_RUNNING], buffer);
   RichString_append(out, CRT_colors[METER_TEXT], " running");
}
57

58
59
60
61
62
63
MeterClass TasksMeter_class = {
   .super = {
      .extends = Class(Meter),
      .delete = Meter_delete,
      .display = TasksMeter_display,
   },
64
   .setValues = TasksMeter_setValues, 
65
   .defaultMode = TEXT_METERMODE,
66
67
68
69
70
71
   .total = 100.0,
   .attributes = TasksMeter_attributes, 
   .name = "Tasks",
   .uiName = "Task counter",
   .caption = "Tasks: "
};