vm_stat
使用哪些库/系统调用/文件来获取有关活动页面,非活动页面等的信息?
答案 0 :(得分:3)
根据Apple's site上的代码,核心数据似乎来自host_statistics64
:
get_stats(&vm_stat);
sspstat("Pages free:", (uint64_t) (vm_stat.free_count - vm_stat.speculative_count));
sspstat("Pages active:", (uint64_t) (vm_stat.active_count));
sspstat("Pages inactive:", (uint64_t) (vm_stat.inactive_count));
sspstat("Pages speculative:", (uint64_t) (vm_stat.speculative_count));
sspstat("Pages wired down:", (uint64_t) (vm_stat.wire_count));
void
get_stats(vm_statistics64_t stat)
{
unsigned int count = HOST_VM_INFO64_COUNT;
kern_return_t ret;
if ((ret = host_statistics64(myHost, HOST_VM_INFO64, (host_info64_t)stat, &count) != KERN_SUCCESS)) {
fprintf(stderr, "%s: failed to get statistics. error %d\n", pgmname, ret);
exit(EXIT_FAILURE);
}
if (stat->lookups == 0)
percent = 0;
else {
/*
* We have limited precision with the 32-bit natural_t fields
* in the vm_statistics structure. There's nothing we can do
* about counter overflows, but we can avoid percentage
* calculation overflows by doing the computation in floating
* point arithmetic ...
*/
percent = (natural_t)(((double)stat->hits*100)/stat->lookups);
}
}