Fix for 986847: Allow setting which commands (and extra options) pt-stalk uses through env vars

This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-11-12 11:26:01 -03:00
parent 2c9ebf33e2
commit 22ec559b38
3 changed files with 47 additions and 25 deletions
+12 -12
View File
@@ -648,18 +648,18 @@ remove_pid_file() {
set -u
CMD_GDB="$(_which gdb)"
CMD_IOSTAT="$(_which iostat)"
CMD_MPSTAT="$(_which mpstat)"
CMD_MYSQL="$(_which mysql)"
CMD_MYSQLADMIN="$(_which mysqladmin)"
CMD_OPCONTROL="$(_which opcontrol)"
CMD_OPREPORT="$(_which opreport)"
CMD_PMAP="$(_which pmap)"
CMD_STRACE="$(_which strace)"
CMD_SYSCTL="$(_which sysctl)"
CMD_TCPDUMP="$(_which tcpdump)"
CMD_VMSTAT="$(_which vmstat)"
CMD_GDB="${CMD_GDB:-"$(_which gdb)"}"
CMD_IOSTAT="${CMD_IOSTAT:-"$(_which iostat)"}"
CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}"
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
CMD_SYSCTL="${CMD_SYSCTL:-"$(_which sysctl)"}"
CMD_TCPDUMP="${CMD_TCPDUMP:-"$(_which tcpdump)"}"
CMD_VMSTAT="${CMD_VMSTAT:-"$(_which vmstat)"}"
[ -z "$CMD_SYSCTL" -a -x "/sbin/sysctl" ] && CMD_SYSCTL="/sbin/sysctl"
+12 -12
View File
@@ -28,18 +28,18 @@
set -u
# Global variables.
CMD_GDB="$(_which gdb)"
CMD_IOSTAT="$(_which iostat)"
CMD_MPSTAT="$(_which mpstat)"
CMD_MYSQL="$(_which mysql)"
CMD_MYSQLADMIN="$(_which mysqladmin)"
CMD_OPCONTROL="$(_which opcontrol)"
CMD_OPREPORT="$(_which opreport)"
CMD_PMAP="$(_which pmap)"
CMD_STRACE="$(_which strace)"
CMD_SYSCTL="$(_which sysctl)"
CMD_TCPDUMP="$(_which tcpdump)"
CMD_VMSTAT="$(_which vmstat)"
CMD_GDB="${CMD_GDB:-"$(_which gdb)"}"
CMD_IOSTAT="${CMD_IOSTAT:-"$(_which iostat)"}"
CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}"
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
CMD_SYSCTL="${CMD_SYSCTL:-"$(_which sysctl)"}"
CMD_TCPDUMP="${CMD_TCPDUMP:-"$(_which tcpdump)"}"
CMD_VMSTAT="${CMD_VMSTAT:-"$(_which vmstat)"}"
# Try to find command manually.
[ -z "$CMD_SYSCTL" -a -x "/sbin/sysctl" ] && CMD_SYSCTL="/sbin/sysctl"
+23 -1
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
plan 21
plan 22
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
PT_TMPDIR="$TEST_PT_TMPDIR"
@@ -141,11 +141,33 @@ parse_options "$BIN_DIR/pt-stalk" --run-time 2 -- --defaults-file=/tmp/12345/my.
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 ')
is "$iters" "2" "2 iteration/2s 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 \