7

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?

4 Answers 4

9

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.

Edit:

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.

4
  • 3
    There is no sar after recent Sierra update. Is there any other command other than top and nettop? Commented Oct 21, 2016 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/… Commented Oct 21, 2016 at 9:49
  • Please notify us when it's finished. Thank you. Commented Oct 21, 2016 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. Commented Oct 23, 2016 at 16:14
2

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='.*'
1

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

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

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

0

There 2 options for this.

  1. netdata. This didn't work on my mac. I raised an issue on their repo but it is not resolved yet. https://github.com/netdata/netdata/issues/16696

  2. glances. Glances can track historical resource usage and it can export to 10+ tools like csv, influx, kafka, rabbitmq etc.

$ python -m pip install glances

If you want to export it to csv, you can run

$ glances --export-csv /tmp/glances.csv

I use glances + influxdb + grafana to see historical data and wrote a detailed blog post about the same here. https://avilpage.com/2024/06/macos-log-track-cpu-ram-usage.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .