mirror of
https://github.com/torvalds/linux.git
synced 2026-12-03 20:06:35 +00:00
The purpose of this test is to test for races in the exit of 'perf
trace' missing the last events, it was failing when the COMM wasn't
resolved either because we missed some PERF_RECORD_COMM or somehow
raced on getting it from procfs.
Add --no-comm to the 'perf trace' command line so that we get a
consistent, pid only output, which allows the test to achieve its goal.
This is the output from
'perf trace --no-comm -e syscalls:sys_enter_exit_group':
0.000 21953 syscalls:sys_enter_exit_group()
0.000 21955 syscalls:sys_enter_exit_group()
0.000 21957 syscalls:sys_enter_exit_group()
0.000 21959 syscalls:sys_enter_exit_group()
0.000 21961 syscalls:sys_enter_exit_group()
0.000 21963 syscalls:sys_enter_exit_group()
0.000 21965 syscalls:sys_enter_exit_group()
0.000 21967 syscalls:sys_enter_exit_group()
0.000 21969 syscalls:sys_enter_exit_group()
0.000 21971 syscalls:sys_enter_exit_group()
Now it passes:
root@number:~# perf test "trace exit race"
110: perf trace exit race : Ok
root@number:~#
root@number:~# perf test -v "trace exit race"
110: perf trace exit race : Ok
root@number:~#
If we artificially make it run just 9 times instead of the 10 it runs,
i.e. by manually doing:
trace_shutdown_race() {
for _ in $(seq 9); do
that 9 is $iter, 10 in the patch, we get:
root@number:~# vim ~acme/libexec/perf-core/tests/shell/trace_exit_race.sh
root@number:~# perf test -v "trace exit race"
--- start ---
test child forked, pid 24629
Missing output, expected 10 but only got 9
---- end(-1) ----
110: perf trace exit race : FAILED!
root@number:~#
I.e. 9 'perf trace' calls produced the expected output, the inverse grep
didn't show anything, so the patch provided by Howard for the previous
patch kicks in and shows a more informative message.
Tested-by: Howard Chu <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Benjamin Peterson <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: https://lore.kernel.org/lkml/ZzdknoHqrJbojb6P@x1
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
52 lines
1.2 KiB
Bash
Executable File
52 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# perf trace exit race
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
# Check that the last events of a perf trace'd subprocess are not
|
|
# lost. Specifically, trace the exiting syscall of "true" 10 times and ensure
|
|
# the output contains 10 correct lines.
|
|
|
|
# shellcheck source=lib/probe.sh
|
|
. "$(dirname $0)"/lib/probe.sh
|
|
|
|
skip_if_no_perf_trace || exit 2
|
|
|
|
if [ "$1" = "-v" ]; then
|
|
verbose="1"
|
|
fi
|
|
|
|
iter=10
|
|
regexp=" +[0-9]+\.[0-9]+ [0-9]+ syscalls:sys_enter_exit_group\(\)$"
|
|
|
|
trace_shutdown_race() {
|
|
for _ in $(seq $iter); do
|
|
perf trace --no-comm -e syscalls:sys_enter_exit_group true 2>>$file
|
|
done
|
|
result="$(grep -c -E "$regexp" $file)"
|
|
[ $result = $iter ]
|
|
}
|
|
|
|
|
|
file=$(mktemp /tmp/temporary_file.XXXXX)
|
|
|
|
# Do not use whatever ~/.perfconfig file, it may change the output
|
|
# via trace.{show_timestamp,show_prefix,etc}
|
|
export PERF_CONFIG=/dev/null
|
|
|
|
trace_shutdown_race
|
|
err=$?
|
|
|
|
if [ $err != 0 ] && [ "${verbose}" = "1" ]; then
|
|
lines_not_matching=$(mktemp /tmp/temporary_file.XXXXX)
|
|
if grep -v -E "$regexp" $file > $lines_not_matching ; then
|
|
echo "Lines not matching the expected regexp: '$regexp':"
|
|
cat $lines_not_matching
|
|
else
|
|
echo "Missing output, expected $iter but only got $result"
|
|
fi
|
|
rm -f $lines_not_matching
|
|
fi
|
|
|
|
rm -f ${file}
|
|
exit $err
|