I know I can use Activity Monitor (as well as a slew of 3rd party applications) to monitor the usage of RAM and CPU on my Mac. However, I want to capture a log over an amount of time so that I can compare usage between processes without having to take screen shots, etc. Something Console-like, like this:

Process A (5:22 - 5:32)

5:22:01: 2.2% CPU, 5 Threads, 111.1MB Real Mem  
5:22:03: 2.1% CPU, 4 Threads, 90.4MB Real Mem  

How can I accomplish this?


This mightn't quite hit the mark, but try this:

sar -o ~/output.sar 10 10 

That gathers 10 sets of metrics at 10 second intervals. You can then extract useful information from the output file (even while it's still running), for instance this will get you the disk activity for the interval you sampled:

sar -d -f ~/output.sar

Do a man sar to find out what other options there are.


sar doesn't do memory so this will get you the free memory on your system at ten second intervals:

vm_stat 10 | awk 'NR>2 {gsub("K","000");print ($1+$4)/256000}'

You can redirect that to a file.

If you need more information, please ask.

  • 2
    There is no sar after recent Sierra update. Is there any other command other than top and nettop? Oct 21 '16 at 2:25
  • 1
    @SkrewEverything I did find the source for sar, and I'll try to build it on Sierra later: opensource.apple.com/source/system_cmds/system_cmds-643.30.1/… Oct 21 '16 at 9:49
  • Please notify us when it's finished. Thank you. Oct 21 '16 at 12:57
  • sar will compile easily enough, but not the code that does the real work: sadc, which gets link errors. I don't see myself re-visiting in the short term. Oct 23 '16 at 16:14

You can log CPU and memory usage of processes, though not thread count, with the Python program Syrupy.

Syrupy is a Python script that regularly takes snapshots of the memory and CPU load of one or more running processes, so as to dynamically build up a profile of their usage of system resources.

Syrupy works by one of two modes. In the first (default) mode, it monitors the resource usage of a process resulting from the execution of a user-specified command (which can be any arbitrarily-complex combination of programs and arguments that can be invoked from a shell terminal). In the second mode, Syrupy monitors the resource usage of external running processes that meet user-specified criteria: a PID (Process IDentifier) number or a command string matching a regular expression pattern.

In either case, the monitoring of the system resource usage is based on repeated calls to the system command ps.

For your use case, logging every running process, I think this command would work:

syrupy.py --poll-command='.*'

You can use top and pipe data into awk or grep to read specific info you need.

Check it out here; http://ss64.com/osx/top.html

top is actually the underlying tool where Activity Monitor is build on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.