I am running a process and I want to track it's CPU usage and in the end I would like to have a graph of time vs CPU usage. Any app or script for that? I googled and I couldn't find any. And activity monitor does not give graph of over the time of the process.


You could also use a shell command like this:

while :;do ps -p 1234 -o %cpu=;sleep 1;done

Replace 1234 with the pid of the process.

You can use gnuplot to create a graph for the data:

gnuplot<<<'set term png;set output "/tmp/plot.png";plot "/tmp/data" with boxes'
qlmanage -p /tmp/plot.png
  • hey this great! I am getting the output of CPU usage on terminal and I am sure I can export it to external text file. If I understand correctly this script sleeps for every 1s before checking it. Now I need something more. The process is also spawning bunch of child processes. So with above script I assume I will only CPU usage of parent process. So if I want total CPU usage (parent and all of it's child processes), how do I go about it? [I don't care how much each individual child process is consuming] – avi Dec 17 '13 at 9:48
  • You can redirect the output to a file by adding something like >file.txt after the command. If the pid of the parent process is 1234, you can use for example ps -eo %cpu=,pid=,ppid=|awk '$2==1234||$3==1234{s+=$1}END{print s}'. – Lri Dec 19 '13 at 15:45

There are some apps that allow you to do this, but the ones that I found were paid. If you are willing to pay for one, you could try Hardware Monitor.

If not, you can try using this tip from Mac OS X Hints. With this script, it should be able to track the CPU history and export it to a document.

  • Can you confirm that HW Monitor support per process usage? – avi Dec 15 '13 at 6:43
  • I can't confirm it as I have not used the app. You can try using the demo app that is in the same website and see if it has it. Again, you can also try the second option that I pointed out. – chrisjr Dec 15 '13 at 6:44

You must log in to answer this question.

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