PepperEgg
V2EX  ›  macOS

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

  •  
  •   PepperEgg · Jun 25, 2024 · 2149 views
    This topic created in 688 days ago, the information mentioned may be changed or developed.
    简单来说现在就是需要知道物理内存和已用内存
    目前已知物理内存可以用 sysctl hw.memsize 获取
    找了半天,貌似也只能参考 top ,但是 top 输出的过于复杂。
    现在就差一个可以获取已用内存的命令 T 。T
    Supplement 1  ·  Jun 26, 2024
    找到一个命令 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%
    Supplement 2  ·  Jun 26, 2024
    上面的 append 不靠谱,代码还是得自己写。
    从 vm_stat 引出来最终答案:
    https://justinyan.me/post/3982
    4 replies    2024-06-26 15:15:12 +08:00
    niubilewodev
        1
    niubilewodev  
       Jun 25, 2024   ❤️ 1
    vm_stat
    beginor
        2
    beginor  
       Jun 25, 2024 via Android
    M 芯片的话可以试试 asitop

    brew install asitop 或者 pip install asitop
    AdamCao
        3
    AdamCao  
       Jun 26, 2024 via Android
    我用的 bottom ,看到的东西挺多的
    PepperEgg
        4
    PepperEgg  
    OP
       Jun 26, 2024
    @niubilewodev 看了下 vm_stat 实现的原理,然后找了篇文章看了下,大致知道咋回事了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1212 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 17:43 · PVG 01:43 · LAX 10:43 · JFK 13:43
    ♥ Do have faith in what you're doing.