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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
#!/usr/bin/env bash
plan 22
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
PT_TMPDIR="$TEST_PT_TMPDIR"
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
TOOL="pt-stalk"
mkdir "$PT_TMPDIR/collect" 2>/dev/null
source "$LIB_DIR/log_warn_die.sh"
source "$LIB_DIR/subshell.sh"
source "$LIB_DIR/parse_options.sh"
source "$LIB_DIR/safeguards.sh"
source "$LIB_DIR/alt_cmds.sh"
source "$LIB_DIR/collect.sh"
# We need flush tables, otherwise we won't have stable results for opentables tests
CMD_MYSQL="$(_which mysql)"
$CMD_MYSQL --defaults-file=/tmp/12345/my.sandbox.cnf -ss -e 'FLUSH TABLES'
parse_options "$BIN_DIR/pt-stalk" --run-time 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
# Prefix (with path) for the collect files.
p="$PT_TMPDIR/collect/2011_12_05"
# Default collect, no extras like gdb, tcpdump, etc.
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
cat "$p-opentables2" > /tmp/collect.test
# Even if this system doesn't have all the cmds, collect should still
# have created some files for cmds that (hopefully) all systems have.
ls -1 $PT_TMPDIR/collect | sort > $PT_TMPDIR/collect-files
# If this system has /proc, then some files should be collected.
# Else, those files should not exist.
if [ -f /proc/diskstats ]; then
wait_for_files "$p-diskstats"
cmd_ok \
"grep -q '[0-9]' $p-diskstats" \
"/proc/diskstats"
else
test -f $PT_TMPDIR/collect/$p-diskstats
is "$?" "1" "No /proc/diskstats"
fi
cmd_ok \
"grep -q '\-hostname\$' $PT_TMPDIR/collect-files" \
"Collected hostname"
cmd_ok \
"grep -q 'Avail' $p-df" \
"df"
# hostname is the last thing collected, so if it's ok,
# then the sub reached its end.
is \
"`cat $p-hostname`" \
"`hostname`" \
"hostname"
cmd_ok \
"grep -q -i 'buffer pool' $p-innodbstatus1" \
"innodbstatus1"
cmd_ok \
"grep -q -i 'buffer pool' $p-innodbstatus2" \
"innodbstatus2"
cmd_ok \
"grep -q 'error log seems to be .*/mysqld.log' $p-output" \
"Finds MySQL error log"
if [ "$(which lsof 2>/dev/null)" ]; then
wait_for_files "$p-lsof"
cmd_ok \
"grep -q 'COMMAND[ ]\+PID[ ]\+USER' $p-lsof" \
"lsof"
else
is "1" "1" "SKIP lsof not in PATH"
fi
cmd_ok \
"grep -q -e OS_waits -e Type $p-mutex-status1" \
"mutex-status1"
cmd_ok \
"grep -q -e OS_waits -e Type $p-mutex-status2" \
"mutex-status2"
cmd_ok \
"grep -q '^| Uptime' $p-mysqladmin" \
"mysqladmin ext"
cmd_ok \
"grep -qP 'Database\tTable\tIn_use' $p-opentables1" \
"opentables1"
cmd_ok \
"grep -qP 'Database\tTable\tIn_use' $p-opentables2" \
"opentables2"
cmd_ok \
"grep -q '1. row' $p-processlist" \
"processlist"
cmd_ok \
"grep -q 'mysqld' $p-ps" \
"ps"
cmd_ok \
"grep -qP '^wait_timeout\t\d' $p-variables" \
"variables"
iters=$(cat $p-df | grep -c '^TS ')
is "$iters" "1" "1 iteration/1s run time"
empty_files=0
for file in $p-*; do
if ! [ -s $file ]; then
empty_files=1
break
fi
# We need additional check here in case if first match
# is empty string.
if [ 0 -eq "$(grep -vc '^TS ' --max-count 1 $file)" ] ||
[ 0 -eq "$(grep -vc '^$' --max-count 1 $file)" ]; then
empty_files=1
break
fi
done
is "$empty_files" "0" "No empty files"
# ###########################################################################
# Debug option for mysqladmin is not default now, we will test it separately.
# ###########################################################################
#Skipping until PT-2242 is fixed
if false; then
parse_options "$BIN_DIR/pt-stalk" --run-time 2 -- --defaults-file=/tmp/12345/my.sandbox.cnf
rm $PT_TMPDIR/collect/*
# Prefix (with path) for the collect files.
p="$PT_TMPDIR/collect/2011_12_05"
CMD_MYSQLADMIN="mysqladmin debug"
# Default collect, no extras like gdb, tcpdump, etc.
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
if [[ "$SANDBOX_VERSION" > "5.0" ]]; then
wait_for_files "$p-log_error"
cmd_ok \
"grep -qE 'Memory status|Open streams|Begin safemalloc' $p-log_error" \
"debug"
else
is "1" "1" "SKIP Can't determine MySQL 5.0 error log"
fi
else
is "1" "1" "SKIP until PT-2242 is fixed"
fi
# ###########################################################################
# Try longer run time.
# ###########################################################################
parse_options "$BIN_DIR/pt-stalk" --run-time 3 -- --defaults-file=/tmp/12345/my.sandbox.cnf
rm $PT_TMPDIR/collect/*
fake_opcontrol="$PT_TMPDIR/collect/fake_opcontrol"
fake_out="$PT_TMPDIR/collect/pt-faked-opcontrol-out"
cat <<FAKE_EXEC > "$fake_opcontrol"
#!/bin/sh
echo "Faked opcontrol: \$@" > "$fake_out"
exit 1
FAKE_EXEC
chmod +x "$fake_opcontrol"
CMD_OPCONTROL="$fake_opcontrol"
OPT_COLLECT_OPROFILE=1
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
CMD_OPCONTROL=""
OPT_COLLECT_OPROFILE=""
iters=$(cat $p-df | grep -c '^TS ')
# We need to adjust result on slow machines
if [ $iters -eq 2 ]; then
iters=3;
fi
is "$iters" "3" "2 or 3 iteration/3s run time"
is \
"$(cat "$fake_out")" \
"Faked opcontrol: --init" \
"Bug 986847: Can manually set which commands pt-stalk uses"
if [ -f "$p-vmstat" ]; then
n=$(awk '/[ ]*[0-9]/ { n += 1 } END { print n }' "$p-vmstat")
is \
"$n" \
"3" \
"vmstat runs for --run-time seconds (bug 955860)"
else
is "1" "1" "SKIP vmstat not installed"
fi
# ############################################################################
# Done
# ############################################################################
|