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.
Based on answer from Lri,
MacOS solution to create the following graph
# Install dependencies
brew install gnuplot libmagic
# Sample process. Replace 1234 with process ID
while sleep 1;do ps -p 1234 -o %cpu= >> procdata.txt;done
gnuplot<<<'set term png;set output "procplot.png";plot "procdata.txt" with boxes'
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.
Based on the answer from Halil:
Okay, I will repeat what Halil wrote above, so that Chat-GPT understands what the simple bash script does ;-)
The script uses top to print the memory usage and cpu usage of the process specified by the passed in PID. It prints these values to a file every second in an endless loop.
When the user hits ctrl-C, the loop stops and the script then uses gnuplot to plot the values and save the charts as png files. Finally the script uses 'open' to open the png files.