aboutsummaryrefslogtreecommitdiffstats
path: root/LoadAverageMeter.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
committerDaniel Lange <DLange@git.local>2021-01-11 20:43:27 +0100
commitc55320e9e2a8916e911bcd39ab37b79e3a7d03b2 (patch)
treed6be9a09fdf7d6dc155de3429a70697ee2bb43b0 /LoadAverageMeter.c
parent65357c8c46154de4e4eca14075bfe5523bb5fc14 (diff)
downloaddebian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.gz
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.tar.bz2
debian_htop-c55320e9e2a8916e911bcd39ab37b79e3a7d03b2.zip
New upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'LoadAverageMeter.c')
-rw-r--r--LoadAverageMeter.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index d5424cd..0c7b833 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -24,8 +24,36 @@ static const int LoadMeter_attributes[] = {
LOAD
};
+static const int OK_attributes[] = {
+ METER_VALUE_OK
+};
+
+static const int Medium_attributes[] = {
+ METER_VALUE_WARN
+};
+
+static const int High_attributes[] = {
+ METER_VALUE_ERROR
+};
+
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, size_t size) {
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
+
+ // only show bar for 1min value
+ this->curItems = 1;
+
+ // change bar color and total based on value
+ if (this->values[0] < 1.0) {
+ this->curAttributes = OK_attributes;
+ this->total = 1.0;
+ } else if (this->values[0] < this->pl->cpuCount) {
+ this->curAttributes = Medium_attributes;
+ this->total = this->pl->cpuCount;
+ } else {
+ this->curAttributes = High_attributes;
+ this->total = 2 * this->pl->cpuCount;
+ }
+
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
}
@@ -33,19 +61,29 @@ static void LoadAverageMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
- RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
+ RichString_writeAscii(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[1]);
- RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
+ RichString_appendAscii(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[2]);
- RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
+ RichString_appendAscii(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
}
static void LoadMeter_updateValues(Meter* this, char* buffer, size_t size) {
double five, fifteen;
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
- if (this->values[0] > this->total) {
- this->total = this->values[0];
+
+ // change bar color and total based on value
+ if (this->values[0] < 1.0) {
+ this->curAttributes = OK_attributes;
+ this->total = 1.0;
+ } else if (this->values[0] < this->pl->cpuCount) {
+ this->curAttributes = Medium_attributes;
+ this->total = this->pl->cpuCount;
+ } else {
+ this->curAttributes = High_attributes;
+ this->total = 2 * this->pl->cpuCount;
}
+
xSnprintf(buffer, size, "%.2f", this->values[0]);
}
@@ -53,7 +91,7 @@ static void LoadMeter_display(const Object* cast, RichString* out) {
const Meter* this = (const Meter*)cast;
char buffer[20];
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
- RichString_write(out, CRT_colors[LOAD], buffer);
+ RichString_writeAscii(out, CRT_colors[LOAD], buffer);
}
const MeterClass LoadAverageMeter_class = {

© 2014-2024 Faster IT GmbH | imprint | privacy policy