Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Add a new shell test for perf ftrace

$ sudo ./perf test ftrace -vv
86: perf ftrace tests:
--- start ---
test child forked, pid 1772223
perf ftrace list test
syscalls for sleep:
__x64_sys_nanosleep
__ia32_sys_nanosleep
__x64_sys_clock_nanosleep
__ia32_sys_clock_nanosleep
perf ftrace list test [Success]
perf ftrace trace test
# tracer: function_graph
#
# CPU DURATION FUNCTION CALLS
# | | | | | | |
0) | __x64_sys_clock_nanosleep() {
0) | common_nsleep() {
0) | hrtimer_nanosleep() {
0) | do_nanosleep() {
perf ftrace trace test [Success]
perf ftrace latency test
target function: __x64_sys_clock_nanosleep
# DURATION | COUNT | GRAPH |
32 - 64 ms | 1 | ############################################## |
perf ftrace latency test [Success]
perf ftrace profile test
# Total (us) Avg (us) Max (us) Count Function
100136.400 100136.400 100136.400 1 __x64_sys_clock_nanosleep
100135.200 100135.200 100135.200 1 common_nsleep
100134.700 100134.700 100134.700 1 hrtimer_nanosleep
100133.700 100133.700 100133.700 1 do_nanosleep
100130.600 100130.600 100130.600 1 schedule
166.868 55.623 80.299 3 scheduler_tick
5.926 5.926 5.926 1 native_smp_send_reschedule
301.941 301.941 301.941 1 __x64_sys_execve
295.786 295.786 295.786 1 do_execveat_common.isra.0
71.397 35.699 46.403 2 bprm_execve
2.519 1.260 1.547 2 sched_mm_cid_before_execve
1.098 0.549 0.686 2 sched_mm_cid_after_execve
perf ftrace profile test [Success]
---- end(0) ----
86: perf ftrace tests : Ok

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/r/20240808044954.1775333-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
ed5bb548 90d78e7b

+84
+84
tools/perf/tests/shell/ftrace.sh
··· 1 + #!/bin/sh 2 + # perf ftrace tests 3 + # SPDX-License-Identifier: GPL-2.0 4 + 5 + set -e 6 + 7 + # perf ftrace commands only works for root 8 + if [ "$(id -u)" != 0 ]; then 9 + echo "perf ftrace test [Skipped: no permission]" 10 + exit 2 11 + fi 12 + 13 + output=$(mktemp /tmp/__perf_test.ftrace.XXXXXX) 14 + 15 + cleanup() { 16 + rm -f "${output}" 17 + 18 + trap - EXIT TERM INT 19 + } 20 + 21 + trap_cleanup() { 22 + cleanup 23 + exit 1 24 + } 25 + trap trap_cleanup EXIT TERM INT 26 + 27 + # this will be set in test_ftrace_trace() 28 + target_function= 29 + 30 + test_ftrace_list() { 31 + echo "perf ftrace list test" 32 + perf ftrace -F > "${output}" 33 + # this will be used in test_ftrace_trace() 34 + sleep_functions=$(grep 'sys_.*sleep$' "${output}") 35 + echo "syscalls for sleep:" 36 + echo "${sleep_functions}" 37 + echo "perf ftrace list test [Success]" 38 + } 39 + 40 + test_ftrace_trace() { 41 + echo "perf ftrace trace test" 42 + perf ftrace trace --graph-opts depth=5 sleep 0.1 > "${output}" 43 + # it should have some function name contains 'sleep' 44 + grep "^#" "${output}" 45 + grep -F 'sleep()' "${output}" 46 + # find actual syscall function name 47 + for FN in ${sleep_functions}; do 48 + if grep -q "${FN}" "${output}"; then 49 + target_function="${FN}" 50 + echo "perf ftrace trace test [Success]" 51 + return 52 + fi 53 + done 54 + 55 + echo "perf ftrace trace test [Failure: sleep syscall not found]" 56 + exit 1 57 + } 58 + 59 + test_ftrace_latency() { 60 + echo "perf ftrace latency test" 61 + echo "target function: ${target_function}" 62 + perf ftrace latency -T "${target_function}" sleep 0.1 > "${output}" 63 + grep "^#" "${output}" 64 + grep "###" "${output}" 65 + echo "perf ftrace latency test [Success]" 66 + } 67 + 68 + test_ftrace_profile() { 69 + echo "perf ftrace profile test" 70 + perf ftrace profile sleep 0.1 > "${output}" 71 + grep ^# "${output}" 72 + grep sleep "${output}" 73 + grep schedule "${output}" 74 + grep execve "${output}" 75 + echo "perf ftrace profile test [Success]" 76 + } 77 + 78 + test_ftrace_list 79 + test_ftrace_trace 80 + test_ftrace_latency 81 + test_ftrace_profile 82 + 83 + cleanup 84 + exit 0