Created
October 22, 2010 05:49
-
-
Save minase/640025 to your computer and use it in GitHub Desktop.
vmstatics.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vim: fileencoding=utf-8 expandtab tabstop=2 shiftwidth=2 : | |
// | |
// vmstatics.c | |
// | |
// % clang -Wall -o vmstatics vmstatics.c | |
// % ./vmstatics | |
// active 1627869184 | |
// inactive 1990959104 | |
// wired 1616474112 | |
// speculative 1243693056 | |
// free 2109575168 | |
// total 8588570624 | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <mach/mach.h> | |
int main(int argc, char **argv) | |
{ | |
vm_size_t page_size; | |
mach_port_t localhost; | |
vm_statistics64_data_t vm_stat; | |
mach_msg_type_number_t count; | |
uint64_t active, inactive, wired, speculative, free; | |
localhost = mach_host_self(); | |
if(host_page_size(localhost, &page_size) != KERN_SUCCESS) { | |
perror("host_page_size"); | |
exit(EXIT_FAILURE); | |
} | |
if(host_statistics64(localhost, HOST_VM_INFO64, (host_info64_t)&vm_stat, &count) != KERN_SUCCESS) { | |
perror("host_statistics64"); | |
exit(EXIT_FAILURE); | |
} | |
active = vm_stat.active_count * page_size; | |
inactive = vm_stat.inactive_count * page_size; | |
wired = vm_stat.wire_count * page_size; | |
speculative = vm_stat.speculative_count * page_size; | |
free = vm_stat.free_count * page_size - speculative; | |
// printf("page size %u\n", (uint32_t)page_size); | |
printf("active %llu\n", active); | |
printf("inactive %llu\n", inactive); | |
printf("wired %llu\n", wired); | |
printf("speculative %llu\n", speculative); | |
printf("free %llu\n", free); | |
printf("total %llu\n", active + inactive + wired + speculative + free); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment