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.
May 31st, 2009 at 5:55 pm
If you ever need to profile individual parts of your perl scripts to improve on their runtime, check out the Devel::DProf package.
May 31st, 2009 at 5:57 pm
Sage advice. Thanks!
June 4th, 2009 at 6:31 pm
Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.
June 5th, 2009 at 8:14 pm
Thanks a lot !
October 30th, 2010 at 12:05 am
Maybe you should change the page subject A quick command line way to see how much CPU a process is using | cyborgworkshop.org to more suited for your webpage you write. I loved the the writing however.