Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: perl program status

by Lexicon (Chaplain)
on Apr 05, 2001 at 04:42 UTC ( [id://69961]=note: print w/replies, xml ) Need Help??


in reply to perl program status

I think I have a different take on what you're after than everyone else. I've written a few jobs that take an hour or so to finish, and I want to know that they're proceeding along smoothly. This is also pretty standard for debugging things in the first place, so if you set this up first it will help with your debugging and give you status afterwards. I assume you're doing everything at the command line and not TK or anything...

First, build a standard subroutine to do all your output for you. Mine follows. It prints my status messages where I want them as well as the message index, the time, and the elapsed time.

Before every major section, Log what you are about to do. Give the message a nice bold start so you know you're at a major heading. If you are processing and you want status of the processing, put an if statement in your loop and print some status every 1000 iterations or whatever is apropriate. If it's really heavy processing, the single if shouldn't slow you down too much, especially if you're calling subroutines, at least if Fundamental Benchmarks has any validity. Put some dashes in front of the message so you know you're in a subsection. I also like to throw in some extra processing to give me an Estimated Time To Completion. I have never ever seen this value be very accurate, as programs tend to slow down after a while of heavy processing. But I do it anyway.

Hope this helps!

my $Start_Time = time; my $LogFile = "logfile.log"; my $ProgressIndex = 1; my $i = 0; EnterIntoLog ("My freaky message"); $i *= $i for (1..10000000); EnterIntoLog ("Another message"); sub EnterIntoLog { my $message = shift; my $Now = time; my $Seconds_Past = int ($Now - $Start_Time); my $Minutes = int ($Seconds_Past/60); my $Seconds = $Seconds_Past % 60; my $ProgressString = sprintf ( "%05d\t" . localtime($Now) . "\t%02d:%02d\t$message\n", $ProgressIndex++, $Minutes, $Seconds); print $ProgressString; open LOG, ">>$LogFile" or die "Can't open $LogFile: $!\n"; print LOG $ProgressString or die "Can't print to $LogFile: $!\n"; close LOG or die "Can't close $LogFile: $!\n"; }

-Lexicon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://69961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found