Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the memory usage of a OS X/macOS process

Tags:

command

macos

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?

like image 992
ryo Avatar asked Dec 18 '16 05:12

ryo


People also ask

How do you collect data on CPU utilization and memory usage on Mac?

View CPU activity on your Mac in the Activity Monitor window. To enable viewing in the Dock, choose View > Dock Icon, then select the Show CPU option you want to view. In the Activity Monitor app on your Mac, do any of the following: To view processor activity over time, click CPU (or use the Touch Bar).


2 Answers

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
like image 150
Mark Setchell Avatar answered Oct 06 '22 02:10

Mark Setchell


For me, the next command works great:

ps -axm -o %mem,rss,comm | grep <programm name>
like image 26
voltento Avatar answered Oct 06 '22 00:10

voltento