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.
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.
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
15
package GenTest::QueryPerformance;
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;
35
my $performance = $class->SUPER::new({
36
'dbh' => PERFORMANCE_DBH,
37
'version' => PERFORMANCE_VERSION,
38
'query' => PERFORMANCE_QUERY,
39
'execution_time' => PERFORMANCE_EXECUTION_TIME
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');
50
my $performance = shift;
52
my %status_hash = @{$performance->dbh()->selectcol_arrayref("SHOW SESSION STATUS", { Columns=>[1,2] })};
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;
59
delete $status_hash{$variable_name} if $variable_name !~ m{^handler}sgio;
61
# delete $status_hash{$variable_name} if $status_hash{$variable_name} eq '0';
64
my %innodb_hash = @{$performance->dbh()->selectcol_arrayref("SHOW GLOBAL STATUS LIKE 'Innodb_%'", { Columns=>[1,2] })};
66
foreach my $variable_name (keys %innodb_hash) {
67
$status_hash{$variable_name} = $innodb_hash{$variable_name} - $innodb_baseline{$variable_name};
70
$performance->[PERFORMANCE_SESSION_STATUS] = \%status_hash;
74
return $_[0]->[PERFORMANCE_QUERY];
77
sub sessionStatusVariable {
78
return $_[0]->[PERFORMANCE_SESSION_STATUS]->{$_[1]};
81
sub sessionStatusVariables {
82
return $_[0]->[PERFORMANCE_SESSION_STATUS];
86
return $_[0]->[PERFORMANCE_EXECUTION_TIME];
89
sub setExecutionTime {
90
$_[0]->[PERFORMANCE_EXECUTION_TIME] = $_[1];
94
return $_[0]->[PERFORMANCE_DBH];
98
return $_[0]->[PERFORMANCE_VERSION];