perf trace: Add tests for BTF general augmentation
v2 cover perf trace: Add tests for BTF general augmentation
The previous version of the perf trace BTF general augmentation tests didn't pass Shellcheck (thanks to Arnaldo Carvalho de Melo <[email protected]> for pointing this out), this version uses bash instead of POSIX shell to pass Shellcheck.
This patch series also adds documentation for the new option --force-btf, which is used in the tests.
Howard Chu (2):
perf trace: Add tests for BTF general augmentation perf docs: Add documentation for --force-btf option
tools/perf/Documentation/perf-trace.txt | 5 ++ tools/perf/tests/shell/trace_btf_general.sh | 81 +++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 tools/perf/tests/shell/trace_btf_general.sh
Signature · 1 line
2.43.0
PATCH v2 1/2 perf trace: Add tests for BTF general augmentation
Currently, we only have perf trace augmentation tests for enum arguments. This patch adds tests for more general syscall arguments, such as struct pointers, strings, and buffers.
These tests utilize the perf config system to configure the perf trace output, as suggested by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/tests/shell/trace_btf_general.sh | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 tools/perf/tests/shell/trace_btf_general.sh
tools/perf/tests/shell/trace_btf_general.sh new file +81 -0
@@ -0,0 +1,81 @@ +#!/bin/bash +# perf trace BTF general tests +# SPDX-License-Identifier: GPL-2.0 + +err=0 +set -e + +. "$(dirname $0)"/lib/probe.sh +skip_if_no_perf_trace || exit 2 + +file1=$(mktemp /tmp/file1_XXXXX) +file2=$(echo $file1 | sed 's/file1/file2/g') + +buffer="buffer content" +perf_config_tmp=$(mktemp /tmp/.perfconfig_XXXXX) + +trap cleanup EXIT TERM INT HUP + +trace_test_string() { + echo "Testing perf trace's string augmentation" + if ! perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1 | \ + grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" + then + echo "String augmentation test failed" + err=1 + fi +} + +trace_test_buffer() { + echo "Testing perf trace's buffer augmentation" + # echo will insert a newline (\10) at the end of the buffer + if ! perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1 | \ + grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" + then + echo "Buffer augmentation test failed" + err=1 + fi +} + +trace_test_struct_btf() { + echo "Testing perf trace's struct augmentation" + if ! perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1 | \ + grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" + then + echo "BTF struct augmentation test failed" + err=1 + fi +} + +cleanup() { + rm -rf ${file1} ${file2} ${perf_config_tmp} +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} + +# don't overwrite user's perf config +trace_config() { + export PERF_CONFIG=${perf_config_tmp} + perf config trace.show_arg_names=false trace.show_duration=false \ + trace.show_timestamp=false trace.args_alignment=0 +} + +trace_config + +trace_test_string + +if [ $err = 0 ]; then + trace_test_buffer +fi + +if [ $err = 0 ]; then + trace_test_struct_btf +fi + +cleanup + +exit $err
Signature · 1 line
2.43.0
Namhyung Kim
maintainerHello,
Quoted 21 lines · Howard Chu
Currently, we only have perf trace augmentation tests for enum arguments. This patch adds tests for more general syscall arguments, such as struct pointers, strings, and buffers.
These tests utilize the perf config system to configure the perf trace output, as suggested by Arnaldo Carvalho de Melo <[email protected]>
Suggested-by Arnaldo Carvalho de Melo <[email protected]>Suggested-by Ian Rogers <[email protected]>Signed-off-by Howard Chu <[email protected]>--- tools/perf/tests/shell/trace_btf_general.sh | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 tools/perf/tests/shell/trace_btf_general.shtools/perf/tests/shell/trace_btf_general.sh new file +0
-0
tools/perf/tests/shell/trace_btf_general.sh line 9
Quoted 9 lines
tools/perf/tests/shell/trace_btf_general.sh new file +9
-0@@ -0,0 +1,81 @@ +#!/bin/bash +# perf trace BTF general tests +# SPDX-License-Identifier: GPL-2.0 + +err=0 +set -e + +. "$(dirname $0)"/lib/probe.sh +skip_if_no_perf_trace || exit 2
The kernel might not have BPF/BTF support. I think you can check if /sys/kernel/btf/vmlinux is there and skip the test if not.
Thanks,
Namhyung
Quoted 75 lines
tools/perf/tests/shell/trace_btf_general.sh new file +72
-0+ +file1=$(mktemp /tmp/file1_XXXXX) +file2=$(echo $file1 | sed 's/file1/file2/g') + +buffer="buffer content" +perf_config_tmp=$(mktemp /tmp/.perfconfig_XXXXX) + +trap cleanup EXIT TERM INT HUP + +trace_test_string() { + echo "Testing perf trace's string augmentation" + if ! perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1 | \ + grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" + then + echo "String augmentation test failed" + err=1 + fi +} + +trace_test_buffer() { + echo "Testing perf trace's buffer augmentation" + # echo will insert a newline (\10) at the end of the buffer + if ! perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1 | \ + grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" + then + echo "Buffer augmentation test failed" + err=1 + fi +} + +trace_test_struct_btf() { + echo "Testing perf trace's struct augmentation" + if ! perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1 | \ + grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" + then + echo "BTF struct augmentation test failed" + err=1 + fi +} + +cleanup() { + rm -rf ${file1} ${file2} ${perf_config_tmp} +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} + +# don't overwrite user's perf config +trace_config() { + export PERF_CONFIG=${perf_config_tmp} + perf config trace.show_arg_names=false trace.show_duration=false \ + trace.show_timestamp=false trace.args_alignment=0 +} + +trace_config + +trace_test_string + +if [ $err = 0 ]; then + trace_test_buffer +fi + +if [ $err = 0 ]; then + trace_test_struct_btf +fi + +cleanup + +exit $errSignature · 1 line
2.43.0
Hello Namhyung,
Quoted 29 lines · Namhyung Kim
Hello,
Quoted 25 lines · Howard Chu
Currently, we only have perf trace augmentation tests for enum arguments. This patch adds tests for more general syscall arguments, such as struct pointers, strings, and buffers.
These tests utilize the perf config system to configure the perf trace output, as suggested by Arnaldo Carvalho de Melo <[email protected]>
Suggested-by Arnaldo Carvalho de Melo <[email protected]>Suggested-by Ian Rogers <[email protected]>Signed-off-by Howard Chu <[email protected]>--- tools/perf/tests/shell/trace_btf_general.sh | 81 +++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 tools/perf/tests/shell/trace_btf_general.shtools/perf/tests/shell/trace_btf_general.sh new file +4
-0@@ -0,0 +1,81 @@ +#!/bin/bash +# perf trace BTF general tests +# SPDX-License-Identifier: GPL-2.0 +
Quoted 8 lines
tools/perf/tests/shell/trace_btf_general.sh line 9
Quoted 5 lines
tools/perf/tests/shell/trace_btf_general.sh new file +5
-0+err=0 +set -e + +. "$(dirname $0)"/lib/probe.sh +skip_if_no_perf_trace || exit 2The kernel might not have BPF/BTF support. I think you can check if
/sys/kernel/btf/vmlinuxis there and skip the test if not.
My bad, I will add the check to it.
Thanks,
Howard
PATCH v2 2/2 perf docs: Add documentation for --force-btf option
In reply to Howard ChuThe --force-btf option is intended for debugging purposes and is currently undocumented. Add documentation for it.
--- tools/perf/Documentation/perf-trace.txt | 5 +++++ 1 file changed, 5 insertions(+)
tools/perf/Documentation/perf-trace.txt +5 -0
@@ -241,6 +241,11 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs. printing using the existing 'perf trace' syscall arg beautifiers to map integer arguments to strings (pid to comm, syscall id to syscall name, etc). +--force-btf:: + Use btf_dump to pretty print syscall argument data, instead of using hand-crafted pretty + printers. This option is intended for testing BTF integration in perf trace. btf_dump-based + pretty-printing serves as a fallback to hand-crafted pretty printers, as the latter can + better pretty-print integer flags and struct pointers. PAGEFAULTS ----------
Signature · 1 line
2.43.0