htop/linux/PressureStallMeter.c

137 lines
4.0 KiB
C
Raw Normal View History

2020-08-20 03:59:41 +00:00
/*
htop - PressureStallMeter.c
(C) 2004-2011 Hisham H. Muhammad
(C) 2019 Ran Benita
Released under the GNU GPLv2, see the COPYING file
2020-08-20 03:59:41 +00:00
in the source distribution for its full text.
*/
#include "PressureStallMeter.h"
#include <stdbool.h>
2020-08-20 03:59:41 +00:00
#include <string.h>
#include "CRT.h"
#include "Meter.h"
#include "Object.h"
#include "Platform.h"
#include "RichString.h"
2020-10-14 18:21:09 +00:00
#include "XUtils.h"
2020-08-20 03:59:41 +00:00
2020-10-13 12:35:30 +00:00
static const int PressureStallMeter_attributes[] = {
2020-08-20 03:59:41 +00:00
PRESSURE_STALL_TEN, PRESSURE_STALL_SIXTY, PRESSURE_STALL_THREEHUNDRED
};
static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) {
2020-10-31 21:14:27 +00:00
const char* file;
if (strstr(Meter_name(this), "CPU")) {
file = "cpu";
} else if (strstr(Meter_name(this), "IO")) {
file = "io";
} else {
file = "memory";
}
2020-08-20 03:59:41 +00:00
2020-10-31 21:14:27 +00:00
bool some;
if (strstr(Meter_name(this), "Some")) {
some = true;
} else {
some = false;
}
2020-08-20 03:59:41 +00:00
2020-10-31 21:14:27 +00:00
Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]);
xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]);
2020-08-20 03:59:41 +00:00
}
static void PressureStallMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
2020-08-20 03:59:41 +00:00
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[0]);
RichString_write(out, CRT_colors[PRESSURE_STALL_TEN], buffer);
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[1]);
RichString_append(out, CRT_colors[PRESSURE_STALL_SIXTY], buffer);
xSnprintf(buffer, sizeof(buffer), "%.2lf%% ", this->values[2]);
RichString_append(out, CRT_colors[PRESSURE_STALL_THREEHUNDRED], buffer);
}
2020-10-13 12:35:30 +00:00
const MeterClass PressureStallCPUSomeMeter_class = {
2020-08-20 03:59:41 +00:00
.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 = "Pressure Stall Information, some CPU",
.caption = "Some CPU pressure: "
};
2020-10-13 12:35:30 +00:00
const MeterClass PressureStallIOSomeMeter_class = {
2020-08-20 03:59:41 +00:00
.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 = "Pressure Stall Information, some IO",
.caption = "Some IO pressure: "
};
2020-10-13 12:35:30 +00:00
const MeterClass PressureStallIOFullMeter_class = {
2020-08-20 03:59:41 +00:00
.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 = "Pressure Stall Information, full IO",
.caption = "Full IO pressure: "
};
2020-10-13 12:35:30 +00:00
const MeterClass PressureStallMemorySomeMeter_class = {
2020-08-20 03:59:41 +00:00
.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 = "Pressure Stall Information, some memory",
.caption = "Some Mem pressure: "
};
2020-10-13 12:35:30 +00:00
const MeterClass PressureStallMemoryFullMeter_class = {
2020-08-20 03:59:41 +00:00
.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 = "Pressure Stall Information, full memory",
.caption = "Full Mem pressure: "
};