#!/usr/perl/bin/perl
open(FHD, "C:\\wflogs\\WorkflowServerLog.txt") || die("can't open the file\n");
open(OFH, ">c:\\wflogs\\AverageTimeLog.txt") || die("cna't open the file\n");
my %hbegincount;
my %hendcount;
my %hbegintime;
my %hendtime;
my $lineCount = 0;
while($line = <FHD>)
{
$lineCount++;
if($lineCount < 1000000)
{
chomp($line);
my ($r1,$r2,$r3,$r4) = split(/\|/, $line);
$r1=~s/^\s+|\s+$//g;
$r2=~s/^\s+|\s+$//g;
$r3=~s/^\s+|\s+$//g;
$r4=~s/^\s+|\s+$//g;
# print "$r1,$r2,$r3,$r4 \n";
if($r4=~/begin$/i)
{
my ($r41,$r42) = split(/\s+/, $r4);
#print "begin :$r41, $r42 \n";
$hbegincount{$r41}++;
my $cltime = &CalTime($r1);
$hbegintime{$r41} += $cltime;
}
elsif($r4=~/end$/i)
{
my ($r41,$r42) = split(/\s+/, $r4);
if($hbegincount{$r41} > $hendcount{$r41})
{
$hendcount{$r41}++;
my $cltime = &CalTime($r1);
$hendtime{$r41} += $cltime;
}
}
else
{
next;
}
}
}
close(FHD);
while( my ($key, $value) = each %hbegintime )
{
#print "key : $key, $value \n";
#print "count : $hbegincount{$key} == $hendcount{$key}\n";
if($hbegincount{$key} == $hendcount{$key})
{
my $totaltime = $hendtime{$key} - $value;
my $var = $totaltime / $hbegincount{$key};
print OFH "average : $key,$var, $totaltime, $hbegincount{$key} \n";
#print "average : $key,$var, $totaltime, $hbegincount{$key} \n";
}
else
{
my $diffcount = $hbegincount{$key} - $hendcount{$key};
print OFH "diff : $key,$diffcount\n";
#print "diff : $key,$diffcount\n";
}
}
close(OFH);
sub CalTime()
{
my ($t1) = @_;
my ($t11,$t12,$t13) = split(/\:/, $t1);
my ($t131,$t132) = split(/\./, $t13);
my $totaltime;
$totaltime = $t11 * 3600 * 1000 + $t12 * 60 * 1000 + $t131 * 1000 + $t132;
return $totaltime;
}
转载于:https://www.cnblogs.com/cquccy/archive/2012/12/25/2832335.html