From b53a9a76fe8ffe210e878bd05b4610eaf6c958c9 Mon Sep 17 00:00:00 2001 From: Fernando Ipar Date: Tue, 24 Jan 2017 16:04:37 -0300 Subject: [PATCH] added support for operf if present, and if CMD_OPCONTROL is not set --- bin/pt-stalk | 19 +++++++++++++++---- lib/bash/collect.sh | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bin/pt-stalk b/bin/pt-stalk index 288e2163..22a6f99f 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -779,6 +779,7 @@ CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}" CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}" CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}" CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}" +[ -z "$CMD_OPCONTROL" ] && CMD_OPCONTROL=$(_which operf) CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}" CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}" CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}" @@ -853,9 +854,15 @@ collect() { local have_oprofile="" if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then - if $CMD_OPCONTROL --init; then - $CMD_OPCONTROL --start --no-vmlinux - have_oprofile="yes" + if [ $(echo $CMD_OPCONTROL|grep -c opcontrol) -gt 0 ]; then + # use legacy opcontrol + if $CMD_OPCONTROL --init; then + $CMD_OPCONTROL --start --no-vmlinux + have_oprofile="yes" + fi + else + $CMD_OPCONTROL -p `pidof mysqld` & + OPERF_PID=$! fi elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then $CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" & @@ -951,6 +958,7 @@ collect() { log "Loop end: $(date +'TS %s.%N %F %T')" if [ "$have_oprofile" ]; then + if [ $(echo $CMD_OPCONTROL|grep -c opcontrol) -gt 0 ]; then $CMD_OPCONTROL --stop $CMD_OPCONTROL --dump @@ -963,6 +971,9 @@ collect() { $CMD_OPCONTROL --save=pt_collect_$p + else + kill -SIGINT $OPERF_PID + fi local mysqld_path=$(_which mysqld); if [ "$mysqld_path" -a -f "$mysqld_path" ]; then $CMD_OPREPORT \ @@ -985,7 +996,7 @@ collect() { kill -s 15 $strace_pid [ "$mysqld_pid" ] && kill -s 18 $mysqld_pid fi - + innodb_status 2 tokudb_status 2 $CMD_MYSQL $EXT_ARGV -e "$mutex" >> "$d/$p-mutex-status2" & diff --git a/lib/bash/collect.sh b/lib/bash/collect.sh index 85b9c141..2bc1409a 100644 --- a/lib/bash/collect.sh +++ b/lib/bash/collect.sh @@ -34,6 +34,7 @@ CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}" CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}" CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}" CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}" +[ -z "$CMD_OPCONTROL" ] && CMD_OPCONTROL=$(_which operf) CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}" CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}" CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}" @@ -128,9 +129,16 @@ collect() { # The --init should be a no-op if it has already been init-ed. local have_oprofile="" if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then - if $CMD_OPCONTROL --init; then - $CMD_OPCONTROL --start --no-vmlinux - have_oprofile="yes" + if [ $(echo $CMD_OPCONTROL|grep -c opcontrol) -gt 0 ]; then + # use legacy opcontrol + if $CMD_OPCONTROL --init; then + $CMD_OPCONTROL --start --no-vmlinux + have_oprofile="yes" + fi + else + # use operf, may fail under VirtualBox or old processor models (see http://oprofile.sourceforge.net/doc/perf_events.html) + $CMD_OPCONTROL -p `pidof mysqld` & + OPERF_PID=$! fi elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then # Don't run oprofile and strace at the same time. @@ -245,6 +253,7 @@ collect() { log "Loop end: $(date +'TS %s.%N %F %T')" if [ "$have_oprofile" ]; then + if [ $(echo $CMD_OPCONTROL|grep -c opcontrol) -gt 0 ]; then $CMD_OPCONTROL --stop $CMD_OPCONTROL --dump @@ -257,6 +266,9 @@ collect() { $CMD_OPCONTROL --save=pt_collect_$p + else + kill -SIGINT $OPERF_PID + fi # Attempt to generate a report; if this fails, then just tell the user # how to generate the report. local mysqld_path=$(_which mysqld); @@ -282,7 +294,7 @@ collect() { # Sometimes strace leaves threads/processes in T status. [ "$mysqld_pid" ] && kill -s 18 $mysqld_pid fi - + innodb_status 2 tokudb_status 2 $CMD_MYSQL $EXT_ARGV -e "$mutex" >> "$d/$p-mutex-status2" &