Skip to content

Instantly share code, notes, and snippets.

@mattsta
Created December 23, 2021 20:45
Show Gist options
  • Select an option

  • Save mattsta/e63b7be8ccbb002ad09aa1465095a01b to your computer and use it in GitHub Desktop.

Select an option

Save mattsta/e63b7be8ccbb002ad09aa1465095a01b to your computer and use it in GitHub Desktop.

Revisions

  1. mattsta created this gist Dec 23, 2021.
    9 changes: 9 additions & 0 deletions vmstat.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    #!/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]'