aboutsummaryrefslogtreecommitdiffstats
path: root/LoadAverageMeter.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:15 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:15 +0200
commitd3c9975943df58e293359b87905d19ff1fd52061 (patch)
treee416378879f60e8d538b1b25963904f767d30ff4 /LoadAverageMeter.c
downloaddebian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.gz
debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.tar.bz2
debian_htop-d3c9975943df58e293359b87905d19ff1fd52061.zip
Imported Upstream version 0.5upstream/0.5
Diffstat (limited to 'LoadAverageMeter.c')
-rw-r--r--LoadAverageMeter.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
new file mode 100644
index 0000000..7add62d
--- /dev/null
+++ b/LoadAverageMeter.c
@@ -0,0 +1,69 @@
+/*
+htop
+(C) 2004 Hisham H. Muhammad
+Released under the GNU GPL, see the COPYING file
+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;
+
+struct LoadAverageMeter_ {
+ Meter super;
+ ProcessList* pl;
+};
+
+}*/
+
+/* private property */
+void LoadAverageMeter_scan(double* one, double* five, double* fifteen);
+
+LoadAverageMeter* LoadAverageMeter_new() {
+ LoadAverageMeter* this = malloc(sizeof(LoadAverageMeter));
+ Meter_init((Meter*)this, String_copy("LoadAverage"), String_copy("Load average: "), 3);
+ ((Meter*)this)->attributes[0] = CRT_colors[LOAD_AVERAGE_FIFTEEN];
+ ((Meter*)this)->attributes[1] = CRT_colors[LOAD_AVERAGE_FIVE];
+ ((Meter*)this)->attributes[2] = CRT_colors[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 */
+void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
+ int activeProcs, totalProcs, lastProc;
+ FILE *fd = fopen(PROCDIR "/loadavg", "r");
+ fscanf(fd, "%lf %lf %lf %d/%d %d", one, five, fifteen,
+ &activeProcs, &totalProcs, &lastProc);
+ 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_display(Object* cast, RichString* out) {
+ Meter* this = (Meter*)cast;
+ char buffer[20];
+ RichString_prune(out);
+ sprintf(buffer, "%.2f ", this->values[2]);
+ RichString_append(out, CRT_colors[LOAD_AVERAGE_ONE], 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);
+}

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