perf test trace: Reduce test failures and make error messages verbose
cover perf test trace: Reduce test failures and make error messages verbose
Currently, BTF tests fail constantly, this series fixes two major reasons why they fail, and makes the error messages acquired when using '-vv' more verbose, so when they fail, one can easily diagnose the problem.
Before:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 783533
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint syscall
---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!After:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 851658
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint timer:hrtimer_setup,timer:hrtimer_start
[tracepoint failure] Failed to trace tracepoint timer:hrtimer_setup,timer:hrtimer_start, output:
event syntax error: 'timer:hrtimer_setup,timer:hrtimer_start'
\___ unknown tracepoint Error: File /sys/kernel/tracing//events/timer/hrtimer_setup not found.
Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?.
Run 'perf list' for a list of valid events
Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]
-e, --event <event> event/syscall selector. use 'perf list' to list available events---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!
Howard Chu (5):
perf test trace: Use shell's -f flag to check if vmlinux exists perf test trace: Remove set -e and print trace test's error messages perf test trace: Stop tracing hrtimer_init event in trace enum test perf test trace: Remove set -e for BTF general tests
perf test trace BTF: Use --sort-events in BTF general tests
tools/perf/tests/shell/trace_btf_enum.sh | 17 +++++++++-------- tools/perf/tests/shell/trace_btf_general.sh | 19 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/5 perf test trace: Use shell's -f flag to check if vmlinux exists
To match the style of the existing codebase, no functional changes were applied.
--- tools/perf/tests/shell/trace_btf_enum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/trace_btf_enum.sh +1 -1
@@ -17,7 +17,7 @@ skip_if_no_perf_trace || exit 2 check_vmlinux() { echo "Checking if vmlinux exists" - if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1 + if [ ! -f /sys/kernel/btf/vmlinux ] then echo "trace+enum test [Skipped missing vmlinux BTF support]" err=2
Signature · 1 line
2.45.2
PATCH 2/5 perf test trace: Remove set -e and print trace test's error messages
In reply to Howard ChuCurrently perf test utilizes the set -e option in shell that exit immediately if a command exits with a non-zero status, this prevents further error handling and introduces ambiguity. This patch removes set -e and prints the error message after invoking perf trace during perf tests.
In my case, the command that exits with a non-zero status is perf trace instead of grep, because it can't find the 'timer:hrtimer_setup' tracepoint, see below.
Before:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 783533
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint syscall
---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!After:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 851658
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint timer:hrtimer_setup,timer:hrtimer_start
[tracepoint failure] Failed to trace tracepoint timer:hrtimer_setup,timer:hrtimer_start, output:
event syntax error: 'timer:hrtimer_setup,timer:hrtimer_start'
\___ unknown tracepoint Error: File /sys/kernel/tracing//events/timer/hrtimer_setup not found.
Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?.
Run 'perf list' for a list of valid events
Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]
-e, --event <event> event/syscall selector. use 'perf list' to list available events---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!
--- tools/perf/tests/shell/trace_btf_enum.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
tools/perf/tests/shell/trace_btf_enum.sh +7 -6
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 err=0 -set -e syscall="landlock_add_rule" non_syscall="timer:hrtimer_setup,timer:hrtimer_start"
@@ -34,22 +33,24 @@ trace_landlock() { return fi - if perf trace -e $syscall $TESTPROG 2>&1 | \ - grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*" + output="$(perf trace -e $syscall $TESTPROG 2>&1)" + if echo "$output" | grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*" then err=0 else + printf "[syscall failure] Failed to trace syscall $syscall, output:\n$output" err=1 fi } trace_non_syscall() { - echo "Tracing non-syscall tracepoint ${non-syscall}" - if perf trace -e $non_syscall --max-events=1 2>&1 | \ - grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$' + echo "Tracing non-syscall tracepoint ${non_syscall}" + output="$(perf trace -e $non_syscall --max-events=1 2>&1)" + if echo "$output" | grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$' then err=0 else + printf "[tracepoint failure] Failed to trace tracepoint $non_syscall, output:\n$output" err=1 fi }
Signature · 1 line
2.45.2
Namhyung Kim
maintainerRe: [PATCH v1 2/5] perf test trace: Remove set -e and print trace test's error messages
Hi Howard,
Quoted 5 lines · Howard Chu
Currently perf test utilizes the set -e option in shell that exit immediately if a command exits with a non-zero status, this prevents further error handling and introduces ambiguity. This patch removes set -e and prints the error message after invoking perf trace during perf tests.
I think it's fine to exits with non-zero inside 'if' statements. But it won't work if you want to move it out of the 'if' statements. I'm not sure how it'd work in a subshll for the assignment. But it'd be ok to remove 'set -e' anyway since the test checks the result manually.
Thanks,
Namhyung
Quoted 93 lines
In my case, the command that exits with a non-zero status is perf trace instead of grep, because it can't find the 'timer:hrtimer_setup' tracepoint, see below.
Before:
$ sudo /tmp/perf test enum -vv 107: perf trace enum augmentation tests: 107: perf trace enum augmentation tests : Running --- start --- test child forked, pid 783533 Checking if vmlinux exists Tracing syscall landlock_add_rule Tracing non-syscall tracepoint syscall ---- end(-1) ---- 107: perf trace enum augmentation tests : FAILED!After:
$ sudo /tmp/perf test enum -vv 107: perf trace enum augmentation tests: 107: perf trace enum augmentation tests : Running --- start --- test child forked, pid 851658 Checking if vmlinux exists Tracing syscall landlock_add_rule Tracing non-syscall tracepoint timer:hrtimer_setup,timer:hrtimer_start [tracepoint failure] Failed to trace tracepoint timer:hrtimer_setup,timer:hrtimer_start, output: event syntax error: 'timer:hrtimer_setup,timer:hrtimer_start' \___ unknown tracepointError: File
/sys/kernel/tracing//events/timer/hrtimer_setupnot found.
Hint: Perhaps this kernel misses someCONFIG_setting to enable this feature?.Run 'perf list' for a list of valid events
Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]-e, --event <event> event/syscall selector. use 'perf list' to list available events---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!Signed-off-by Howard Chu <[email protected]>--- tools/perf/tests/shell/trace_btf_enum.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)tools/perf/tests/shell/trace_btf_enum.sh +7
-6@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 err=0 -set -e syscall="landlock_add_rule" non_syscall="timer:hrtimer_setup,timer:hrtimer_start"@@ -34,22 +33,24 @@ trace_landlock() { return fi - if perf trace -e $syscall $TESTPROG 2>&1 | \ - grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*" + output="$(perf trace -e $syscall $TESTPROG 2>&1)" + if echo "$output" | grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*" then err=0 else + printf "[syscall failure] Failed to trace syscall $syscall, output:\n$output" err=1 fi } trace_non_syscall() { - echo "Tracing non-syscall tracepoint ${non-syscall}" - if perf trace -e $non_syscall --max-events=1 2>&1 | \ - grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$' + echo "Tracing non-syscall tracepoint ${non_syscall}" + output="$(perf trace -e $non_syscall --max-events=1 2>&1)" + if echo "$output" | grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$' then err=0 else + printf "[tracepoint failure] Failed to trace tracepoint $non_syscall, output:\n$output" err=1 fi }Signature · 1 line
2.45.2
Re: [PATCH v1 2/5] perf test trace: Remove set -e and print trace test's error messages
Hello Namhyung,
Quoted 10 lines · Namhyung Kim
Hi Howard,
Quoted 5 lines · Howard Chu
Currently perf test utilizes the set -e option in shell that exit immediately if a command exits with a non-zero status, this prevents further error handling and introduces ambiguity. This patch removes set -e and prints the error message after invoking perf trace during perf tests.
Quoted 4 lines
I think it's fine to exits with non-zero inside 'if' statements. But it won't work if you want to move it out of the 'if' statements. I'm not sure how it'd work in a subshll for the assignment. But it'd be ok to remove 'set -e' anyway since the test checks the result manually.
Yeah it won't exit from the non-zero status from the if statement. Thanks.
Thanks,
Howard
PATCH 3/5 perf test trace: Stop tracing hrtimer_init event in trace enum test
In reply to Howard ChuThe event 'timer:hrtimer_setup' is relatively new, for older kernels, perf trace enum tests won't run as the event 'timer:hrtimer_setup' cannot be found.
It was originally called 'timer:hrtimer_init', before being renamed in:
commit 244132c4e577 ("tracing/timers: Rename the hrtimer_init event to hrtimer_setup")
Using timer:hrtimer_start should be enough for current testing, and hopefully 'start' won't be renamed in the future.
Before:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 786187
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint timer:hrtimer_setup,timer:hrtimer_start
[tracepoint failure] Failed to trace timer:hrtimer_setup,timer:hrtimer_start tracepoint, output:
event syntax error: 'timer:hrtimer_setup,timer:hrtimer_start'
\___ unknown tracepoint Error: File /sys/kernel/tracing//events/timer/hrtimer_setup not found.
Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?.
Run 'perf list' for a list of valid events
Usage: perf trace [<options>] [<command>]
or: perf trace [<options>] -- <command> [<options>]
or: perf trace record [<options>] [<command>]
or: perf trace record [<options>] -- <command> [<options>]
-e, --event <event> event/syscall selector. use 'perf list' to list available events
---- end(-1) ----
107: perf trace enum augmentation tests : FAILED!
After:
$ sudo /tmp/perf test enum -vv
107: perf trace enum augmentation tests:
107: perf trace enum augmentation tests : Running
--- start ---
test child forked, pid 808547
Checking if vmlinux exists
Tracing syscall landlock_add_rule
Tracing non-syscall tracepoint timer:hrtimer_start
---- end(0) ----
107: perf trace enum augmentation tests : Ok--- tools/perf/tests/shell/trace_btf_enum.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/trace_btf_enum.sh +1 -1
@@ -5,7 +5,7 @@ err=0 syscall="landlock_add_rule" -non_syscall="timer:hrtimer_setup,timer:hrtimer_start" +non_syscall="timer:hrtimer_start" TESTPROG="perf test -w landlock"
Signature · 1 line
2.45.2
PATCH 4/5 perf test trace: Remove set -e for BTF general tests
In reply to Howard ChuRemove set -e and print error messages in BTF general tests.
Before:
$ sudo /tmp/perf test btf -vv
108: perf trace BTF general tests:
108: perf trace BTF general tests : Running
--- start ---
test child forked, pid 889299
Checking if vmlinux BTF exists
Testing perf trace's string augmentation
String augmentation test failed
---- end(-1) ----
108: perf trace BTF general tests : FAILED!After:
$ sudo /tmp/perf test btf -vv
108: perf trace BTF general tests:
108: perf trace BTF general tests : Running
--- start ---
test child forked, pid 886551
Checking if vmlinux BTF exists
Testing perf trace's string augmentation
String augmentation test failed, output:
:886566/886566 renameat2(CWD, "/tmp/file1_RcMa", CWD, "/tmp/file2_RcMa", NOREPLACE) = 0---- end(-1) ----
108: perf trace BTF general tests : FAILED!--- tools/perf/tests/shell/trace_btf_general.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
tools/perf/tests/shell/trace_btf_general.sh +9 -10
@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 err=0 -set -e # shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh
@@ -28,10 +27,10 @@ check_vmlinux() { 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]+$" + output="$(perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" + if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" then - echo "String augmentation test failed" + printf "String augmentation test failed, output:\n$output" err=1 fi }
@@ -39,20 +38,20 @@ trace_test_string() { 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]+$" + output="$(perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1)" + if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" then - echo "Buffer augmentation test failed" + printf "Buffer augmentation test failed, output:\n$output" 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]+$" + output="$(perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" + if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" then - echo "BTF struct augmentation test failed" + printf "BTF struct augmentation test failed, output:\n$output" err=1 fi }
Signature · 1 line
2.45.2
Namhyung Kim
maintainerRe: [PATCH v1 4/5] perf test trace: Remove set -e for BTF general tests
Quoted 44 lines · Howard Chu
Remove set -e and print error messages in BTF general tests.
Before:
$ sudo /tmp/perf test btf -vv 108: perf trace BTF general tests: 108: perf trace BTF general tests : Running --- start --- test child forked, pid 889299 Checking if vmlinux BTF exists Testing perf trace's string augmentation String augmentation test failed ---- end(-1) ---- 108: perf trace BTF general tests : FAILED!After:
$ sudo /tmp/perf test btf -vv 108: perf trace BTF general tests: 108: perf trace BTF general tests : Running --- start --- test child forked, pid 886551 Checking if vmlinux BTF exists Testing perf trace's string augmentation String augmentation test failed, output: :886566/886566 renameat2(CWD, "/tmp/file1_RcMa", CWD, "/tmp/file2_RcMa", NOREPLACE) = 0---- end(-1) ---- 108: perf trace BTF general tests : FAILED!Signed-off-by Howard Chu <[email protected]>--- tools/perf/tests/shell/trace_btf_general.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)tools/perf/tests/shell/trace_btf_general.sh +0
-1@@ -3,7 +3,6 @@ # SPDX-License-Identifier: GPL-2.0 err=0 -set -e # shellcheck source=lib/probe.sh . "$(dirname $0)"/lib/probe.sh
tools/perf/tests/shell/trace_btf_general.sh check_vmlinux() { · line 33
Quoted 10 lines
tools/perf/tests/shell/trace_btf_general.sh +3
-3@@ -28,10 +27,10 @@ check_vmlinux() { 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]+$" + output="$(perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" + if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" then - echo "String augmentation test failed" + printf "String augmentation test failed, output:\n$output"
Looks like you need "\n" after the output as well.
Quoted 4 lines
tools/perf/tests/shell/trace_btf_general.sh +0
-0err=1 fi }
tools/perf/tests/shell/trace_btf_general.sh trace_test_string() { · line 44
Quoted 10 lines
tools/perf/tests/shell/trace_btf_general.sh +3
-3@@ -39,20 +38,20 @@ trace_test_string() { 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]+$" + output="$(perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1)" + if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" then - echo "Buffer augmentation test failed" + printf "Buffer augmentation test failed, output:\n$output"
Ditto. And probably for the previous patch too.
tools/perf/tests/shell/trace_btf_general.sh trace_test_string() { · line 54
Quoted 13 lines
tools/perf/tests/shell/trace_btf_general.sh +3
-3err=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]+$" + output="$(perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" + if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" then - echo "BTF struct augmentation test failed" + printf "BTF struct augmentation test failed, output:\n$output"
And here as well.
Thanks,
Namhyung
Quoted 6 lines
tools/perf/tests/shell/trace_btf_general.sh +0
-0err=1 fi }Signature · 1 line
2.45.2
Re: [PATCH v1 4/5] perf test trace: Remove set -e for BTF general tests
Hello,
Quoted 3 lines · Namhyung Kim
Quoted 1 line · Howard Chu
Remove set -e and print error messages in BTF general tests.
<SNIP>
Quoted 7 lines
tools/perf/tests/shell/trace_btf_general.sh check_vmlinux() { · line 33
Quoted 4 lines
tools/perf/tests/shell/trace_btf_general.sh +2
-1+ if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" then - echo "String augmentation test failed" + printf "String augmentation test failed, output:\n$output"Looks like you need "\n" after the output as well.
Quoted 16 lines
Quoted 4 lines
err=1fi
}tools/perf/tests/shell/trace_btf_general.sh trace_test_string() { · line 44
Quoted 10 lines
tools/perf/tests/shell/trace_btf_general.sh +3
-3@@ -39,20 +38,20 @@ trace_test_string() { 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]+$" + output="$(perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1)" + if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" then - echo "Buffer augmentation test failed" + printf "Buffer augmentation test failed, output:\n$output"Ditto. And probably for the previous patch too.
No problem, thanks. I should also mention I used the wrong title for patch 3. It should be 'perf test trace: Stop tracing hrtimer_setup event in trace enum test' instead of 'perf test trace: Stop tracing hrtimer_init event in trace enum test'. Thanks for the review and I will change them in v2.
Thanks,
Howard
PATCH 5/5 perf test trace BTF: Use --sort-events in BTF general tests
In reply to Howard ChuWithout the '--sort-events' flag, perf trace doesn't receive and process events based on their arrival time, thus PERF_RECORD_COMM event that assigns the correct comm to a PID, may be delivered and processed after regular samples, causing trace outputs not having a 'comm', e.g. 'mv', instead, having the default PID placeholder, e.g. ':14514'.
Hopefully this answers Namhyung's question in [1].
You can simply justify the statement with this diff:
---8<---
tools/perf/builtin-trace.c +1 -0
@@ -4204,6 +4204,7 @@ static int trace__deliver_event(struct trace *trace, union perf_event *event) {int err; +printf ("[debug] deliver\n" );if (!trace->sort_events)return __trace__deliver_event (trace, event);
tools/perf/util/comm.c +1 -0
@@ -213,6 +213,7 @@ int comm__override(struct comm *comm, const char *str, u64 timestamp, bool exec) new =comm_strs__findnew (str);if (!new)return -ENOMEM ; +printf ("[OVERRIDE] old %s new %s str %s\n" , old->str, new->str, str);comm_str__put (old); comm->comm_str = new;
tools/perf/util/machine.c +1 -0
@@ -578,6 +578,7 @@ int machine__process_comm_event(struct machine *machine, union perf_event *eventif (dump_trace)perf_event__fprintf_comm (event, stdout); +printf ("[debug] machine__process_comm_event\n" );if (thread ==NULL ||__thread__set_comm (thread, event->comm.comm, sample->time, exec)) {dump_printf ("problem processing PERF_RECORD_COMM, skipping event.\n" );
Now, simply run this command multiple times:
$ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2 And you should see two types of results:
$ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2
[debug] deliver
[debug] machine__process_comm_event
[OVERRIDE] old :1221169 new mv str mv
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
0.000 ( 0.013 ms): mv/1221169 renameat2(olddfd: CWD, oldname: "/tmp/file1", newdfd: CWD, newname: "/tmp/file2", flags: NOREPLACE) = 0
[debug] deliver $ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
[debug] deliver
0.000 ( 0.014 ms): :1221398/1221398 renameat2(olddfd: CWD, oldname: "/tmp/file1", newdfd: CWD, newname: "/tmp/file2", flags: NOREPLACE) = 0
[debug] deliver
[debug] deliver
[debug] machine__process_comm_event
[OVERRIDE] old :1221398 new mv str mv
[debug] deliver
[debug] deliver
[debug] deliverAnyway, use --sort-events in BTF general tests to avoid :PID, a comm is preferred.
[1]: https://lore.kernel.org/linux-perf-users/[email protected]/
--- tools/perf/tests/shell/trace_btf_general.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/perf/tests/shell/trace_btf_general.sh +3 -3
@@ -27,7 +27,7 @@ check_vmlinux() { trace_test_string() { echo "Testing perf trace's string augmentation" - output="$(perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" + output="$(perf trace --sort-events -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" then printf "String augmentation test failed, output:\n$output"
@@ -38,7 +38,7 @@ trace_test_string() { trace_test_buffer() { echo "Testing perf trace's buffer augmentation" # echo will insert a newline (\10) at the end of the buffer - output="$(perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1)" + output="$(perf trace --sort-events -e write --max-events=1 -- echo "${buffer}" 2>&1)" if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" then printf "Buffer augmentation test failed, output:\n$output"
@@ -48,7 +48,7 @@ trace_test_buffer() { trace_test_struct_btf() { echo "Testing perf trace's struct augmentation" - output="$(perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" + output="$(perf trace --sort-events -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" then printf "BTF struct augmentation test failed, output:\n$output"
Signature · 1 line
2.45.2
Namhyung Kim
maintainerRe: [PATCH v1 5/5] perf test trace BTF: Use --sort-events in BTF general tests
Quoted 7 lines · Howard Chu
Without the '--sort-events' flag, perf trace doesn't receive and process events based on their arrival time, thus
PERF_RECORD_COMMevent that assigns the correct comm to a PID, may be delivered and processed after regular samples, causing trace outputs not having a 'comm', e.g. 'mv', instead, having the default PID placeholder, e.g. ':14514'.Hopefully this answers Namhyung's question in [1].
Thanks, it makes sense. Maybe it migrated to another CPU after exec.
Quoted 4 lines
You can simply justify the statement with this diff:
---8<---
Please do not use this in the format patch emails. This makes git treat the following contents as commit body so it'll be added to the commit as if it's a valid change. Maybe adding some spaces at the beginning of each line help. But I think it's better if you publish it somewhere else and add a link instead.
Thanks,
Namhyung
Quoted 119 lines
tools/perf/builtin-trace.c +1
-0@@ -4204,6 +4204,7 @@ static int trace__deliver_event(struct trace *trace, union perf_event *event) {int err; +printf ("[debug] deliver\n" );if (!trace->sort_events)return __trace__deliver_event (trace, event);tools/perf/util/comm.c +1
-0@@ -213,6 +213,7 @@ int comm__override(struct comm *comm, const char *str, u64 timestamp, bool exec) new =comm_strs__findnew (str);if (!new)return -ENOMEM ; +printf ("[OVERRIDE] old %s new %s str %s\n" , old->str, new->str, str);comm_str__put (old); comm->comm_str = new;tools/perf/util/machine.c +1
-0@@ -578,6 +578,7 @@ int machine__process_comm_event(struct machine *machine, union perf_event *eventif (dump_trace)perf_event__fprintf_comm (event, stdout); +printf ("[debug] machine__process_comm_event\n" );if (thread ==NULL ||__thread__set_comm (thread, event->comm.comm, sample->time, exec)) {dump_printf ("problem processing PERF_RECORD_COMM, skipping event.\n" );Now, simply run this command multiple times:
$ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2 And you should see two types of results:$ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2 [debug] deliver [debug] machine__process_comm_event [OVERRIDE] old :1221169 new mv str mv [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver 0.000 ( 0.013 ms): mv/1221169 renameat2(olddfd: CWD, oldname: "/tmp/file1", newdfd: CWD, newname: "/tmp/file2", flags: NOREPLACE) = 0 [debug] deliver$ touch /tmp/file1 && sudo /tmp/perf trace -e renameat* -- mv /tmp/file1 /tmp/file2 && rm -f /tmp/file2 [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver [debug] deliver 0.000 ( 0.014 ms): :1221398/1221398 renameat2(olddfd: CWD, oldname: "/tmp/file1", newdfd: CWD, newname: "/tmp/file2", flags: NOREPLACE) = 0 [debug] deliver [debug] deliver [debug] machine__process_comm_event [OVERRIDE] old :1221398 new mv str mv [debug] deliver [debug] deliver [debug] deliverAnyway, use --sort-events in BTF general tests to avoid :PID, a comm is preferred.
[1]: https://lore.kernel.org/linux-perf-users/[email protected]/
Signed-off-by Howard Chu <[email protected]>--- tools/perf/tests/shell/trace_btf_general.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tools/perf/tests/shell/trace_btf_general.sh +3
-3@@ -27,7 +27,7 @@ check_vmlinux() { trace_test_string() { echo "Testing perf trace's string augmentation" - output="$(perf trace -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" + output="$(perf trace --sort-events -e renameat* --max-events=1 -- mv ${file1} ${file2} 2>&1)" if ! echo "$output" | grep -q -E "^mv/[0-9]+ renameat(2)?\(.*, \"${file1}\", .*, \"${file2}\", .*\) += +[0-9]+$" then printf "String augmentation test failed, output:\n$output"@@ -38,7 +38,7 @@ trace_test_string() { trace_test_buffer() { echo "Testing perf trace's buffer augmentation" # echo will insert a newline (\10) at the end of the buffer - output="$(perf trace -e write --max-events=1 -- echo "${buffer}" 2>&1)" + output="$(perf trace --sort-events -e write --max-events=1 -- echo "${buffer}" 2>&1)" if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" then printf "Buffer augmentation test failed, output:\n$output"@@ -48,7 +48,7 @@ trace_test_buffer() { trace_test_struct_btf() { echo "Testing perf trace's struct augmentation" - output="$(perf trace -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" + output="$(perf trace --sort-events -e clock_nanosleep --force-btf --max-events=1 -- sleep 1 2>&1)" if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,\}, 0x[0-9a-f]+\) += +[0-9]+$" then printf "BTF struct augmentation test failed, output:\n$output"Signature · 1 line
2.45.2
Re: [PATCH v1 5/5] perf test trace BTF: Use --sort-events in BTF general tests
Hello Namhyung,
Quoted 15 lines · Namhyung Kim
Quoted 7 lines · Howard Chu
Without the '--sort-events' flag, perf trace doesn't receive and process events based on their arrival time, thus
PERF_RECORD_COMMevent that assigns the correct comm to a PID, may be delivered and processed after regular samples, causing trace outputs not having a 'comm', e.g. 'mv', instead, having the default PID placeholder, e.g. ':14514'.Hopefully this answers Namhyung's question in [1].
Thanks, it makes sense. Maybe it migrated to another CPU after exec.
Quoted 3 lines
You can simply justify the statement with this diff:
Quoted 7 lines
Quoted 1 line
---8<---
Please do not use this in the format patch emails. This makes git treat the following contents as commit body so it'll be added to the commit as if it's a valid change. Maybe adding some spaces at the beginning of each line help. But I think it's better if you publish it somewhere else and add a link instead.
Sorry. I will delete this scissor in v2.
Thanks,
Howard