freebsd memory metrics

This commit is contained in:
Doug MacEachern 2005-02-09 04:19:55 +00:00
parent d879ff5bb8
commit 7d61e468b2
2 changed files with 19 additions and 5 deletions

View File

@ -12,6 +12,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/user.h> #include <sys/user.h>
#include <sys/vmmeter.h>
#include <fcntl.h> #include <fcntl.h>
#endif #endif
@ -38,6 +39,7 @@ static int get_koffsets(sigar_t *sigar)
int i; int i;
struct nlist klist[] = { struct nlist klist[] = {
{ "_cp_time" }, { "_cp_time" },
{ "_cnt" },
{ NULL } { NULL }
}; };
@ -104,6 +106,8 @@ int sigar_os_open(sigar_t **sigar)
(*sigar)->boot_time = boottime.tv_sec; /* XXX seems off a bit */ (*sigar)->boot_time = boottime.tv_sec; /* XXX seems off a bit */
(*sigar)->pagesize = getpagesize();
(*sigar)->last_pid = -1; (*sigar)->last_pid = -1;
(*sigar)->pinfo = NULL; (*sigar)->pinfo = NULL;
@ -131,7 +135,6 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
vm_statistics_data_t vmstat; vm_statistics_data_t vmstat;
kern_return_t status; kern_return_t status;
mach_msg_type_number_t count = sizeof(vmstat) / sizeof(integer_t); mach_msg_type_number_t count = sizeof(vmstat) / sizeof(integer_t);
#endif
int mib[2]; int mib[2];
int totmem; int totmem;
size_t len = sizeof(totmem); size_t len = sizeof(totmem);
@ -150,9 +153,6 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->total = totmem; mem->total = totmem;
sigar_mem_calc_ram(sigar, mem);
#ifdef DARWIN
status = host_statistics(sigar->mach_port, HOST_VM_INFO, status = host_statistics(sigar->mach_port, HOST_VM_INFO,
(host_info_t)&vmstat, &count); (host_info_t)&vmstat, &count);
@ -162,12 +162,25 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->free = vmstat.free_count * sigar->pagesize; mem->free = vmstat.free_count * sigar->pagesize;
#else #else
mem->free = 1; /*XXX*/ int status;
struct vmmeter vmem;
status = kread(sigar, &vmem, sizeof(vmem),
sigar->koffsets[KOFFSET_VMMETER]);
if (status != SIGAR_OK) {
return status;
}
mem->total = vmem.v_page_count * sigar->pagesize;
mem->free = vmem.v_free_count * sigar->pagesize;
#endif #endif
mem->used = mem->total - mem->free; mem->used = mem->total - mem->free;
mem->shared = SIGAR_FIELD_NOTIMPL; /*XXX*/ mem->shared = SIGAR_FIELD_NOTIMPL; /*XXX*/
sigar_mem_calc_ram(sigar, mem);
mem->actual_free = mem->free; mem->actual_free = mem->free;
mem->actual_used = mem->used; mem->actual_used = mem->used;

View File

@ -12,6 +12,7 @@
enum { enum {
KOFFSET_CPUINFO, KOFFSET_CPUINFO,
KOFFSET_VMMETER,
KOFFSET_MAX KOFFSET_MAX
}; };