23

In Ubuntu, /usr/bin/time -v any-command tells me the memory usage of any-command and some information. (Source: https://stackoverflow.com/a/774601/2885946)

I want to do the same thing in OS X/macOS.

Could you tell me how to get the memory usage of a process on OS X like /usr/bin/time -v in Ubuntu?

Community
  • 1
  • 1
ryo
  • 2,009
  • 5
  • 24
  • 44
  • 1
    The best way is to just install GNU `time` using homebrew. See http://stackoverflow.com/questions/32515381/mac-os-x-usr-bin-time-verbose-flag/32515486#32515486 – sideshowbarker Dec 18 '16 at 07:06

2 Answers2

55

You can use the Apple-supplied /usr/bin/time as follows without installing anything:

/usr/bin/time -l <DO SOMETHING>

It is important to use the full path /usr/bin/time because time calls bash and results in error: -bash: -l: command not found

Sample Output

0.04 real         
0.00 user
0.00 sys
   2830336  maximum resident set size       <-- peak memory usage
         0  average shared memory size
         0  average unshared data size
         0  average unshared stack size
       462  page reclaims
       253  page faults
         0  swaps
        13  block input operations
         3  block output operations
         0  messages sent
         0  messages received
         0  signals received
        26  voluntary context switches
        94  involuntary context switches
Nakilon
  • 34,866
  • 14
  • 107
  • 142
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
4

For me, the next command works great:

ps -axm -o %mem,rss,comm | grep <programm name>
voltento
  • 833
  • 10
  • 26