How to find memory usage like an activity monitor display in osx 10.9 and above. i have used following code to fetch memory usage.
but there is some difference between what it shows in activity monitor and what is i find by this code.
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics64_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS)
{
NSLog(@"Failed to fetch vm statistics");
}
float free_count = vm_stat.free_count * pagesize;
float active_count=vm_stat.active_count *pagesize;
float inactive_count=vm_stat.inactive_count * pagesize;
float wire_used=vm_stat.wire_count *pagesize;
float zero_fill_count=vm_stat.zero_fill_count * pagesize;
float reactivations=vm_stat.reactivations *pagesize;
float pageins=vm_stat.pageins *pagesize;
float pageouts=vm_stat.pageouts *pagesize;
float faults=vm_stat.faults *pagesize;
float cow_faults=vm_stat.cow_faults * pagesize;
float lookups=vm_stat.lookups *pagesize;
float hits=vm_stat.hits * pagesize;
float purgeable_count=vm_stat.purgeable_count * pagesize;
float purges=vm_stat.purges *pagesize;
float speculative_count=vm_stat.speculative_count *pagesize;
I am also wondering that which should i consider as App memory, File caches, wired memory and compressed memory.
Here, wired count i got using this code is same as displaying in an activity monitor.
Can some one help me out here. Thanks