4
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
10
use warnings FATAL => 'all';
11
use English qw(-no_match_vars);
18
use CompareQueryTimes;
21
my $dp = new DSNParser(opts=>$dsn_opts);
22
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
23
my $dbh = $sb->get_dbh_for('master');
26
plan skip_all => "Cannot connect to sandbox master";
32
$sb->create_dbs($dbh, ['test']);
34
Transformers->import(qw(make_checksum));
39
{ dbh => $dbh, name => 'server1' },
40
{ dbh => $dbh, name => 'server2' },
44
return make_checksum(@_);
47
# #############################################################################
49
# #############################################################################
51
# diag(`/tmp/12345/use < samples/compare-warnings.sql`);
53
$ct = new CompareQueryTimes(
57
isa_ok($ct, 'CompareQueryTimes');
59
# #############################################################################
60
# Test query time comparison.
61
# #############################################################################
66
{ fingerprint => 'foo', Query_time => $t1, },
67
{ fingerprint => 'foo', Query_time => $t2, },
72
sub test_compare_query_times {
73
my ( $t1, $t2, $diff, $comment ) = @_;
74
my %diff = compare($t1, $t2);
75
my $msg = sprintf("compare t %.6f vs. %.6f %s",
76
$t1, $t2, ($comment || ''));
78
$diff{different_query_times},
84
test_compare_query_times(0, 0, 0);
85
test_compare_query_times(0, 0.000001, 1, 'increase from zero');
86
test_compare_query_times(0.000001, 0.000005, 0, 'no increase in bucket');
87
test_compare_query_times(0.000001, 0.000010, 1, '1 bucket diff on edge');
88
test_compare_query_times(0.000008, 0.000018, 1, '1 bucket diff');
89
test_compare_query_times(0.000001, 10, 1, 'full bucket range diff on edges');
90
test_compare_query_times(0.000008, 1000000, 1, 'huge diff');
93
test_compare_query_times(0.000001, 0.000006, 1, '1us threshold');
94
test_compare_query_times(0.000010, 0.000020, 1, '10us threshold');
95
test_compare_query_times(0.000100, 0.000200, 1, '100us threshold');
96
test_compare_query_times(0.001000, 0.006000, 1, '1ms threshold');
97
test_compare_query_times(0.010000, 0.015000, 1, '10ms threshold');
98
test_compare_query_times(0.100000, 0.150000, 1, '100ms threshold');
99
test_compare_query_times(1.000000, 1.200000, 1, '1s threshold');
100
test_compare_query_times(10.0, 10.1, 1, '10s threshold');
102
# #############################################################################
103
# Test the main actions, which don't do much.
104
# #############################################################################
106
fingerprint => 'set @a=?',
111
$dbh->do('set @a=1');
113
$dbh->selectcol_arrayref('select @a'),
119
$ct->before_execute(event => $event),
121
"before_execute() doesn't modify event"
124
$ct->execute(event => $event, dbh => $dbh);
127
exists $event->{Query_time}
128
&& $event->{Query_time} >= 0,
129
'execute() set Query_time'
133
$dbh->selectcol_arrayref('select @a'),
135
'Query was actually executed'
139
$ct->after_execute(event => $event),
141
"after_execute() doesn't modify event"
145
# #############################################################################
147
# #############################################################################
149
compare(0.000100, 0.000250);
152
# Significant query time differences
153
# Query ID server1 server2 %Increase %Threshold
154
# ================== ======= ======= ========= ==========
155
# EDEF654FCCC4A4D8-0 100us 250us 150.00 100
159
$ct->report(hosts => $hosts),
161
'report in bucket difference'
165
compare(0.000100, 1.100251);
168
# Big query time differences
169
# Query ID server1 server2 Difference
170
# ================== ======= ======= ==========
171
# EDEF654FCCC4A4D8-0 100us 1s 1s
175
$ct->report(hosts => $hosts),
177
'report in bucket difference'
180
# #############################################################################
182
# #############################################################################
186
open STDERR, '>', \$output;
187
$ct->_d('Complete test coverage');
191
qr/Complete test coverage/,
194
$sb->wipe_clean($dbh);