--- projects/libstatgrab/src/libstatgrab/memory_stats.c 2003/03/05 21:00:59 1.5 +++ projects/libstatgrab/src/libstatgrab/memory_stats.c 2003/04/03 20:05:10 1.6 @@ -32,6 +32,11 @@ #include #include "tools.h" #endif +#ifdef FREEBSD +#include +#include +#include +#endif mem_stat_t *get_memory_stats(){ @@ -48,6 +53,11 @@ mem_stat_t *get_memory_stats(){ char *line_ptr; FILE *f; #endif +#ifdef FREEBSD + long inactive; + size_t size; + int pagesize; +#endif #ifdef SOLARIS if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ @@ -101,6 +111,55 @@ mem_stat_t *get_memory_stats(){ &mem_stat.cache))!=4){ return NULL; } + +#endif + +#ifdef FREEBSD + /* Returns byes */ + if (sysctlbyname("hw.physmem", NULL, &size, NULL, NULL) < 0){ + return NULL; + } + if (sysctlbyname("hw.physmem", &mem_stat.total, &size, NULL, NULL) < 0){ + return NULL; + } + + /*returns pages*/ + if (sysctlbyname("vm.stats.vm.v_free_count", NULL, &size, NULL, NULL) < 0){ + return NULL; + } + if (sysctlbyname("vm.stats.vm.v_free_count", &mem_stat.free, &size, NULL, NULL) < 0){ + return NULL; + } + + if (sysctlbyname("vm.stats.vm.v_inactive_count", NULL, &size, NULL, NULL) < 0){ + return NULL; + } + if (sysctlbyname("vm.stats.vm.v_inactive_count", &inactive , &size, NULL, NULL) < 0){ + return NULL; + } + + if (sysctlbyname("vm.stats.vm.v_cache_count", NULL, &size, NULL, NULL) < 0){ + return NULL; + } + if (sysctlbyname("vm.stats.vm.v_cache_count", &mem_stat.cache, &size, NULL, NULL) < 0){ + return NULL; + } + + /* Because all the vm.stats returns pages, i need to get the page size. + * After that i then need to multiple the anything that used vm.stats to get + * the system statistics by pagesize + */ + if ((pagesize=getpagesize()) == -1){ + return NULL; + } + + mem_stat.cache=mem_stat.cache*pagesize; + /* Of couse nothing is ever that simple :) And i have inactive pages to deal + * with too. So im goingto add them to free memory :) + */ + mem_stat.free=(mem_stat.free*pagesize)+(inactive*pagesize); + + mem_stat.used=mem_stat.total-mem_stat.free; #endif