Monitoring a Perl program
Posted by enquirer (enquirer), 9 February 2004I have a Perl program that takes a long time to run. How can I check up on its progress - I want to know if it has got into an infinite loop or not, or if it's still running just how much longer it's likely to take
Posted by admin (Graham Ellis), 9 February 2004Big question this one - lots of possible answers and options.
For starters, if your program has a big loop that occupies most of the time you might like to put a printf statement in there, output to STDERR rather that STDOUT, and give the loop count, percentage of the way through, or something like that. Here's a code sample:
Few things to note:
* $| turns on autoflush mode (so that your carefully added alerts don't just get buffered).
* \r is used rather that \n to ensure that each alerts overrights the previous
* printf is used to ensure all lines are the same length
If you have a loop that goes round "millions" of times, you won't want to print in every loop - follow your print statement with
if (++$freq%50 == 0)
or something like that - it will print just one line in every 50!
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho