2006-03-04 18:16:49 +00:00
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - LoadAverageMeter.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "LoadAverageMeter.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
|
|
|
#include "CRT.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Object.h"
|
2014-11-27 21:57:24 +00:00
|
|
|
#include "Platform.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "RichString.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "XUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
|
2020-09-28 10:23:07 +00:00
|
|
|
static const int LoadAverageMeter_attributes[] = {
|
|
|
|
LOAD_AVERAGE_ONE,
|
|
|
|
LOAD_AVERAGE_FIVE,
|
|
|
|
LOAD_AVERAGE_FIFTEEN
|
2006-06-06 20:41:01 +00:00
|
|
|
};
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-28 10:23:07 +00:00
|
|
|
static const int LoadMeter_attributes[] = {
|
|
|
|
LOAD
|
|
|
|
};
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2016-05-04 05:39:26 +00:00
|
|
|
static void LoadAverageMeter_updateValues(Meter* this, char* buffer, int size) {
|
2015-11-23 05:46:43 +00:00
|
|
|
Platform_getLoadAverage(&this->values[0], &this->values[1], &this->values[2]);
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[0], this->values[1], this->values[2]);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
static void LoadAverageMeter_display(const Object* cast, RichString* out) {
|
|
|
|
const Meter* this = (const Meter*)cast;
|
2006-03-04 18:16:49 +00:00
|
|
|
char buffer[20];
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
2015-11-23 05:46:43 +00:00
|
|
|
RichString_write(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[1]);
|
2006-03-04 18:16:49 +00:00
|
|
|
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[2]);
|
2015-11-23 05:46:43 +00:00
|
|
|
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
|
2006-04-10 20:40:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 05:39:26 +00:00
|
|
|
static void LoadMeter_updateValues(Meter* this, char* buffer, int size) {
|
2006-04-10 20:40:38 +00:00
|
|
|
double five, fifteen;
|
2014-11-27 21:57:24 +00:00
|
|
|
Platform_getLoadAverage(&this->values[0], &five, &fifteen);
|
2006-04-10 20:40:38 +00:00
|
|
|
if (this->values[0] > this->total) {
|
|
|
|
this->total = this->values[0];
|
|
|
|
}
|
2017-07-27 19:07:50 +00:00
|
|
|
xSnprintf(buffer, size, "%.2f", this->values[0]);
|
2006-04-10 20:40:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
static void LoadMeter_display(const Object* cast, RichString* out) {
|
|
|
|
const Meter* this = (const Meter*)cast;
|
2006-04-10 20:40:38 +00:00
|
|
|
char buffer[20];
|
2020-10-06 09:40:24 +00:00
|
|
|
xSnprintf(buffer, sizeof(buffer), "%.2f ", this->values[0]);
|
2010-11-22 12:40:20 +00:00
|
|
|
RichString_write(out, CRT_colors[LOAD], buffer);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const MeterClass LoadAverageMeter_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete,
|
|
|
|
.display = LoadAverageMeter_display,
|
|
|
|
},
|
2016-05-04 05:39:26 +00:00
|
|
|
.updateValues = LoadAverageMeter_updateValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2014-01-16 03:40:47 +00:00
|
|
|
.maxItems = 3,
|
2008-03-09 08:58:38 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = LoadAverageMeter_attributes,
|
|
|
|
.name = "LoadAverage",
|
|
|
|
.uiName = "Load average",
|
2015-11-04 10:53:17 +00:00
|
|
|
.description = "Load averages: 1 minute, 5 minutes, 15 minutes",
|
2008-03-09 08:58:38 +00:00
|
|
|
.caption = "Load average: "
|
|
|
|
};
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const MeterClass LoadMeter_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.super = {
|
|
|
|
.extends = Class(Meter),
|
|
|
|
.delete = Meter_delete,
|
|
|
|
.display = LoadMeter_display,
|
|
|
|
},
|
2016-05-04 05:39:26 +00:00
|
|
|
.updateValues = LoadMeter_updateValues,
|
2012-12-05 15:12:20 +00:00
|
|
|
.defaultMode = TEXT_METERMODE,
|
2016-03-11 02:54:34 +00:00
|
|
|
.maxItems = 1,
|
2008-03-09 08:58:38 +00:00
|
|
|
.total = 100.0,
|
|
|
|
.attributes = LoadMeter_attributes,
|
|
|
|
.name = "Load",
|
|
|
|
.uiName = "Load",
|
2015-02-03 21:31:44 +00:00
|
|
|
.description = "Load: average of ready processes in the last minute",
|
2008-03-09 08:58:38 +00:00
|
|
|
.caption = "Load: "
|
|
|
|
};
|