--- projects/libstatgrab/src/libstatgrab/swap_stats.c 2003/03/07 15:43:14 1.3 +++ projects/libstatgrab/src/libstatgrab/swap_stats.c 2003/04/04 11:45:55 1.4 @@ -32,6 +32,12 @@ #include #include "tools.h" #endif +#ifdef FREEBSD +#include +#include +#include +#include +#endif swap_stat_t *get_swap_stats(){ @@ -45,6 +51,11 @@ swap_stat_t *get_swap_stats(){ FILE *f; char *line_ptr; #endif +#ifdef FREEBSD + struct kvm_swap swapinfo; + int pagesize; + kvm_t *kvmd = NULL; +#endif #ifdef SOLARIS if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ @@ -71,7 +82,21 @@ swap_stat_t *get_swap_stats(){ } fclose(f); #endif +#ifdef FREEBSD + if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){ + return NULL; + } + if ((kvm_getswapinfo(kvmd, &swapinfo, 1,0)) == -1){ + return NULL; + } + pagesize=getpagesize(); + swap_stat.total= (long long)swapinfo.ksw_total * (long long)pagesize; + swap_stat.used = (long long)swapinfo.ksw_used * (long long)pagesize; + swap_stat.free = swap_stat.total-swap_stat.used; + + kvm_close(kvmd); +#endif return &swap_stat; }