~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Validator/ExecutionTimeComparator.pm

initial import from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Validator::ExecutionTimeComparator;
 
2
 
 
3
require Exporter;
 
4
@ISA = qw(GenTest GenTest::Validator);
 
5
 
 
6
use strict;
 
7
 
 
8
use GenTest;
 
9
use GenTest::Constants;
 
10
use GenTest::Comparator;
 
11
use GenTest::Result;
 
12
use GenTest::Validator;
 
13
use Data::Dumper;
 
14
 
 
15
my @execution_times;
 
16
my %execution_ratios;
 
17
my $total_queries;
 
18
 
 
19
use constant MINIMUM_TIME_INTERVAL      => 1;   # seconds
 
20
use constant MINIMUM_RATIO              => 2;   # Minimum speed-up or slow-down required in order to report a query
 
21
 
 
22
sub validate {
 
23
        my ($comparator, $executors, $results) = @_;
 
24
 
 
25
        return STATUS_WONT_HANDLE if $#$results != 1;
 
26
 
 
27
        my $time0 = $results->[0]->duration();
 
28
        my $time1 = $results->[1]->duration();
 
29
        my $query = $results->[0]->query();
 
30
 
 
31
        return STATUS_WONT_HANDLE if $time0 == 0 || $time1 == 0;
 
32
        return STATUS_WONT_HANDLE if $time0 < MINIMUM_TIME_INTERVAL && $time1 < MINIMUM_TIME_INTERVAL;
 
33
 
 
34
        my $ratio = $time0 / $time1;
 
35
 
 
36
        say("ratio = $ratio; time0 = $time0 sec; time1 = $time1 sec; query: $query") if $ratio >= MINIMUM_RATIO;
 
37
 
 
38
        $total_queries++;
 
39
        $execution_times[0]->{sprintf('%.1f', $time0)}++;
 
40
        $execution_times[1]->{sprintf('%.1f', $time1)}++;
 
41
 
 
42
        push @{$execution_ratios{sprintf('%.1f', $ratio)}}, $query;
 
43
 
 
44
        return STATUS_OK;
 
45
}
 
46
 
 
47
sub DESTROY {
 
48
        say("Total queries: $total_queries");
 
49
        print Dumper \@execution_times;
 
50
        foreach my $ratio (sort keys %execution_ratios) {
 
51
                print "ratio = $ratio; queries = ".scalar(@{$execution_ratios{$ratio}}).":\n";
 
52
                if (
 
53
                        ($ratio <= (1 - (1 / MINIMUM_RATIO) ) ) ||
 
54
                        ($ratio >= MINIMUM_RATIO)
 
55
                ) {
 
56
                        foreach my $query (@{$execution_ratios{$ratio}}) {
 
57
                                print "$query\n";
 
58
                        }
 
59
                }
 
60
        }
 
61
}
 
62
 
 
63
1;