brintos

brintos / linux-shallow public Read only

0
0
Text · 2.3 KiB · a6ee740 Raw
90 lines · bash
1#!/bin/sh2# perf ftrace tests3# SPDX-License-Identifier: GPL-2.04 5set -e6 7# perf ftrace commands only works for root8if [ "$(id -u)" != 0 ]; then9    echo "perf ftrace test  [Skipped: no permission]"10    exit 211fi12 13output=$(mktemp /tmp/__perf_test.ftrace.XXXXXX)14 15cleanup() {16  rm -f "${output}"17 18  trap - EXIT TERM INT19}20 21trap_cleanup() {22  cleanup23  exit 124}25trap trap_cleanup EXIT TERM INT26 27# this will be set in test_ftrace_trace()28target_function=29 30test_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 40test_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 name47    for FN in ${sleep_functions}; do48	if grep -q "${FN}" "${output}"; then49	    target_function="${FN}"50	    echo "perf ftrace trace test  [Success]"51	    return52	fi53    done54 55    echo "perf ftrace trace test  [Failure: sleep syscall not found]"56    exit 157}58 59test_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 68test_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    time_re="[[:space:]]+10[[:digit:]]{4}\.[[:digit:]]{3}"76    # 100283.000 100283.000 100283.000          1   __x64_sys_clock_nanosleep77    # Check for one *clock_nanosleep line with a Count of just 1 that takes a bit more than 0.1 seconds78    # Strip the _x64_sys part to work with other architectures79    grep -E "^${time_re}${time_re}${time_re}[[:space:]]+1[[:space:]]+.*clock_nanosleep" "${output}"80    echo "perf ftrace profile test  [Success]"81}82 83test_ftrace_list84test_ftrace_trace85test_ftrace_latency86test_ftrace_profile87 88cleanup89exit 090