scripts: Allow to specify a limit on the number of tests reported
[kai/samba-autobuild/.git] / script / show_testsuite_time
1 #!/usr/bin/env perl
2 use Time::Local ('timegm');
3 my $in = STDIN;
4 use strict;
5
6 my $intest=0;
7 my $name;
8 my $start=0;
9 my $end=0;
10 my %hash;
11 my $fh;
12 my $max=0;
13 if ($#ARGV >= 0) {
14         open($fh, "<", $ARGV[0]) || die "can't open ".$ARGV[0];
15 } else {
16         $fh = $in;
17 }
18 if ($#ARGV >= 1) {
19         $max = $ARGV[1];
20 }
21
22 while(<$fh>)
23 {
24         if (m/^testsuite: (.*)/) {
25                 $intest = 1;
26                 $name = $1;
27         }
28         if (m/testsuite-\w+:/) {
29                 $hash{"$name -> ".($end - $start)} = $end - $start;
30                 $intest = 0;
31                 $start = 0;
32         }
33         if (m/^time: (\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/ && $intest) {
34                 my $ts=timegm($6,$5,$4,$3,$2 - 1,$1 - 1900);
35                 if ($start == 0) {
36                         $start = $ts;
37                 } else {
38                         $end = $ts;
39                 }
40         }
41 }
42 my @sorted = sort { $hash{$b}<=>$hash{$a} } keys(%hash);
43 $max = $#sorted unless $max or ($max < $#sorted);
44 for my $l (@sorted[0..($max - 1)]) {
45         print $l."\n";
46 }