From ac37c62faac92eceeeeb1fb1f89ebda0ae4ba76d Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 9 Feb 2005 03:36:54 +0000 Subject: [PATCH] freebsd swap metrics --- src/os/darwin/darwin_sigar.c | 23 +++++++++++++++++++---- src/os/darwin/sigar_os.h | 4 ++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 86a408c8..24f02b78 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -11,6 +11,7 @@ #include #include #include +#include #endif #include @@ -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; diff --git a/src/os/darwin/sigar_os.h b/src/os/darwin/sigar_os.h index ce272732..a0c50d10 100644 --- a/src/os/darwin/sigar_os.h +++ b/src/os/darwin/sigar_os.h @@ -4,6 +4,8 @@ #ifdef DARWIN #include #include +#else +#include #endif #include @@ -16,6 +18,8 @@ struct sigar_t { struct kinfo_proc *pinfo; #ifdef DARWIN mach_port_t mach_port; +#else + kvm_t *kp; #endif };