blob: f7962475edf9334f85605018b495d90ba2fbf79e [file] [log] [blame]
Nathan Scott2be09922020-08-20 13:59:41 +10001/*
2htop - PressureStallMeter.c
3(C) 2004-2011 Hisham H. Muhammad
4(C) 2019 Ran Benita
Daniel Lange94ad1112021-09-22 11:33:00 +02005Released under the GNU GPLv2+, see the COPYING file
Nathan Scott2be09922020-08-20 13:59:41 +10006in the source distribution for its full text.
7*/
8
Daniel Lange179aeb02023-11-29 17:44:20 +01009#include "config.h" // IWYU pragma: keep
10
mayurdahibhate3f86a012021-04-29 23:43:36 +053011#include "linux/PressureStallMeter.h"
Nathan Scott2be09922020-08-20 13:59:41 +100012
Benny Baumann0f526292020-09-19 13:55:23 +020013#include <stdbool.h>
Nathan Scott2be09922020-08-20 13:59:41 +100014#include <string.h>
15
Benny Baumannc6f04a92020-09-19 20:22:34 +020016#include "CRT.h"
Benny Baumann0f526292020-09-19 13:55:23 +020017#include "Meter.h"
18#include "Object.h"
Benny Baumannc6f04a92020-09-19 20:22:34 +020019#include "Platform.h"
Benny Baumann0f526292020-09-19 13:55:23 +020020#include "RichString.h"
Benny Baumann872e5422020-10-14 20:21:09 +020021#include "XUtils.h"
Benny Baumannc6f04a92020-09-19 20:22:34 +020022
Nathan Scott2be09922020-08-20 13:59:41 +100023
Christian Göttsche7af06652020-10-13 14:35:30 +020024static const int PressureStallMeter_attributes[] = {
Christian Göttsche1d8192c2020-11-29 15:27:51 +010025 PRESSURE_STALL_TEN,
26 PRESSURE_STALL_SIXTY,
27 PRESSURE_STALL_THREEHUNDRED
Nathan Scott2be09922020-08-20 13:59:41 +100028};
29
Christian Göttsche2d1042a2020-10-06 13:13:16 +020030static void PressureStallMeter_updateValues(Meter* this) {
Benny Baumannb23f8232020-10-31 22:14:27 +010031 const char* file;
32 if (strstr(Meter_name(this), "CPU")) {
33 file = "cpu";
34 } else if (strstr(Meter_name(this), "IO")) {
35 file = "io";
Matthias Maier0bd10852023-02-13 21:39:32 -060036 } else if (strstr(Meter_name(this), "IRQ")) {
37 file = "irq";
Benny Baumannb23f8232020-10-31 22:14:27 +010038 } else {
39 file = "memory";
40 }
Nathan Scott2be09922020-08-20 13:59:41 +100041
Benny Baumannb23f8232020-10-31 22:14:27 +010042 bool some;
43 if (strstr(Meter_name(this), "Some")) {
44 some = true;
45 } else {
46 some = false;
47 }
Nathan Scott2be09922020-08-20 13:59:41 +100048
Benny Baumannb23f8232020-10-31 22:14:27 +010049 Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
Christian Göttscheded9c5d2020-12-08 15:55:26 +010050
51 /* only print bar for ten (not sixty and threehundred), cause the sum is meaningless */
52 this->curItems = 1;
53
Christian Göttsche2d1042a2020-10-06 13:13:16 +020054 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]);
Nathan Scott2be09922020-08-20 13:59:41 +100055}
56
Christian Göttsche79ad39c2020-10-06 12:28:11 +020057static void PressureStallMeter_display(const Object* cast, RichString* out) {
58 const Meter* this = (const Meter*)cast;
Nathan Scott2be09922020-08-20 13:59:41 +100059 char buffer[20];
Christian Göttsche436808f2021-04-14 20:47:42 +020060 int len;
61
62 len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[0]);
63 RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_TEN], buffer, len);
64 len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[1]);
65 RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer, len);
66 len = xSnprintf(buffer, sizeof(buffer), "%5.2lf%% ", this->values[2]);
67 RichString_appendnAscii(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer, len);
Nathan Scott2be09922020-08-20 13:59:41 +100068}
69
Christian Göttsche7af06652020-10-13 14:35:30 +020070const MeterClass PressureStallCPUSomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +100071 .super = {
72 .extends = Class(Meter),
73 .delete = Meter_delete,
74 .display = PressureStallMeter_display,
75 },
76 .updateValues = PressureStallMeter_updateValues,
77 .defaultMode = TEXT_METERMODE,
78 .maxItems = 3,
79 .total = 100.0,
80 .attributes = PressureStallMeter_attributes,
81 .name = "PressureStallCPUSome",
Christian Göttsche1d8192c2020-11-29 15:27:51 +010082 .uiName = "PSI some CPU",
83 .caption = "PSI some CPU: ",
84 .description = "Pressure Stall Information, some cpu"
Nathan Scott2be09922020-08-20 13:59:41 +100085};
86
Christian Göttsche7af06652020-10-13 14:35:30 +020087const MeterClass PressureStallIOSomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +100088 .super = {
89 .extends = Class(Meter),
90 .delete = Meter_delete,
91 .display = PressureStallMeter_display,
92 },
93 .updateValues = PressureStallMeter_updateValues,
94 .defaultMode = TEXT_METERMODE,
95 .maxItems = 3,
96 .total = 100.0,
97 .attributes = PressureStallMeter_attributes,
98 .name = "PressureStallIOSome",
Christian Göttsche1d8192c2020-11-29 15:27:51 +010099 .uiName = "PSI some IO",
100 .caption = "PSI some IO: ",
101 .description = "Pressure Stall Information, some io"
Nathan Scott2be09922020-08-20 13:59:41 +1000102};
103
Christian Göttsche7af06652020-10-13 14:35:30 +0200104const MeterClass PressureStallIOFullMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +1000105 .super = {
106 .extends = Class(Meter),
107 .delete = Meter_delete,
108 .display = PressureStallMeter_display,
109 },
110 .updateValues = PressureStallMeter_updateValues,
111 .defaultMode = TEXT_METERMODE,
112 .maxItems = 3,
113 .total = 100.0,
114 .attributes = PressureStallMeter_attributes,
115 .name = "PressureStallIOFull",
Christian Göttsche1d8192c2020-11-29 15:27:51 +0100116 .uiName = "PSI full IO",
117 .caption = "PSI full IO: ",
118 .description = "Pressure Stall Information, full io"
Nathan Scott2be09922020-08-20 13:59:41 +1000119};
120
Matthias Maier0bd10852023-02-13 21:39:32 -0600121const MeterClass PressureStallIRQFullMeter_class = {
122 .super = {
123 .extends = Class(Meter),
124 .delete = Meter_delete,
125 .display = PressureStallMeter_display,
126 },
127 .updateValues = PressureStallMeter_updateValues,
128 .defaultMode = TEXT_METERMODE,
129 .maxItems = 3,
130 .total = 100.0,
131 .attributes = PressureStallMeter_attributes,
132 .name = "PressureStallIRQFull",
133 .uiName = "PSI full IRQ",
134 .caption = "PSI full IRQ: ",
135 .description = "Pressure Stall Information, full irq"
136};
137
Christian Göttsche7af06652020-10-13 14:35:30 +0200138const MeterClass PressureStallMemorySomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +1000139 .super = {
140 .extends = Class(Meter),
141 .delete = Meter_delete,
142 .display = PressureStallMeter_display,
143 },
144 .updateValues = PressureStallMeter_updateValues,
145 .defaultMode = TEXT_METERMODE,
146 .maxItems = 3,
147 .total = 100.0,
148 .attributes = PressureStallMeter_attributes,
149 .name = "PressureStallMemorySome",
Christian Göttsche1d8192c2020-11-29 15:27:51 +0100150 .uiName = "PSI some memory",
151 .caption = "PSI some memory: ",
152 .description = "Pressure Stall Information, some memory"
Nathan Scott2be09922020-08-20 13:59:41 +1000153};
154
Christian Göttsche7af06652020-10-13 14:35:30 +0200155const MeterClass PressureStallMemoryFullMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +1000156 .super = {
157 .extends = Class(Meter),
158 .delete = Meter_delete,
159 .display = PressureStallMeter_display,
160 },
161 .updateValues = PressureStallMeter_updateValues,
162 .defaultMode = TEXT_METERMODE,
163 .maxItems = 3,
164 .total = 100.0,
165 .attributes = PressureStallMeter_attributes,
166 .name = "PressureStallMemoryFull",
Christian Göttsche1d8192c2020-11-29 15:27:51 +0100167 .uiName = "PSI full memory",
168 .caption = "PSI full memory: ",
169 .description = "Pressure Stall Information, full memory"
Nathan Scott2be09922020-08-20 13:59:41 +1000170};