May 17

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.

5 Responses

  1. yzf600 Says:

    If you ever need to profile individual parts of your perl scripts to improve on their runtime, check out the Devel::DProf package.

  2. jason Says:

    Sage advice. Thanks!

  3. AndrewBoldman Says:

    Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  4. jason Says:

    Thanks a lot !

  5. Player Profiles Says:

    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.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.