add vmstat util

This commit is contained in:
Doug MacEachern 2007-08-04 18:03:28 +00:00
parent 02ab6d8730
commit ea1427b004
1 changed files with 21 additions and 7 deletions

View File

@ -244,12 +244,29 @@ char *sigar_os_error_string(sigar_t *sigar, int err)
} }
} }
#ifdef DARWIN
static int sigar_vmstat(sigar_t *sigar, vm_statistics_data_t *vmstat)
{
kern_return_t status;
mach_msg_type_number_t count = sizeof(*vmstat) / sizeof(integer_t);
status = host_statistics(sigar->mach_port, HOST_VM_INFO,
(host_info_t)vmstat, &count);
if (status == KERN_SUCCESS) {
return SIGAR_OK;
}
else {
return errno;
}
}
#endif
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem) int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
{ {
#ifdef DARWIN #ifdef DARWIN
int status;
vm_statistics_data_t vmstat; vm_statistics_data_t vmstat;
kern_return_t status;
mach_msg_type_number_t count = sizeof(vmstat) / sizeof(integer_t);
uint64_t mem_total; uint64_t mem_total;
#else #else
unsigned long mem_total; unsigned long mem_total;
@ -279,11 +296,8 @@ int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
mem->total = mem_total; mem->total = mem_total;
#if defined(DARWIN) #if defined(DARWIN)
status = host_statistics(sigar->mach_port, HOST_VM_INFO, if ((status = sigar_vmstat(sigar, &vmstat)) != SIGAR_OK) {
(host_info_t)&vmstat, &count); return status;
if (status != KERN_SUCCESS) {
return errno;
} }
mem->free = vmstat.free_count * sigar->pagesize; mem->free = vmstat.free_count * sigar->pagesize;