--- projects/libstatgrab/src/libstatgrab/memory_stats.c 2004/01/19 16:49:21 1.19 +++ projects/libstatgrab/src/libstatgrab/memory_stats.c 2004/02/12 23:04:52 1.20 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * - * $Id: memory_stats.c,v 1.19 2004/01/19 16:49:21 tdb Exp $ + * $Id: memory_stats.c,v 1.20 2004/02/12 23:04:52 tdb Exp $ */ #ifdef HAVE_CONFIG_H @@ -40,6 +40,12 @@ #include #include #endif +#ifdef OPENBSD +#include +#include +#include +#include +#endif mem_stat_t *get_memory_stats(){ @@ -66,9 +72,13 @@ mem_stat_t *get_memory_stats(){ u_int inactive_count; int pagesize; #endif -#ifdef NETBSD +#if defined(NETBSD) || defined(OPENBSD) struct uvmexp *uvm; #endif +#ifdef OPENBSD + int mib[2]; + size_t size; +#endif #ifdef SOLARIS if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ @@ -169,10 +179,37 @@ mem_stat_t *get_memory_stats(){ if ((uvm = get_uvmexp()) == NULL) { return NULL; } +#endif +#ifdef OPENBSD + mib[0] = CTL_VM; + mib[1] = VM_UVMEXP; + + if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) { + return NULL; + } + + uvm = malloc(size); + if (uvm == NULL) { + return NULL; + } + + if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) { + return NULL; + } +#endif +#if defined(NETBSD) || defined(OPENBSD) mem_stat.total = uvm->pagesize * uvm->npages; +#ifdef NETBSD mem_stat.cache = uvm->pagesize * (uvm->filepages + uvm->execpages); +#else + mem_stat.cache = 0; +#endif mem_stat.free = uvm->pagesize * (uvm->free + uvm->inactive); mem_stat.used = mem_stat.total - mem_stat.free; +#endif + +#ifdef OPENBSD + free(uvm); #endif return &mem_stat;