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);
16
use Time::HiRes qw(sleep);
17
shift @INC; # our unshift (above)
18
shift @INC; # MaatkitTest's unshift
19
shift @INC; # Sandbox's unshift
20
require "$trunk/bin/pt-query-digest";
22
my $dp = new DSNParser(opts=>$dsn_opts);
23
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
24
my $dbh = $sb->get_dbh_for('master');
27
plan skip_all => 'Cannot connect to sandbox master';
35
# #############################################################################
36
# Issue 361: Add a --runfor (or something) option to mk-query-digest
37
# #############################################################################
38
`$trunk/bin/pt-query-digest --processlist h=127.1,P=12345,u=msandbox,p=msandbox --run-time 3 --port 12345 --log /tmp/mk-query-digest.log --pid /tmp/mk-query-digest.pid --daemonize 1>/dev/null 2>/dev/null`;
39
chomp(my $pid = `cat /tmp/mk-query-digest.pid`);
41
my $output = `ps x | grep $pid | grep processlist | grep -v grep`;
44
'Still running for --run-time (issue 361)'
48
$output = `ps x | grep $pid | grep processlist | grep -v grep`;
52
'No longer running for --run-time (issue 361)'
55
diag(`rm -rf /tmp/mk-query-digest.log`);
57
# #############################################################################
58
# Issue 1150: Make mk-query-digest --run-time behavior more flexible
59
# #############################################################################
60
@args = ('--report-format', 'query_report,profile', '--limit', '10');
62
# --run-time-mode event without a --run-time should result in the same output
63
# as --run-time-mode clock because the log ts will be effectively ignored.
65
sub { mk_query_digest::main("$trunk/t/lib/samples/slowlogs/slow033.txt",
66
'--report-format', 'query_report,profile')
70
@args = ('--report-format', 'query_report,profile', '--limit', '10');
73
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
74
qw(--run-time-mode event))
81
"Event run time mode doesn't change analysis"
86
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
87
qw(--run-time-mode event --run-time 1h)) },
88
"t/pt-query-digest/samples/slow033-rtm-event-1h.txt"
90
"Run-time mode event 1h"
93
# This is correct because the next event is 1d and 1m after the first.
94
# So runtime 1d should not include it.
97
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
98
qw(--run-time-mode event --run-time 1d)) },
99
"t/pt-query-digest/samples/slow033-rtm-event-1h.txt"
101
"Run-time mode event 1d"
104
# Now we'll get the 2nd event but not the 3rd.
107
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
108
qw(--run-time-mode event --run-time 25h)) },
109
"t/pt-query-digest/samples/slow033-rtm-event-25h.txt"
111
"Run-time mode event 25h"
115
push @args, qw(--iterations 0);
118
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
119
qw(--run-time-mode interval --run-time 1d)) },
120
"t/pt-query-digest/samples/slow033-rtm-interval-1d.txt"
122
"Run-time mode interval 1d"
125
# This correctly splits these two events:
126
# Time: 090727 11:19:30 # User@Host: [SQL_SLAVE] @ []
127
# Time: 090727 11:19:31 # User@Host: [SQL_SLAVE] @ []
128
# The first belongs to the 0-29s interval, the second to the
132
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
133
qw(--run-time-mode interval --run-time 30)) },
134
"t/pt-query-digest/samples/slow033-rtm-interval-30s.txt"
136
"Run-time mode interval 30s"
139
# Now, contrary to the above, those two events are together because they're
140
# within the same 30m interval.
143
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
144
qw(--run-time-mode interval --run-time 30m)) },
145
"t/pt-query-digest/samples/slow033-rtm-interval-30m.txt",
147
"Run-time mode interval 30m"
150
pop @args; # report --iterations 0
152
# Like the first 30s run above, but with only 3 interations, only the
153
# first 3 queries are gotten.
156
sub { mk_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
157
qw(--run-time-mode interval --run-time 30 --iterations 3)) },
158
"t/pt-query-digest/samples/slow033-rtm-interval-30s-3iter.txt"
160
"Run-time mode interval and --iterations"
163
# #############################################################################
165
# #############################################################################
166
$sb->wipe_clean($dbh);