From: Serhei Makarov Date: Fri, 19 Jun 2026 20:39:39 +0000 (-0400) Subject: tests/run-stackprof-system-gprof.sh: check this kind of rewrite X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b91000999b6005ea86ee5b82318e28ed27f06def;p=thirdparty%2Felfutils.git tests/run-stackprof-system-gprof.sh: check this kind of rewrite --- diff --git a/tests/run-stackprof-system-gprof.sh b/tests/run-stackprof-system-gprof.sh index e2765324..19e46d16 100755 --- a/tests/run-stackprof-system-gprof.sh +++ b/tests/run-stackprof-system-gprof.sh @@ -16,65 +16,61 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -set -x +. $srcdir/stackprof-subr.sh -. $srcdir/test-subr.sh +set -x +unset VALGRIND_CMD # prerequisites type timeout 2>/dev/null || (echo "no timeout installed"; exit 77) -expr `whoami` = "root" || (echo "run as root"; exit 77) +check_perf_event_open || (echo "perf_event_open fails (check kernel.perf_event_paranoid + kernel config)"; exit 77) +expr `whoami` = "root" || (echo "not running as root"; exit 77) -# run systemwide scan tempfiles test.out -# produce gprof data -testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v 2>&1 | tee test.out +tempfiles gmon.* +# run systemwide scan, no gprof output +testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v 2>&1 | tee test.out grep "^perf_event_attr configuration" test.out grep "Starting stack profile collection systemwide" test.out -grep -E "^[0-9]+ " test.out +grep -E "^[0-9]+ " test.out # -- pid / sample counts entries -# run it again, producing gprof data -testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -v -g 2>&1 | tee test.out -tempfiles test.out -tempfiles gmon.* -grep "^perf_event_attr configuration type=1 config=0 sample_freq=" test.out +# run systemwide scan again, with gprof output +testrun timeout -p -sINT 10 ${abs_top_builddir}/src/stackprof -v -g 2>&1 | tee test.out +grep "^perf_event_attr configuration" test.out grep "Starting stack profile collection systemwide" test.out grep -E "^buildid [0-9a-f]+" test.out -export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/ +stackprof_debuginfod_setup for f in gmon.*.out do exe="`basename "$f" .out`.exe" - if [ ! -f "$exe" ]; - then - echo "NOTE: finding $f executable by buildid" + if [ ! -f "$exe" ]; then buildid=`echo "$f" | cut -f2 -d.` - if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then - ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe" - else - echo "SKIPPING: executable not found" + if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v executable $buildid; then + echo "$exe not found, skipping" continue fi + ln -s "`${abs_top_builddir}/debuginfod/debuginfod-find executable $buildid`" "$exe" fi + exe_info="$exe (`readlink $exe`)" tempfiles "$exe" - echo "NOTE: analyzing $exe `readlink $exe`" tempfiles gprof_output.txt - # Try a plain gprof attempt on the executable + # try a plain gprof run on the executable if gprof "$exe" "$f" > gprof_output.txt 2>&1; then - # Success, use the output + echo "$exe_info" cat gprof_output.txt - else - # Fall back to debuginfod if necessary (e.g., if debug info is missing) - echo "NOTE: stripped binary found, attempting to find debuginfo" - if testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then - debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`" - gprof "$debuginfo" "$f" - else - echo "SKIPPING: debuginfo not found" - continue - fi + continue + fi + # else fall back to debuginfod + if ! testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $exe; then + echo "$exe_info is a stripped binary, debuginfo not found, skipping" + continue fi + debuginfo="`${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $exe`" + echo "$exe_info" + gprof "$debuginfo" "$f" done exit 0 diff --git a/tests/stackprof-subr.sh b/tests/stackprof-subr.sh new file mode 100644 index 00000000..a75a55d9 --- /dev/null +++ b/tests/stackprof-subr.sh @@ -0,0 +1,34 @@ +# Copyright (C) 2021 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# sourced from run-stackprof-*.sh tests (must be bash scripts) + +. $srcdir/test-subr.sh +# TODO . $srcdir/debuginfod-subr.sh ?? + +check_perf_event_open() { + tempfiles perf-test.out + if ! testrun timeout 2 ${abs_top_builddir}/src/stackprof -v -- /bin/true > perf-test.out 2>&1; then + if grep -q "perf_event_open.*failed\|Operation note permitted\|Permission denied"; then + exit 77 + fi + fi +} + +stackprof_debuginfod_setup() { + # TODO non networked version + export DEBUGINFOD_URLS=https://debuginfod.elfutils.org/ +}