freebsd swap metrics

This commit is contained in:
Doug MacEachern 2005-02-09 03:36:54 +00:00
parent f2b66f82cb
commit ac37c62faa
2 changed files with 23 additions and 4 deletions

View File

@ -11,6 +11,7 @@
#include <sys/types.h>
#include <sys/param.h>
#include <sys/user.h>
#include <fcntl.h>
#endif
#include <sys/ioctl.h>
@ -55,6 +56,8 @@ int sigar_os_open(sigar_t **sigar)
#ifdef DARWIN
(*sigar)->mach_port = mach_host_self();
#else
(*sigar)->kp = kvm_open(NULL, NULL, NULL, O_RDONLY, "kvm_open");
#endif
(*sigar)->ncpu = ncpu;
@ -193,10 +196,22 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
swap->free = swap->total - swap->used;
#else
/*XXX*/
swap->total = 0;
swap->used = 0;
swap->free = 0;
struct kvm_swap kswap[1];
if (kvm_getswapinfo(sigar->kp, kswap, 1, 0) < 0) {
return errno;
}
if (kswap[0].ksw_total == 0) {
swap->total = 0;
swap->used = 0;
swap->free = 0;
return SIGAR_OK;
}
swap->total = kswap[0].ksw_total * sigar->pagesize;
swap->used = kswap[0].ksw_used * sigar->pagesize;
swap->free = swap->total - swap->used;
#endif
return SIGAR_OK;

View File

@ -4,6 +4,8 @@
#ifdef DARWIN
#include <mach/port.h>
#include <mach/host_info.h>
#else
#include <kvm.h>
#endif
#include <sys/sysctl.h>
@ -16,6 +18,8 @@ struct sigar_t {
struct kinfo_proc *pinfo;
#ifdef DARWIN
mach_port_t mach_port;
#else
kvm_t *kp;
#endif
};