4

使用哪些库/系统调用/文件vm_stat来获取有关活动页面、非活动页面等的信息?

4

1 回答 1

4

根据Apple 网站上的代码,核心数据似乎来自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);
    }
}
于 2013-02-09T14:17:54.583 回答