【问题标题】:Where does vm_stat get its information from?vm_stat 从哪里获取信息?
【发布时间】:2013-02-09 14:06:13
【问题描述】:

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

【问题讨论】:

    标签: objective-c macos memory


    【解决方案1】:

    根据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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      • 1970-01-01
      相关资源
      最近更新 更多