简体   繁体   English

如何在mac OSX中查找内存使用情况?

[英]How to find memory usage in mac OSX?

How to find memory usage like an activity monitor display in osx 10.9 and above. 如何在osx 10.9及更高版本中查找活动监视器显示的内存使用情况。 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 谢谢

您可以使用此appMemory = vm_page_size *(vm_stat.internal_page_count - vm_stat.purgeable_count)找到App内存;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM