From 22ec559b380ba241cc3aa430fce446787f2e87fc Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Mon, 12 Nov 2012 11:26:01 -0300 Subject: [PATCH 1/2] Fix for 986847: Allow setting which commands (and extra options) pt-stalk uses through env vars --- bin/pt-stalk | 24 ++++++++++++------------ lib/bash/collect.sh | 24 ++++++++++++------------ t/lib/bash/collect.sh | 24 +++++++++++++++++++++++- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/bin/pt-stalk b/bin/pt-stalk index b8a99e9c..d7ce5389 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -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" diff --git a/lib/bash/collect.sh b/lib/bash/collect.sh index 87a614af..5a8edfc9 100644 --- a/lib/bash/collect.sh +++ b/lib/bash/collect.sh @@ -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" diff --git a/t/lib/bash/collect.sh b/t/lib/bash/collect.sh index 5dd3487d..314f296e 100644 --- a/t/lib/bash/collect.sh +++ b/t/lib/bash/collect.sh @@ -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_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 \ From b4f8732acabbbbfcdfb9d70338899c11a79a702e Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Tue, 13 Nov 2012 17:47:26 -0300 Subject: [PATCH 2/2] Documented the CMD_* env variable override --- bin/pt-stalk | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/bin/pt-stalk b/bin/pt-stalk index d7ce5389..c19bb779 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -1843,7 +1843,49 @@ Print tool's version and exit. =head1 ENVIRONMENT -This tool does not use any environment variables for configuration. +This tool does not require any environment variables for configuration, +although it can be influenced to work differently by through several +variables. Keep in mind that these are expert settings, and should not +be used in most cases. + +Specifically, the variables that can be set are: + +=over + +=item CMD_GDB + +=item CMD_IOSTAT + +=item CMD_MPSTAT + +=item CMD_MYSQL + +=item CMD_MYSQLADMIN + +=item CMD_OPCONTROL + +=item CMD_OPREPORT + +=item CMD_PMAP + +=item CMD_STRACE + +=item CMD_SYSCTL + +=item CMD_TCPDUMP + +=item CMD_VMSTAT + +=back + +For example, during collection iostat is called with a -dx argument, but +because you have an NFS partition, you also need the -n flag there. Instead +of editing the source, you can call pt-stalk as + + CMD_IOSTAT="iostat -n" pt-stalk ... + +which will do exactly what you need. Combined with the plugin hooks, this +gives you a fine-grained control of what the tool does. =head1 SYSTEM REQUIREMENTS