| 1 | |
| 2 | |
| 3 | |
| 4 |
|
| 5 | set -e
|
| 6 |
|
| 7 | |
| 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 | |
| 28 | target_function=
|
| 29 |
|
| 30 | test_ftrace_list() {
|
| 31 | echo "perf ftrace list test"
|
| 32 | perf ftrace -F > "${output}"
|
| 33 | |
| 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 | |
| 44 | grep "^#" "${output}"
|
| 45 | grep -F 'sleep()' "${output}"
|
| 46 | |
| 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 --graph-opts depth=5 sleep 0.1 > "${output}"
|
| 71 | grep ^# "${output}"
|
| 72 | time_re="[[:space:]]+1[[:digit:]]{5}\.[[:digit:]]{3}"
|
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*sys_.*nanosleep" "${output}"
|
| 78 | echo "perf ftrace profile test [Success]"
|
| 79 | }
|
| 80 |
|
| 81 | test_ftrace_list
|
| 82 | test_ftrace_trace
|
| 83 | test_ftrace_latency
|
| 84 | test_ftrace_profile
|
| 85 |
|
| 86 | cleanup
|
| 87 | exit 0
|