Ronald Yacketta wrote:
> 
>         I need to parse the following info and generate the total elapsed
> time for each function call per thread.
> 
> <09/25/02 20:03:31.974 [21168]>|thread: 6: start getContract
> <09/25/02 20:03:32.296 [21168]>|thread: 6: end successful getContract
> <09/25/02 20:07:52.778 [21168]>|thread: 7: start getContract
> <09/25/02 20:07:53.113 [21168]>|thread: 7: end successful getContract
> <09/25/02 20:07:53.115 [21168]>|thread: 7: start getProducts
> <09/25/02 20:07:53.692 [21168]>|thread: 7: end successful getProducts
> <09/25/02 20:07:53.707 [21168]>|thread: 7: start getTermsAndConds
> <09/25/02 20:07:53.867 [21168]>|thread: 7: end successful getTermsAndConds
> <09/25/02 20:07:54.538 [21168]>|thread: 8: start getContract
> <09/25/02 20:07:54.637 [21168]>|thread: 8: end successful getContract
> <09/25/02 20:07:54.639 [21168]>|thread: 8: start getProducts
> <09/25/02 20:07:55.079 [21168]>|thread: 8: end successful getProducts
> <09/25/02 20:07:55.083 [21168]>|thread: 8: start getTermsAndConds
> <09/25/02 20:07:55.193 [21168]>|thread: 8: end successful getTermsAndConds
> <09/25/02 20:07:55.747 [21168]>|thread: 9: start getContract
> <09/25/02 20:07:55.865 [21168]>|thread: 9: end successful getContract
> <09/25/02 20:07:55.867 [21168]>|thread: 9: start getProducts
> <09/25/02 20:07:56.442 [21168]>|thread: 9: end successful getProducts
> <09/25/02 20:07:56.446 [21168]>|thread: 9: start getTermsAndConds
> <09/25/02 20:07:56.541 [21168]>|thread: 9: end successful getTermsAndConds
> 
> So, thread 6 has a start getContract and a end successful getContract with a
> differenance in time of 0.322
> 
> My initial thought was to slurp the file and parse it line by line, added
> the "date" "thread #" and "start call" to a hash if ( /start/ ). I would
> also add the /end successful/ info into the hash, then after the parsing is
> done weed throught the hash matching up the threads for each start/end and
> getting the time diff.


This should do what you want:

use Time::Local;

my %data;
while ( <DATA> ) {
    next unless m!(\d\d)/(\d\d)/(\d\d)\s+
                  (\d\d):(\d\d):(\d\d)(.\d+)\s.*
                  thread:\s+(\d+):\s+
                  (end\s+successful|start)\s+(\S+)!x;
    my $time = timegm( $6, $5, $4, $2, $1 - 1, $3 + 2000 ) . $7;
    if ( $9 eq 'start' ) {
        $data{ "$8\0$10" } -= $time;
        }
    elsif ( $9 eq 'end successful' ) {
        $data{ "$8\0$10" } += $time;
        }
    }

for my $key ( sort keys %data ) {
    my ( $thread, $name ) = split /\0/, $key;
    print "Thread: $thread   Function: $name   Time: $data{$key}\n";
    }

__END__




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to