V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
PepperEgg
V2EX  ›  macOS

macOS 如何通过命令行获取内存使用率

  •  
  •   PepperEgg · 3 天前 · 639 次点击
    简单来说现在就是需要知道物理内存和已用内存
    目前已知物理内存可以用 sysctl hw.memsize 获取
    找了半天,貌似也只能参考 top ,但是 top 输出的过于复杂。
    现在就差一个可以获取已用内存的命令 T 。T
    第 1 条附言  ·  2 天前
    找到一个命令 memory_pressure
    打印信息如下
    The system has 8589934592 (524288 pages with a page size of 16384).

    Stats:
    Pages free: 21287
    Pages purgeable: 2631
    Pages purged: 7215353

    Swap I/O:
    Swapins: 0
    Swapouts: 0

    Page Q counts:
    Pages active: 152896
    Pages inactive: 131961
    Pages speculative: 24003
    Pages throttled: 0
    Pages wired down: 76102

    Compressor Stats:
    Pages used by compressor: 84657
    Pages decompressed: 11575373
    Pages compressed: 17295516

    File I/O:
    Pageins: 21261936
    Pageouts: 395439

    System-wide memory free percentage: 67%
    第 2 条附言  ·  2 天前
    上面的 append 不靠谱,代码还是得自己写。
    从 vm_stat 引出来最终答案:
    https://justinyan.me/post/3982
    4 条回复    2024-06-26 15:15:12 +08:00
    niubilewodev
        1
    niubilewodev  
       3 天前   ❤️ 1
    vm_stat
    beginor
        2
    beginor  
       3 天前 via Android
    M 芯片的话可以试试 asitop

    brew install asitop 或者 pip install asitop
    AdamCao
        3
    AdamCao  
       3 天前 via Android
    我用的 bottom ,看到的东西挺多的
    PepperEgg
        4
    PepperEgg  
    OP
       2 天前
    @niubilewodev 看了下 vm_stat 实现的原理,然后找了篇文章看了下,大致知道咋回事了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   986 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:30 · PVG 03:30 · LAX 12:30 · JFK 15:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.