blob: 9ac0ced23a0bab3de658885d5d2af16dedc89bc8 [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 Lange079c2ab2020-10-05 09:51:32 +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
9#include "PressureStallMeter.h"
Nathan Scott2be09922020-08-20 13:59:41 +100010
Benny Baumann0f526292020-09-19 13:55:23 +020011#include <stdbool.h>
Nathan Scott2be09922020-08-20 13:59:41 +100012#include <string.h>
13
Benny Baumannc6f04a92020-09-19 20:22:34 +020014#include "CRT.h"
Benny Baumann0f526292020-09-19 13:55:23 +020015#include "Meter.h"
16#include "Object.h"
Benny Baumannc6f04a92020-09-19 20:22:34 +020017#include "Platform.h"
Benny Baumann0f526292020-09-19 13:55:23 +020018#include "RichString.h"
Benny Baumann872e5422020-10-14 20:21:09 +020019#include "XUtils.h"
Benny Baumannc6f04a92020-09-19 20:22:34 +020020
Nathan Scott2be09922020-08-20 13:59:41 +100021
Christian Göttsche7af06652020-10-13 14:35:30 +020022static const int PressureStallMeter_attributes[] = {
Nathan Scott2be09922020-08-20 13:59:41 +100023 PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED
24};
25
26static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
27 const char *file;
28 if (strstr(Meter_name(this), "CPU")) {
29 file = "cpu";
30 } else if (strstr(Meter_name(this), "IO")) {
31 file = "io";
32 } else {
33 file = "memory";
34 }
35
36 bool some;
37 if (strstr(Meter_name(this), "Some")) {
38 some = true;
39 } else {
40 some = false;
41 }
42
43 Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
44 xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
45}
46
Christian Göttsche79ad39c2020-10-06 12:28:11 +020047static void PressureStallMeter_display(const Object* cast, RichString* out) {
48 const Meter* this = (const Meter*)cast;
Nathan Scott2be09922020-08-20 13:59:41 +100049 char buffer[20];
50 xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
51 RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
52 xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]);
53 RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer);
54 xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]);
55 RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer);
56}
57
Christian Göttsche7af06652020-10-13 14:35:30 +020058const MeterClass PressureStallCPUSomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +100059 .super = {
60 .extends = Class(Meter),
61 .delete = Meter_delete,
62 .display = PressureStallMeter_display,
63 },
64 .updateValues = PressureStallMeter_updateValues,
65 .defaultMode = TEXT_METERMODE,
66 .maxItems = 3,
67 .total = 100.0,
68 .attributes = PressureStallMeter_attributes,
69 .name = "PressureStallCPUSome",
70 .uiName = "Pressure Stall Information, some CPU",
71 .caption = "Some CPU pressure: "
72};
73
Christian Göttsche7af06652020-10-13 14:35:30 +020074const MeterClass PressureStallIOSomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +100075 .super = {
76 .extends = Class(Meter),
77 .delete = Meter_delete,
78 .display = PressureStallMeter_display,
79 },
80 .updateValues = PressureStallMeter_updateValues,
81 .defaultMode = TEXT_METERMODE,
82 .maxItems = 3,
83 .total = 100.0,
84 .attributes = PressureStallMeter_attributes,
85 .name = "PressureStallIOSome",
86 .uiName = "Pressure Stall Information, some IO",
87 .caption = "Some IO pressure: "
88};
89
Christian Göttsche7af06652020-10-13 14:35:30 +020090const MeterClass PressureStallIOFullMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +100091 .super = {
92 .extends = Class(Meter),
93 .delete = Meter_delete,
94 .display = PressureStallMeter_display,
95 },
96 .updateValues = PressureStallMeter_updateValues,
97 .defaultMode = TEXT_METERMODE,
98 .maxItems = 3,
99 .total = 100.0,
100 .attributes = PressureStallMeter_attributes,
101 .name = "PressureStallIOFull",
102 .uiName = "Pressure Stall Information, full IO",
103 .caption = "Full IO pressure: "
104};
105
Christian Göttsche7af06652020-10-13 14:35:30 +0200106const MeterClass PressureStallMemorySomeMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +1000107 .super = {
108 .extends = Class(Meter),
109 .delete = Meter_delete,
110 .display = PressureStallMeter_display,
111 },
112 .updateValues = PressureStallMeter_updateValues,
113 .defaultMode = TEXT_METERMODE,
114 .maxItems = 3,
115 .total = 100.0,
116 .attributes = PressureStallMeter_attributes,
117 .name = "PressureStallMemorySome",
118 .uiName = "Pressure Stall Information, some memory",
119 .caption = "Some Mem pressure: "
120};
121
Christian Göttsche7af06652020-10-13 14:35:30 +0200122const MeterClass PressureStallMemoryFullMeter_class = {
Nathan Scott2be09922020-08-20 13:59:41 +1000123 .super = {
124 .extends = Class(Meter),
125 .delete = Meter_delete,
126 .display = PressureStallMeter_display,
127 },
128 .updateValues = PressureStallMeter_updateValues,
129 .defaultMode = TEXT_METERMODE,
130 .maxItems = 3,
131 .total = 100.0,
132 .attributes = PressureStallMeter_attributes,
133 .name = "PressureStallMemoryFull",
134 .uiName = "Pressure Stall Information, full memory",
135 .caption = "Full Mem pressure: "
136};