1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 |
|
---|
6 | print "===== LogReportinator =====\n";
|
---|
7 | print "Converts timing information from a number of Greenstone|| logs into a\n";
|
---|
8 | print "nice CSV format.\n";
|
---|
9 | print "===========================\n";
|
---|
10 |
|
---|
11 | use Cwd;
|
---|
12 |
|
---|
13 | my $results = {};
|
---|
14 | my $dir = getcwd();
|
---|
15 |
|
---|
16 | opendir(DH, $dir);
|
---|
17 | my @files = readdir(DH);
|
---|
18 | closedir(DH);
|
---|
19 |
|
---|
20 | print " * Reading log files...\n";
|
---|
21 | my $log_file_count = 0;
|
---|
22 | my $log_failed_count = 0;
|
---|
23 | foreach my $file (@files)
|
---|
24 | {
|
---|
25 | if ($file =~ /([a-z]+)-([a-z\.]+)-W(\d+)-(\d+)\.log/i)
|
---|
26 | {
|
---|
27 | my $digital_library = $1;
|
---|
28 | my $host_machine = $2;
|
---|
29 | my $number_of_workers = $3;
|
---|
30 | my $test_run = $4;
|
---|
31 | print ' - parsing: ' . $file . '... ';
|
---|
32 | my $path = $dir . '/' . $file;
|
---|
33 | my $grep_command = 'grep "Elapsed Time:" "' . $path . '"';
|
---|
34 | my $grep_result = `$grep_command`;
|
---|
35 | if ($grep_result =~ /Elapsed Time: (\d+\.\d\d\d\d\d\d)/)
|
---|
36 | {
|
---|
37 | my $duration = $1;
|
---|
38 | if (!defined $results->{$number_of_workers})
|
---|
39 | {
|
---|
40 | $results->{$number_of_workers} = [$duration];
|
---|
41 | }
|
---|
42 | else
|
---|
43 | {
|
---|
44 | push(@{$results->{$number_of_workers}}, $duration);
|
---|
45 | }
|
---|
46 | $log_file_count++;
|
---|
47 | print "success.\n";
|
---|
48 | }
|
---|
49 | else
|
---|
50 | {
|
---|
51 | print "failed!\n";
|
---|
52 | $log_failed_count++;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | print ' * Writing results.csv...';
|
---|
58 | open(FOUT, '>:utf8', $dir . '/results.csv') or die('Failed to open file for writing.');
|
---|
59 | foreach my $number_of_workers (sort keys %{$results})
|
---|
60 | {
|
---|
61 | print FOUT $number_of_workers . ',' . join(',', @{$results->{$number_of_workers}}) . "\n";
|
---|
62 | }
|
---|
63 | close(FOUT);
|
---|
64 | print "written!\n";
|
---|
65 |
|
---|
66 | print "========== Results ========\n";
|
---|
67 | print sprintf(' Parsed log file: %4d', $log_file_count) . "\n";
|
---|
68 | print sprintf(' Failed to parse: %4d', $log_failed_count) . "\n";
|
---|
69 | print "======== Complete! ========\n\n";
|
---|
70 | exit;
|
---|