Skip to content

Instantly share code, notes, and snippets.

@mattsta
Created December 23, 2021 20:45
Show Gist options
  • Save mattsta/e63b7be8ccbb002ad09aa1465095a01b to your computer and use it in GitHub Desktop.
Save mattsta/e63b7be8ccbb002ad09aa1465095a01b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# mac vm_stat output is unreadable by default (it reports values as multiple of 16384 byte pages),
# so convert the results to actual GB used automatically.
# this python one liner is a list comprehension because it has to hack around
# python not allowing single-line for loops directly.
vm_stat | python -c 'import sys; [print(f"{l:<35}{int(sz) * 16384 / 2**30:>15,.2f} GB") for idx, (l, sz) in enumerate(x.strip().strip(".").split(":") for x in sys.stdin) if idx > 0]'
@mattsta
Copy link
Author

mattsta commented Dec 23, 2021

before as native vm_stat:

$ vm_stat    
Mach Virtual Memory Statistics: (page size of 16384 bytes)
Pages free:                              614582.
Pages active:                           1431832.
Pages inactive:                         1569814.
Pages speculative:                       100817.
Pages throttled:                              0.
Pages wired down:                        283645.
Pages purgeable:                          56525.
"Translation faults":               26400198140.
Pages copy-on-write:                 2219940457.
Pages zero filled:                   8608824109.
Pages reactivated:                      5719368.
Pages purged:                          10799701.
File-backed pages:                       839523.
Anonymous pages:                        2262940.
Pages stored in compressor:              585963.
Pages occupied by compressor:            137186.
Decompressions:                          791524.
Compressions:                           1525031.
Pageins:                               65164717.
Pageouts:                                145608.
Swapins:                                      0.
Swapouts:                                     0.

after as vmstat.sh:

$ ./vmstat.sh 
Pages free                                    9.61 GB
Pages active                                 21.60 GB
Pages inactive                               23.91 GB
Pages speculative                             1.54 GB
Pages throttled                               0.00 GB
Pages wired down                              4.39 GB
Pages purgeable                               0.86 GB
"Translation faults"                    402,814.48 GB
Pages copy-on-write                      33,871.85 GB
Pages zero filled                       131,353.15 GB
Pages reactivated                            87.27 GB
Pages purged                                164.79 GB
File-backed pages                            12.81 GB
Anonymous pages                              34.24 GB
Pages stored in compressor                    8.94 GB
Pages occupied by compressor                  2.09 GB
Decompressions                               12.08 GB
Compressions                                 23.27 GB
Pageins                                     994.33 GB
Pageouts                                      2.22 GB
Swapins                                       0.00 GB
Swapouts                                      0.00 GB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment