aboutsummaryrefslogtreecommitdiffstats
path: root/LoadAverageMeter.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:20 +0200
commitea859f50d9438bc61ae96721a4d255b49de78653 (patch)
treebfb52a5f403ad1e86c562b2f4d608d1268fe8fcf /LoadAverageMeter.c
parent266ab52b3a741a58fb17c48b0f7939d7c5d266de (diff)
downloaddebian_htop-ea859f50d9438bc61ae96721a4d255b49de78653.tar.gz
debian_htop-ea859f50d9438bc61ae96721a4d255b49de78653.tar.bz2
debian_htop-ea859f50d9438bc61ae96721a4d255b49de78653.zip
Imported Upstream version 0.6.2upstream/0.6.2
Diffstat (limited to 'LoadAverageMeter.c')
-rw-r--r--LoadAverageMeter.c81
1 files changed, 50 insertions, 31 deletions
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index 824e71c..4f62260 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -1,6 +1,6 @@
/*
htop
-(C) 2004 Hisham H. Muhammad
+(C) 2004-2006 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
@@ -8,42 +8,44 @@ in the source distribution for its full text.
#include "LoadAverageMeter.h"
#include "Meter.h"
-#include "ProcessList.h"
-
#include <curses.h>
#include "debug.h"
-/*{
-
-typedef struct LoadAverageMeter_ LoadAverageMeter;
+/* private property */
+int LoadAverageMeter_attributes[] = { LOAD_AVERAGE_FIFTEEN, LOAD_AVERAGE_FIVE, LOAD_AVERAGE_ONE };
-struct LoadAverageMeter_ {
- Meter super;
- ProcessList* pl;
+/* private */
+MeterType LoadAverageMeter = {
+ .setValues = LoadAverageMeter_setValues,
+ .display = LoadAverageMeter_display,
+ .mode = TEXT_METERMODE,
+ .items = 3,
+ .total = 100.0,
+ .attributes = LoadAverageMeter_attributes,
+ .name = "LoadAverage",
+ .uiName = "Load average",
+ .caption = "Load average: "
};
-}*/
-
/* private property */
-void LoadAverageMeter_scan(double* one, double* five, double* fifteen);
+int LoadMeter_attributes[] = { LOAD };
-LoadAverageMeter* LoadAverageMeter_new() {
- LoadAverageMeter* this = malloc(sizeof(LoadAverageMeter));
- Meter_init((Meter*)this, String_copy("LoadAverage"), String_copy("Load average: "), 3);
- ((Meter*)this)->attributes[0] = LOAD_AVERAGE_FIFTEEN;
- ((Meter*)this)->attributes[1] = LOAD_AVERAGE_FIVE;
- ((Meter*)this)->attributes[2] = LOAD_AVERAGE_ONE;
- ((Object*)this)->display = LoadAverageMeter_display;
- ((Meter*)this)->setValues = LoadAverageMeter_setValues;
- Meter_setMode((Meter*)this, TEXT);
- LoadAverageMeter_scan(&((Meter*)this)->values[0], &((Meter*)this)->values[1], &((Meter*)this)->values[2]);
- ((Meter*)this)->total = 100.0;
- return this;
-}
+/* private */
+MeterType LoadMeter = {
+ .setValues = LoadMeter_setValues,
+ .display = LoadMeter_display,
+ .mode = TEXT_METERMODE,
+ .items = 1,
+ .total = 100.0,
+ .attributes = LoadMeter_attributes,
+ .name = "Load",
+ .uiName = "Load",
+ .caption = "Load: "
+};
/* private */
-void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
+inline static void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
int activeProcs, totalProcs, lastProc;
FILE *fd = fopen(PROCDIR "/loadavg", "r");
int read = fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
@@ -53,9 +55,9 @@ void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
fclose(fd);
}
-void LoadAverageMeter_setValues(Meter* cast) {
- LoadAverageMeter_scan(&cast->values[2], &cast->values[1], &cast->values[0]);
- snprintf(cast->displayBuffer.c, 25, "%.2f/%.2f/%.2f", cast->values[2], cast->values[1], cast->values[0]);
+void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
+ LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
+ snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
}
void LoadAverageMeter_display(Object* cast, RichString* out) {
@@ -63,9 +65,26 @@ void LoadAverageMeter_display(Object* cast, RichString* out) {
char buffer[20];
RichString_prune(out);
sprintf(buffer, "%.2f ", this->values[2]);
- RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
+ RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
sprintf(buffer, "%.2f ", this->values[1]);
RichString_append(out, CRT_colors[LOAD_AVERAGE_FIVE], buffer);
sprintf(buffer, "%.2f ", this->values[0]);
- RichString_append(out, CRT_colors[LOAD_AVERAGE_FIFTEEN], buffer);
+ RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], buffer);
+}
+
+void LoadMeter_setValues(Meter* this, char* buffer, int size) {
+ double five, fifteen;
+ LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
+ if (this->values[0] > this->total) {
+ this->total = this->values[0];
+ }
+ snprintf(buffer, size, "%.2f", this->values[0]);
+}
+
+void LoadMeter_display(Object* cast, RichString* out) {
+ Meter* this = (Meter*)cast;
+ char buffer[20];
+ RichString_prune(out);
+ sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]);
+ RichString_append(out, CRT_colors[LOAD], buffer);
}

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