1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
htop - PressureStallMeter.c
(C) 2004-2011 Hisham H. Muhammad
(C) 2019 Ran Benita
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
#include "linux/PressureStallMeter.h"
#include <stdbool.h>
#include <string.h>
#include "CRT.h"
#include "Meter.h"
#include "Object.h"
#include "Platform.h"
#include "RichString.h"
#include "XUtils.h"
static const int PressureStallMeter_attributes[] = {
PRESSURE_STALL_TEN,
PRESSURE_STALL_SIXTY,
PRESSURE_STALL_THREEHUNDRED
};
static void PressureStallMeter_updateValues(Meter* this) {
const char* file;
if (strstr(Meter_name(this), "CPU")) {
file = "cpu";
} else if (strstr(Meter_name(this), "IO")) {
file = "io";
} else {
file = "memory";
}
bool some;
if (strstr(Meter_name(this), "Some")) {
some = true;
} else {
some = false;
}
Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
/* only print bar for ten (not sixty and threehundred), cause the sum is meaningless */
this->curItems = 1;
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%s %s %5.2lf%% %5.2lf%% %5.2lf%%", some ? "some" : "full", file, this->values[0], this->values[1], this->values[2]);
}
static void PressureStallMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
int len;
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[0]);
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_TEN], buffer, len);
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[1]);
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer, len);
len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[2]);
RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer, len);
}
const MeterClass PressureStallCPUSomeMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = PressureStallMeter_display,
},
.updateValues = PressureStallMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.attributes = PressureStallMeter_attributes,
.name = "PressureStallCPUSome",
.uiName = "PSI some CPU",
.caption = "PSI some CPU: ",
.description = "Pressure Stall Information, some cpu"
};
const MeterClass PressureStallIOSomeMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = PressureStallMeter_display,
},
.updateValues = PressureStallMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.attributes = PressureStallMeter_attributes,
.name = "PressureStallIOSome",
.uiName = "PSI some IO",
.caption = "PSI some IO: ",
.description = "Pressure Stall Information, some io"
};
const MeterClass PressureStallIOFullMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = PressureStallMeter_display,
},
.updateValues = PressureStallMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.attributes = PressureStallMeter_attributes,
.name = "PressureStallIOFull",
.uiName = "PSI full IO",
.caption = "PSI full IO: ",
.description = "Pressure Stall Information, full io"
};
const MeterClass PressureStallMemorySomeMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = PressureStallMeter_display,
},
.updateValues = PressureStallMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.attributes = PressureStallMeter_attributes,
.name = "PressureStallMemorySome",
.uiName = "PSI some memory",
.caption = "PSI some memory: ",
.description = "Pressure Stall Information, some memory"
};
const MeterClass PressureStallMemoryFullMeter_class = {
.super = {
.extends = Class(Meter),
.delete = Meter_delete,
.display = PressureStallMeter_display,
},
.updateValues = PressureStallMeter_updateValues,
.defaultMode = TEXT_METERMODE,
.maxItems = 3,
.total = 100.0,
.attributes = PressureStallMeter_attributes,
.name = "PressureStallMemoryFull",
.uiName = "PSI full memory",
.caption = "PSI full memory: ",
.description = "Pressure Stall Information, full memory"
};
|