PR-160 - added support for operf if present, and if CMD_OPCONTROL is not set

- Made PR actually working
This commit is contained in:
Sveta Smirnova
2024-01-26 01:01:23 +03:00
parent 8e3ce6c74f
commit 5ca0e8a898
2 changed files with 63 additions and 43 deletions

View File

@@ -200,17 +200,21 @@ collect_mysql_data_one() {
# 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.
if [ "$CMD_OPCONTROL" -a "$OPT_COLLECT_OPROFILE" ]; then
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
if [ $(echo $CMD_OPCONTROL | grep -c opcontrol) -gt 0 ]; then
# use legacy opcontrol
if $CMD_OPCONTROL --init; then
$CMD_OPCONTROL --start --no-vmlinux
fi
else
# use operf, may fail under VirtualBox or old processor models (see http://oprofile.sourceforge.net/doc/perf_events.html)
$CMD_OPCONTROL -s &
OPERF_PID=$!
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
have_oprofile="yes"
elif [ "$CMD_STRACE" -a "$OPT_COLLECT_STRACE" -a "$mysqld_pid" ]; then
# Don't run oprofile and strace at the same time.
$CMD_STRACE -T -s 0 -f -p $mysqld_pid -o "$d/$p-strace" &
@@ -348,31 +352,37 @@ collect_system_data_loop() {
collect_mysql_data_two() {
if [ "$have_oprofile" ]; then
if [ $(echo $CMD_OPCONTROL|grep -c opcontrol) -gt 0 ]; then
$CMD_OPCONTROL --stop
$CMD_OPCONTROL --dump
local session="--session-dir=$d/pt_collect_$p"
local oprofiled_pid=$(_pidof oprofiled | awk '{print $1; exit;}')
if [ "$oprofiled_pid" ]; then
kill $oprofiled_pid
if [ $(echo $CMD_OPCONTROL | grep -c opcontrol) -gt 0 ]; then
$CMD_OPCONTROL --stop
$CMD_OPCONTROL --dump
local oprofiled_pid=$(_pidof oprofiled | awk '{print $1; exit;}')
if [ "$oprofiled_pid" ]; then
kill $oprofiled_pid
else
warn "Cannot kill oprofiled because its PID cannot be determined"
fi
session="session:pt_collect_$p"
$CMD_OPCONTROL --save="pt_collect_$p"
else
warn "Cannot kill oprofiled because its PID cannot be determined"
log "$OPERF_PID"
kill -SIGINT "$OPERF_PID"
fi
$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);
local mysqld_path=$(readlink -f "/proc/$mysqld_pid/exe");
if [ "$mysqld_path" -a -f "$mysqld_path" ]; then
$CMD_OPREPORT \
--demangle=smart \
--symbols \
--merge tgid \
session:pt_collect_$p \
"$session" \
"$mysqld_path" \
> "$d/$p-opreport"
else