1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use PerconaTest;
use Sandbox;
use Time::HiRes qw(sleep);
require "$trunk/bin/pt-query-digest";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
else {
plan tests => 11;
}
my @args;
# #############################################################################
# Issue 361: Add a --runfor (or something) option to mk-query-digest
# #############################################################################
`$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`;
chomp(my $pid = `cat /tmp/mk-query-digest.pid`);
sleep 2;
my $output = `ps x | grep $pid | grep processlist | grep -v grep`;
ok(
$output,
'Still running for --run-time (issue 361)'
);
sleep 1.5;
$output = `ps x | grep $pid | grep processlist | grep -v grep`;
is(
$output,
'',
'No longer running for --run-time (issue 361)'
);
diag(`rm -rf /tmp/mk-query-digest.log`);
# #############################################################################
# Issue 1150: Make mk-query-digest --run-time behavior more flexible
# #############################################################################
@args = ('--report-format', 'query_report,profile', '--limit', '10');
# --run-time-mode event without a --run-time should result in the same output
# as --run-time-mode clock because the log ts will be effectively ignored.
my $before = output(
sub { pt_query_digest::main("$trunk/t/lib/samples/slowlogs/slow033.txt",
'--report-format', 'query_report,profile')
},
);
@args = ('--report-format', 'query_report,profile', '--limit', '10');
my $after = output(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode event))
},
);
is(
$before,
$after,
"Event run time mode doesn't change analysis"
);
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode event --run-time 1h)) },
"t/pt-query-digest/samples/slow033-rtm-event-1h.txt"
),
"Run-time mode event 1h"
);
# This is correct because the next event is 1d and 1m after the first.
# So runtime 1d should not include it.
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode event --run-time 1d)) },
"t/pt-query-digest/samples/slow033-rtm-event-1h.txt"
),
"Run-time mode event 1d"
);
# Now we'll get the 2nd event but not the 3rd.
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode event --run-time 25h)) },
"t/pt-query-digest/samples/slow033-rtm-event-25h.txt"
),
"Run-time mode event 25h"
);
# Run-time interval.
push @args, qw(--iterations 0);
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode interval --run-time 1d)) },
"t/pt-query-digest/samples/slow033-rtm-interval-1d.txt"
),
"Run-time mode interval 1d"
);
# This correctly splits these two events:
# Time: 090727 11:19:30 # User@Host: [SQL_SLAVE] @ []
# Time: 090727 11:19:31 # User@Host: [SQL_SLAVE] @ []
# The first belongs to the 0-29s interval, the second to the
# 30-60s interval.
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode interval --run-time 30)) },
"t/pt-query-digest/samples/slow033-rtm-interval-30s.txt"
),
"Run-time mode interval 30s"
);
# Now, contrary to the above, those two events are together because they're
# within the same 30m interval.
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode interval --run-time 30m)) },
"t/pt-query-digest/samples/slow033-rtm-interval-30m.txt",
),
"Run-time mode interval 30m"
);
pop @args; # report --iterations 0
pop @args;
# Like the first 30s run above, but with only 3 interations, only the
# first 3 queries are gotten.
ok(
no_diff(
sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/slowlogs/slow033.txt",
qw(--run-time-mode interval --run-time 30 --iterations 3)) },
"t/pt-query-digest/samples/slow033-rtm-interval-30s-3iter.txt"
),
"Run-time mode interval and --iterations"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;
|