了解 mac os 中的 vm_stat,如何将这些数字转换为类似于活动监视器的内容? [英] understanding vm_stat in mac os, how to convert those numbers to something similar to activity monitor?

查看:30
本文介绍了了解 mac os 中的 vm_stat,如何将这些数字转换为类似于活动监视器的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 mac os 程序来监视系统(类似于活动监视器).我查看了函数 vm_stat,当我运行它时,我得到了这个:

I'm trying to write a mac os program to monitor the system (something similar to the activity monitor). I have looked at the function vm_stat and when I run it I got this:

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                         438386.
Pages active:                       236438.
Pages inactive:                     113750.
Pages speculative:                   34293.
Pages wired down:                   225027.
"Translation faults":             11132566.
Pages copy-on-write:                319385.
Pages zero filled:                 6618647.
Pages reactivated:                   23071.
Pageins:                            421804.
Pageouts:                           153240.
Object cache: 14 hits of 24183 lookups (0% hit rate)

但是,当我运行活动监视器时,我得到了类似的信息:

However when I run the activity monitor, I got something like:

Page Ins: 1.61gb (8.00kb/sec)
Page outs: 598.6 MB

我有一个问题:为什么 vmstat 中的空闲页面如此之小(与活动监视器相比)

I have a question regarding this: how come the pages free in vmstat is so small (comparing to activity monitor)

推荐答案

  1. 256 是以兆字节为单位的页数(256 页 * 每页 4096 字节 = 1048576 字节 又名 220 字节又名 1 兆字节)假设一个页面是 4096字节.vm_stat 中的数字以页为单位,它还告诉您页大小为 4096 字节,因此您不必硬编码 256.
  2. 由于您没有显示 Activity Monitor 进行比较,我不能肯定地说,但我怀疑这又是由于 vm_stat 使用页面单位和使用人类可读"的活动监视器" 单位,它们确实是相同的值(或者关闭,因为 Activity Monitor 不断更新).
  1. 256 is the number of pages in a megabyte (256 pages * 4096 bytes per page = 1048576 bytes aka 220 bytes aka 1 megabyte) assuming a page is 4096 bytes. The numbers from vm_stat are in pages, and it is also telling you that the page size is 4096 bytes, so you don't need to hardcode 256 necessarily.
  2. Since you don't show Activity Monitor to compare I can't say for certain, but I suspect this is again due to vm_stat using a unit of a page and activity monitor using "human readable" units, and they are indeed the same value (or close given that Activity Monitor updates continuously).

这篇关于了解 mac os 中的 vm_stat,如何将这些数字转换为类似于活动监视器的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆