diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2006-03-04 18:16:49 +0000 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2006-03-04 18:16:49 +0000 |
commit | d6231bab89d634da5564491196b7c478db038505 (patch) | |
tree | bfc0bf00b138763eb41132fd27a8f389a78bf3a4 /LoadMeter.c |
Initial import.
Diffstat (limited to 'LoadMeter.c')
-rw-r--r-- | LoadMeter.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/LoadMeter.c b/LoadMeter.c new file mode 100644 index 00000000..21f5d2fc --- /dev/null +++ b/LoadMeter.c @@ -0,0 +1,63 @@ +/* +htop +(C) 2004-2006 Hisham H. Muhammad +Released under the GNU GPL, see the COPYING file +in the source distribution for its full text. +*/ + +#include "LoadMeter.h" +#include "Meter.h" + +#include "ProcessList.h" + +#include "debug.h" + +/*{ + +typedef struct LoadMeter_ LoadMeter; + +struct LoadMeter_ { + Meter super; + ProcessList* pl; +}; + +}*/ + +LoadMeter* LoadMeter_new() { + LoadMeter* this = malloc(sizeof(LoadMeter)); + Meter_init((Meter*)this, String_copy("Load"), String_copy("Load: "), 1); + ((Meter*)this)->attributes[0] = LOAD; + ((Meter*)this)->setValues = LoadMeter_setValues; + ((Object*)this)->display = LoadMeter_display; + Meter_setMode((Meter*)this, GRAPH); + ((Meter*)this)->total = 1.0; + return this; +} + +/* private */ +void LoadMeter_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, + &activeProcs, &totalProcs, &lastProc); + (void) read; + assert(read == 6); + fclose(fd); +} + +void LoadMeter_setValues(Meter* cast) { + double five, fifteen; + LoadMeter_scan(&cast->values[0], &five, &fifteen); + if (cast->values[0] > cast->total) { + cast->total = cast->values[0]; + } + snprintf(cast->displayBuffer.c, 7, "%.2f", cast->values[0]); +} + +void LoadMeter_display(Object* cast, RichString* out) { + LoadMeter* this = (LoadMeter*)cast; + char buffer[20]; + RichString_prune(out); + sprintf(buffer, "%.2f ", ((Meter*)this)->values[0]); + RichString_append(out, CRT_colors[LOAD], buffer); +} |