Where does vm_stat get its information from?

What libraries / system calls / files are used vm_stat

to get information about active pages, inactive pages, etc.?

+3


source to share


1 answer


Based on Apple's site code , it seems that the underlying data comes from 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 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);
    }
}

      

+3


source







All Articles