I have this perl script called Get_Temperature.pl that has been giving me fits. It simply reads a serial port that gets updated every second and does some regex on those values. The script was slowly consuming more and more CPU over time and creating a huge backlog of data. By the time it had run for an hour, it was at 60% CPU. To help troubleshoot, I wanted to output the amount of CPU that the script was using every time it processed a string, so I used this.
ps -o pcpu,pid,user,args -C Get_Temperature.pl
the -C flag allows me to specify the process name instead of a PID and the output looks like this
%CPU PID USER COMMAND
0.0 1075 jason /usr/bin/perl ./Get_Temperature.pl
Quick, low impact and works.