mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 05:29:30 +00:00
Merge pull request #160 from fipar/operf-support
added support for operf if present, and if CMD_OPCONTROL is not set
This commit is contained in:
29
bin/pt-stalk
29
bin/pt-stalk
@@ -798,6 +798,7 @@ CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}"
|
|||||||
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
|
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
|
||||||
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
|
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
|
||||||
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
|
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
|
||||||
|
[ -z "$CMD_OPCONTROL" ] && CMD_OPCONTROL=$(_which operf)
|
||||||
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
|
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
|
||||||
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
|
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
|
||||||
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
|
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
|
||||||
@@ -931,10 +932,21 @@ collect_mysql_data_one() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
|
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
|
||||||
|
if [ $(echo $CMD_OPCONTROL | grep -cv operf) -gt 0 ]; then
|
||||||
|
# use legacy or custom opcontrol
|
||||||
if $CMD_OPCONTROL --init; then
|
if $CMD_OPCONTROL --init; then
|
||||||
$CMD_OPCONTROL --start --no-vmlinux
|
$CMD_OPCONTROL --start --no-vmlinux
|
||||||
have_oprofile="yes"
|
have_oprofile="yes"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
have_oprofile="yes"
|
||||||
|
local tmpfile="$PT_TMPDIR/oprofile"
|
||||||
|
mkdir "$d/pt_collect_$p"
|
||||||
|
$CMD_OPCONTROL -p "$mysqld_pid" -d "$d/pt_collect_$p" > "$tmpfile" &
|
||||||
|
sleep 1
|
||||||
|
OPERF_PID=$(grep -Eo "kill -SIGINT [[:digit:]]+" "$tmpfile" | grep -Eo "[[:digit:]]+")
|
||||||
|
rm "$tmpfile"
|
||||||
|
fi
|
||||||
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then
|
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then
|
||||||
$CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" &
|
$CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" &
|
||||||
local strace_pid=$!
|
local strace_pid=$!
|
||||||
@@ -1055,6 +1067,10 @@ collect_system_data_loop() {
|
|||||||
|
|
||||||
collect_mysql_data_two() {
|
collect_mysql_data_two() {
|
||||||
if [ "$have_oprofile" ]; then
|
if [ "$have_oprofile" ]; then
|
||||||
|
local session="--session-dir=$d/pt_collect_$p"
|
||||||
|
|
||||||
|
if [ $(echo $CMD_OPCONTROL | grep -cv operf) -gt 0 ]; then
|
||||||
|
# use legacy or custom opcontrol
|
||||||
$CMD_OPCONTROL --stop
|
$CMD_OPCONTROL --stop
|
||||||
$CMD_OPCONTROL --dump
|
$CMD_OPCONTROL --dump
|
||||||
|
|
||||||
@@ -1065,15 +1081,22 @@ collect_mysql_data_two() {
|
|||||||
warn "Cannot kill oprofiled because its PID cannot be determined"
|
warn "Cannot kill oprofiled because its PID cannot be determined"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$CMD_OPCONTROL --save=pt_collect_$p
|
session="session:pt_collect_$p"
|
||||||
|
|
||||||
local mysqld_path=$(_which mysqld);
|
$CMD_OPCONTROL --save="pt_collect_$p"
|
||||||
|
else
|
||||||
|
log "$OPERF_PID"
|
||||||
|
kill -SIGINT "$OPERF_PID"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
local mysqld_path=$(readlink -f "/proc/$mysqld_pid/exe");
|
||||||
if [ "$mysqld_path" -a -f "$mysqld_path" ]; then
|
if [ "$mysqld_path" -a -f "$mysqld_path" ]; then
|
||||||
$CMD_OPREPORT \
|
$CMD_OPREPORT \
|
||||||
--demangle=smart \
|
--demangle=smart \
|
||||||
--symbols \
|
--symbols \
|
||||||
--merge tgid \
|
--merge tgid \
|
||||||
session:pt_collect_$p \
|
"$session" \
|
||||||
"$mysqld_path" \
|
"$mysqld_path" \
|
||||||
> "$d/$p-opreport"
|
> "$d/$p-opreport"
|
||||||
else
|
else
|
||||||
|
@@ -34,6 +34,7 @@ CMD_MPSTAT="${CMD_MPSTAT:-"$(_which mpstat)"}"
|
|||||||
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
|
CMD_MYSQL="${CMD_MYSQL:-"$(_which mysql)"}"
|
||||||
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
|
CMD_MYSQLADMIN="${CMD_MYSQLADMIN:-"$(_which mysqladmin)"}"
|
||||||
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
|
CMD_OPCONTROL="${CMD_OPCONTROL:-"$(_which opcontrol)"}"
|
||||||
|
[ -z "$CMD_OPCONTROL" ] && CMD_OPCONTROL=$(_which operf)
|
||||||
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
|
CMD_OPREPORT="${CMD_OPREPORT:-"$(_which opreport)"}"
|
||||||
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
|
CMD_PMAP="${CMD_PMAP:-"$(_which pmap)"}"
|
||||||
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
|
CMD_STRACE="${CMD_STRACE:-"$(_which strace)"}"
|
||||||
@@ -199,10 +200,22 @@ collect_mysql_data_one() {
|
|||||||
# Next, start oprofile gathering data during the whole rest of this process.
|
# Next, start oprofile gathering data during the whole rest of this process.
|
||||||
# The --init should be a no-op if it has already been init-ed.
|
# The --init should be a no-op if it has already been init-ed.
|
||||||
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
|
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
|
||||||
|
if [ $(echo $CMD_OPCONTROL | grep -cv operf) -gt 0 ]; then
|
||||||
|
# use legacy or custom opcontrol
|
||||||
if $CMD_OPCONTROL --init; then
|
if $CMD_OPCONTROL --init; then
|
||||||
$CMD_OPCONTROL --start --no-vmlinux
|
$CMD_OPCONTROL --start --no-vmlinux
|
||||||
have_oprofile="yes"
|
have_oprofile="yes"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
have_oprofile="yes"
|
||||||
|
local tmpfile="$PT_TMPDIR/oprofile"
|
||||||
|
mkdir "$d/pt_collect_$p"
|
||||||
|
# use operf, may fail under VirtualBox or old processor models (see http://oprofile.sourceforge.net/doc/perf_events.html)
|
||||||
|
$CMD_OPCONTROL -p "$mysqld_pid" -d "$d/pt_collect_$p" > "$tmpfile" &
|
||||||
|
sleep 1
|
||||||
|
OPERF_PID=$(grep -Eo "kill -SIGINT [[:digit:]]+" "$tmpfile" | grep -Eo "[[:digit:]]+")
|
||||||
|
rm "$tmpfile"
|
||||||
|
fi
|
||||||
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then
|
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then
|
||||||
# Don't run oprofile and strace at the same time.
|
# Don't run oprofile and strace at the same time.
|
||||||
$CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" &
|
$CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" &
|
||||||
@@ -340,6 +353,10 @@ collect_system_data_loop() {
|
|||||||
|
|
||||||
collect_mysql_data_two() {
|
collect_mysql_data_two() {
|
||||||
if [ "$have_oprofile" ]; then
|
if [ "$have_oprofile" ]; then
|
||||||
|
local session="--session-dir=$d/pt_collect_$p"
|
||||||
|
|
||||||
|
if [ $(echo $CMD_OPCONTROL | grep -cv operf) -gt 0 ]; then
|
||||||
|
# use legacy or custom opcontrol
|
||||||
$CMD_OPCONTROL --stop
|
$CMD_OPCONTROL --stop
|
||||||
$CMD_OPCONTROL --dump
|
$CMD_OPCONTROL --dump
|
||||||
|
|
||||||
@@ -350,17 +367,24 @@ collect_mysql_data_two() {
|
|||||||
warn "Cannot kill oprofiled because its PID cannot be determined"
|
warn "Cannot kill oprofiled because its PID cannot be determined"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$CMD_OPCONTROL --save=pt_collect_$p
|
session="session:pt_collect_$p"
|
||||||
|
|
||||||
|
$CMD_OPCONTROL --save="pt_collect_$p"
|
||||||
|
else
|
||||||
|
log "$OPERF_PID"
|
||||||
|
kill -SIGINT "$OPERF_PID"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Attempt to generate a report; if this fails, then just tell the user
|
# Attempt to generate a report; if this fails, then just tell the user
|
||||||
# how to generate the report.
|
# how to generate the report.
|
||||||
local mysqld_path=$(_which mysqld);
|
local mysqld_path=$(readlink -f "/proc/$mysqld_pid/exe");
|
||||||
if [ "$mysqld_path" -a -f "$mysqld_path" ]; then
|
if [ "$mysqld_path" -a -f "$mysqld_path" ]; then
|
||||||
$CMD_OPREPORT \
|
$CMD_OPREPORT \
|
||||||
--demangle=smart \
|
--demangle=smart \
|
||||||
--symbols \
|
--symbols \
|
||||||
--merge tgid \
|
--merge tgid \
|
||||||
session:pt_collect_$p \
|
"$session" \
|
||||||
"$mysqld_path" \
|
"$mysqld_path" \
|
||||||
> "$d/$p-opreport"
|
> "$d/$p-opreport"
|
||||||
else
|
else
|
||||||
|
@@ -956,6 +956,39 @@ like(
|
|||||||
"numastat collection has data"
|
"numastat collection has data"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# ###########################################################################
|
||||||
|
# Test if option operf collection works
|
||||||
|
# ###########################################################################
|
||||||
|
|
||||||
|
# ./bin/pt-stalk --no-stalk --iterations=1 --sleep=1 --dest=tmp/pt-stalk --collect-oprofile -- --user=msandbox --password=msandbox --port=12345 --host=127.0.0.1 ^C
|
||||||
|
SKIP: {
|
||||||
|
my $operf = `which operf`;
|
||||||
|
chomp $operf;
|
||||||
|
skip "--collect-oprofile tests require operf" unless -x "$operf";
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
|
||||||
|
$retval = system("$trunk/bin/pt-stalk --no-stalk --run-time 10 --sleep 2 --dest $dest --pid $pid_file --iterations 1 --collect-oprofile -- --defaults-file=$cnf >$log_file 2>&1");
|
||||||
|
|
||||||
|
PerconaTest::wait_until(sub { !-f $pid_file });
|
||||||
|
|
||||||
|
$output = `ls $dest`;
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/opreport/,
|
||||||
|
"operf data collected"
|
||||||
|
) or diag($output);
|
||||||
|
|
||||||
|
$output = `cat $dest/*-opreport`;
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/(mysqld)/,
|
||||||
|
"operf collection has data"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user