summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-11-27 19:57:24 -0200
committerHisham Muhammad <hisham@gobolinux.org>2014-11-27 19:57:24 -0200
commit529095607cd9941116c92bdc4cd52e5cc50ac415 (patch)
tree96b6ece02297f3f7562ca82c08dc158d43dfdea5
parentca03094bb2d60c6ee1558bd2bcfb9038244b38cb (diff)
Isolate cross-platform code for load average.
-rw-r--r--LoadAverageMeter.c20
-rw-r--r--linux/Platform.c15
-rw-r--r--unsupported/Platform.c6
3 files changed, 24 insertions, 17 deletions
diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c
index 850f8029..3ccd6c09 100644
--- a/LoadAverageMeter.c
+++ b/LoadAverageMeter.c
@@ -8,8 +8,7 @@ in the source distribution for its full text.
#include "LoadAverageMeter.h"
#include "CRT.h"
-
-#include <assert.h>
+#include "Platform.h"
/*{
#include "Meter.h"
@@ -21,21 +20,8 @@ int LoadAverageMeter_attributes[] = {
int LoadMeter_attributes[] = { LOAD };
-static inline void LoadAverageMeter_scan(double* one, double* five, double* fifteen) {
- int activeProcs, totalProcs, lastProc;
- *one = 0; *five = 0; *fifteen = 0;
- FILE *fd = fopen(PROCDIR "/loadavg", "r");
- if (fd) {
- int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen,
- &activeProcs, &totalProcs, &lastProc);
- (void) total;
- assert(total == 6);
- fclose(fd);
- }
-}
-
static void LoadAverageMeter_setValues(Meter* this, char* buffer, int size) {
- LoadAverageMeter_scan(&this->values[2], &this->values[1], &this->values[0]);
+ Platform_getLoadAverage(&this->values[2], &this->values[1], &this->values[0]);
snprintf(buffer, size, "%.2f/%.2f/%.2f", this->values[2], this->values[1], this->values[0]);
}
@@ -52,7 +38,7 @@ static void LoadAverageMeter_display(Object* cast, RichString* out) {
static void LoadMeter_setValues(Meter* this, char* buffer, int size) {
double five, fifteen;
- LoadAverageMeter_scan(&this->values[0], &five, &fifteen);
+ Platform_getLoadAverage(&this->values[0], &five, &fifteen);
if (this->values[0] > this->total) {
this->total = this->values[0];
}
diff --git a/linux/Platform.c b/linux/Platform.c
index f6c88170..5fe8507f 100644
--- a/linux/Platform.c
+++ b/linux/Platform.c
@@ -21,6 +21,7 @@ in the source distribution for its full text.
#include "HostnameMeter.h"
#include <math.h>
+#include <assert.h>
/*{
#include "Action.h"
@@ -78,3 +79,17 @@ int Platform_getUptime() {
}
int totalseconds = (int) floor(uptime);
}
+
+void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
+ int activeProcs, totalProcs, lastProc;
+ *one = 0; *five = 0; *fifteen = 0;
+ FILE *fd = fopen(PROCDIR "/loadavg", "r");
+ if (fd) {
+ int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen,
+ &activeProcs, &totalProcs, &lastProc);
+ (void) total;
+ assert(total == 6);
+ fclose(fd);
+ }
+}
+
diff --git a/unsupported/Platform.c b/unsupported/Platform.c
index 8d4b3a0d..b13b495b 100644
--- a/unsupported/Platform.c
+++ b/unsupported/Platform.c
@@ -48,3 +48,9 @@ MeterClass* Platform_meterTypes[] = {
int Platform_getUptime() {
return -1;
}
+
+void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
+ *one = 0;
+ *five = 0;
+ *fifteen = 0;
+}

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