implement loadavg

This commit is contained in:
Doug MacEachern 2004-09-06 16:14:16 +00:00
parent 6ecab7bba0
commit 29bb85ca7a
2 changed files with 20 additions and 3 deletions

View File

@ -89,9 +89,25 @@ int sigar_uptime_get(sigar_t *sigar,
int sigar_loadavg_get(sigar_t *sigar, int sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg) sigar_loadavg_t *loadavg)
{ {
loadavg->loadavg[0] = -1; int i;
loadavg->loadavg[1] = -1; struct tbl_loadavg avg;
loadavg->loadavg[2] = -1;
if (table(TBL_LOADAVG, 0, &avg, 1, sizeof(avg)) < 0) {
return errno;
}
if (avg.tl_lscale) {
for (i=0; i<3; i++) {
loadavg->loadavg[i] =
((double)avg.tl_avenrun.l[i] /
(double)avg.tl_lscale);
}
}
else {
for (i=0; i<3; i++) {
loadavg->loadavg[i] = avg.tl_avenrun.d[i];
}
}
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -7,6 +7,7 @@
#undef usr #undef usr
#undef sys #undef sys
#include <errno.h>
#include <sys/vm.h> #include <sys/vm.h>
#include <mach.h> #include <mach.h>