#!/usr/bin/perl use strict; my $dir = 'C:\lfsologs'; opendir(DIR, $dir); my @files = sort(grep /.*\.log$/, readdir DIR); closedir(DIR); my @results; my @allLogLines; my $totaltime = 0; foreach my $file (@files) { print "$dir\\$file\n"; open(INPUT, "$dir\\$file"); my @lines = ; close(INPUT); for (my $i = 0; $i < scalar @lines; $i++) { push @allLogLines, $lines[$i]; } } processLines(@allLogLines); foreach my $action (sort @results) { print "$action\n"; } print "total request time: $totaltime ms\n"; sub processLines($) { my (@logLines) = @_; my %rootCallByThreadId = {}; for (my $i = 0; $i < scalar @logLines; $i++) { my $line = $logLines[$i]; chomp($line); if ($line =~ /^(\d{2})\:(\d{2})\:(\d{2})\.(\d{3}) \[(\d{1,5})\].*[ ]+LFSession\:\:SendRequest \((.*)\)/) { my $hour = $1, my $minute = $2, my $second = $3, my $ms = $4, my $threadid = $5, my $url = $6; my $prevline = $rootCallByThreadId{$threadid}; chomp($prevline); my $request = $url . " (line " . ($i + 1) . ") (" . $prevline . ")"; my $prevtime = "UNKNOWN"; if ($prevline =~ /(\d\d:\d\d:\d\d\.\d\d\d) /) { $prevtime = $1; } my $pos = $ms; $pos += ($second * 1000); $pos += ($minute * 1000 * 60); $pos += ($hour * 1000 * 60 * 60); my $foundnext = 0; # find the next line corresponding to this request for (my $j = $i + 2; $j < scalar @logLines; $j++) { my $nextline = $logLines[$j]; chomp($nextline); if ($nextline =~ /^(\d{2})\:(\d{2})\:(\d{2})\.(\d{3}) \[(\d{1,5})\]/) { my $hour2 = $1, my $minute2 = $2, my $second2 = $3, my $ms2 = $4, my $threadid2 = $5; if ($threadid eq $threadid2) { my $pos2 = $ms2; $pos2 += ($second2 * 1000); $pos2 += ($minute2 * 1000 * 60); $pos2 += ($hour2 * 1000 * 60 * 60); my $reqtime = $pos2 + 1 - $pos - 1; $totaltime += $reqtime; my $strtime = sprintf("%6d ms", $reqtime); my $colwidth = 135; if (length($request) > $colwidth) { $request = substr($request, 0, $colwidth); } elsif (length($request) < $colwidth) { $request .= ' ' x ($colwidth - length($request)); } $colwidth = 150; if (length($url) > $colwidth) { $url = substr($url, 0, $colwidth); } elsif (length($url) < $colwidth) { $url .= ' ' x ($colwidth - length($url)); } my $rowid = sprintf("%05d", $i); push @results, "$hour:$minute:$second\t$strtime\t$url"; $foundnext = 1; last; } } } print "No response for $line\n" if (!$foundnext); } else { my $threadid = 0; if ($line =~ /^(\d{2})\:(\d{2})\:(\d{2})\.(\d{3}) \[(\d{1,5})\] \w/) { $threadid = $5; $rootCallByThreadId{$threadid} = $line; } } } }