~ubuntu-branches/ubuntu/vivid/drizzle/vivid-proposed

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/lib/GenTest/QueryPerformance.pm

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2013-08-22 20:18:31 UTC
  • mto: (20.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20130822201831-gn3ozsh7o7wmc5tk
Tags: upstream-7.2.3
ImportĀ upstreamĀ versionĀ 7.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This program is free software; you can redistribute it and/or modify
 
2
# it under the terms of the GNU General Public License as published by
 
3
# the Free Software Foundation; version 2 of the License.
 
4
#
 
5
# This program is distributed in the hope that it will be useful, but
 
6
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
7
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
8
# General Public License for more details.
 
9
#
 
10
# You should have received a copy of the GNU General Public License
 
11
# along with this program; if not, write to the Free Software
 
12
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 
13
# USA
 
14
 
 
15
package GenTest::QueryPerformance;
 
16
 
 
17
require Exporter;
 
18
@ISA = qw(GenTest);
 
19
 
 
20
use strict;
 
21
use GenTest;
 
22
 
 
23
use constant PERFORMANCE_DBH            => 0;
 
24
use constant PERFORMANCE_VERSION        => 1;
 
25
use constant PERFORMANCE_QUERY          => 2;
 
26
use constant PERFORMANCE_SESSION_STATUS => 3;
 
27
use constant PERFORMANCE_EXECUTION_TIME => 4;
 
28
 
 
29
1;
 
30
 
 
31
my %innodb_baseline;
 
32
 
 
33
sub new {
 
34
        my $class = shift;
 
35
        my $performance = $class->SUPER::new({
 
36
                'dbh'                   => PERFORMANCE_DBH,
 
37
                'version'               => PERFORMANCE_VERSION,
 
38
                'query'                 => PERFORMANCE_QUERY,
 
39
                'execution_time'        => PERFORMANCE_EXECUTION_TIME
 
40
        }, @_);
 
41
 
 
42
        $performance->dbh()->do("FLUSH STATUS");
 
43
        %innodb_baseline = @{$performance->dbh()->selectcol_arrayref("SHOW GLOBAL STATUS LIKE 'Innodb_%'",  { Columns=>[1,2] })};
 
44
        $performance->[PERFORMANCE_VERSION] = $performance->dbh()->selectrow_array('SELECT @@version');
 
45
 
 
46
        return $performance;
 
47
}
 
48
 
 
49
sub record {
 
50
        my $performance = shift;
 
51
 
 
52
        my %status_hash = @{$performance->dbh()->selectcol_arrayref("SHOW SESSION STATUS",  { Columns=>[1,2] })};
 
53
 
 
54
        foreach my $variable_name (keys %status_hash) {
 
55
                delete $status_hash{$variable_name} if $variable_name =~ m{^(com_|qcache_|ssl_)}sgio;
 
56
                delete $status_hash{$variable_name} if $variable_name =~ m{^(threads_created|uptime|opened_files|queries|connections)}sgio;
 
57
                delete $status_hash{$variable_name} if $variable_name =~ m{^(aria_|innodb_)}sgio;
 
58
 
 
59
                delete $status_hash{$variable_name} if $variable_name !~ m{^handler}sgio;
 
60
        
 
61
#               delete $status_hash{$variable_name} if $status_hash{$variable_name} eq '0';
 
62
        }
 
63
 
 
64
        my %innodb_hash = @{$performance->dbh()->selectcol_arrayref("SHOW GLOBAL STATUS LIKE 'Innodb_%'",  { Columns=>[1,2] })};
 
65
 
 
66
        foreach my $variable_name (keys %innodb_hash) {
 
67
                $status_hash{$variable_name} = $innodb_hash{$variable_name} - $innodb_baseline{$variable_name};
 
68
        }
 
69
 
 
70
        $performance->[PERFORMANCE_SESSION_STATUS] = \%status_hash;
 
71
}
 
72
 
 
73
sub query {
 
74
        return $_[0]->[PERFORMANCE_QUERY];
 
75
}
 
76
 
 
77
sub sessionStatusVariable {
 
78
        return $_[0]->[PERFORMANCE_SESSION_STATUS]->{$_[1]};
 
79
}
 
80
 
 
81
sub sessionStatusVariables {
 
82
        return $_[0]->[PERFORMANCE_SESSION_STATUS];
 
83
}
 
84
 
 
85
sub executionTime {
 
86
        return $_[0]->[PERFORMANCE_EXECUTION_TIME];
 
87
}
 
88
 
 
89
sub setExecutionTime {
 
90
        $_[0]->[PERFORMANCE_EXECUTION_TIME] = $_[1];
 
91
}
 
92
 
 
93
sub dbh {
 
94
        return $_[0]->[PERFORMANCE_DBH];
 
95
}
 
96
 
 
97
sub version {
 
98
        return $_[0]->[PERFORMANCE_VERSION];
 
99
}
 
100
 
 
101
1;