diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-11-27 19:57:24 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-11-27 19:57:24 -0200 |
commit | 529095607cd9941116c92bdc4cd52e5cc50ac415 (patch) | |
tree | 96b6ece02297f3f7562ca82c08dc158d43dfdea5 /linux/Platform.c | |
parent | ca03094bb2d60c6ee1558bd2bcfb9038244b38cb (diff) |
Isolate cross-platform code for load average.
Diffstat (limited to 'linux/Platform.c')
-rw-r--r-- | linux/Platform.c | 15 |
1 files changed, 15 insertions, 0 deletions
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); + } +} + |