Skip to content

Instantly share code, notes, and snippets.

@bzamecnik
Last active January 24, 2021 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bzamecnik/ec98276548e48b19ea59a8ef96d7f03f to your computer and use it in GitHub Desktop.
Save bzamecnik/ec98276548e48b19ea59a8ef96d7f03f to your computer and use it in GitHub Desktop.
Process memory usage on OSX using GNU time
# On Linux we can use native GNU time, on OSX we have to install gnu-time
# manually, since native time doesn't measure memory.
# http://man7.org/linux/man-pages/man1/time.1.html
# http://braumeister.org/formula/gnu-time
$ brew install gnu-time
# can be called via gtime, since time is a bash command
# %M - Maximum resident set size of the process during its lifetime, in Kbytes.
# Actually it is in bytes, not kilobytes!!
# http://stackoverflow.com/questions/22732932/how-to-get-the-max-memory-usage-of-a-program-using-psutil-in-python
# usage:
$ gtime -f %M some_command arg1 arg2 ...
$ gtime --verbose some_command arg1 arg2 ...
# example - just memory:
$ gtime -f %M python --version
Python 3.4.5
6602752
# example - full info
$ gtime --verbose python --version
Python 3.4.5
Command being timed: "python --version"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 33%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.01
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 6569984
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 106
Minor (reclaiming a frame) page faults: 420
Voluntary context switches: 6
Involuntary context switches: 28
Swaps: 0
File system inputs: 4
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment