How to find memory usage on Mac OSX?

How to find memory usage, for example, displaying an activity monitor in osx 10.9 and higher. I used the following code to extract memory.

but there is some difference between what it shows in the activity monitor and what I can 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'm also interested in what I should consider as App memory, file caches, wired memory, and compressed memory.

Here, the wired account I used with this code is similar to that shown on the activity monitor.

Can anyone help me here. Thanks

+5
source share
1 answer

You can find the App memory using this appMemory = vm_page_size * (vm_stat.internal_page_count - vm_stat.purgeable_count);

0
source

Source: https://habr.com/ru/post/1204552/


All Articles