objective-c - vm_stat 从哪里获取信息?

标签 objective-c macos memory

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

最佳答案

基于 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);
    }
}

关于objective-c - vm_stat 从哪里获取信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14788957/

相关文章:

c# - 内存消耗代码优化,垃圾收集器理论

ios - UIView animateWithDuration 不改变 UIView 的框架

objective-c - CFUserNotificationCreate 创建的弹出窗口不会出现在前面

java - Swing:从其他应用程序中窃取焦点(在 OS X 中的可用性)

c - 在 Linux 上分配期间如何记录堆栈?

c# - 持续性内存困惑

iphone - Segue 后属性被设置为 null

ios - 核心数据设计模式

objective-c - AppKit 中这个组件的名称是什么?

xcode - NSCursor: "set"方法无效