Skip to content

Commit

Permalink
perf test shell tpebs: Avoid failures with perf event paranoia
Browse files Browse the repository at this point in the history
When not running as root and with higher perf event paranoia values
the perf record forked by TPEBS can fail to attach to the process. Skip
the test in these scenarios.

Signed-off-by: Ian Rogers <[email protected]>
  • Loading branch information
captain5050 committed Dec 16, 2024
1 parent 8ad04e0 commit 63ccee6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tools/perf/tests/shell/test_stat_intel_tpebs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
# SPDX-License-Identifier: GPL-2.0

set -e
grep -q GenuineIntel /proc/cpuinfo || { echo Skipping non-Intel; exit 2; }

ParanoidAndNotRoot() {
[ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ]
}

if ! grep -q GenuineIntel /proc/cpuinfo
then
echo "Skipping non-Intel"
exit 2
fi

if ParanoidAndNotRoot 0
then
echo "Skipping paranoid >0 and not root"
exit 2
fi

# Use this event for testing because it should exist in all platforms
event=cache-misses:R
Expand All @@ -20,3 +35,4 @@ alt_name=/cache-misses/R
echo "Testing with --record-tpebs"
result=$(perf stat -e "$event" --record-tpebs -a sleep 0.01 2>&1)
[[ "$result" =~ "perf record" && "$result" =~ $event || "$result" =~ $alt_name ]] || exit 1
echo "Success!"

0 comments on commit 63ccee6

Please sign in to comment.