1 #!/bin/sh 1 #!/bin/sh 2 # perf script tests 2 # perf script tests 3 # SPDX-License-Identifier: GPL-2.0 3 # SPDX-License-Identifier: GPL-2.0 4 4 5 set -e 5 set -e 6 6 7 temp_dir=$(mktemp -d /tmp/perf-test-script.XXX 7 temp_dir=$(mktemp -d /tmp/perf-test-script.XXXXXXXXXX) 8 8 9 perfdatafile="${temp_dir}/perf.data" 9 perfdatafile="${temp_dir}/perf.data" 10 db_test="${temp_dir}/db_test.py" 10 db_test="${temp_dir}/db_test.py" 11 11 12 err=0 12 err=0 13 13 14 cleanup() 14 cleanup() 15 { 15 { 16 trap - EXIT TERM INT 16 trap - EXIT TERM INT 17 sane=$(echo "${temp_dir}" | cut -b 1-2 17 sane=$(echo "${temp_dir}" | cut -b 1-21) 18 if [ "${sane}" = "/tmp/perf-test-scrip 18 if [ "${sane}" = "/tmp/perf-test-script" ] ; then 19 echo "--- Cleaning up ---" 19 echo "--- Cleaning up ---" 20 rm -rf "${temp_dir:?}/"* 20 rm -rf "${temp_dir:?}/"* 21 rmdir "${temp_dir}" 21 rmdir "${temp_dir}" 22 fi 22 fi 23 } 23 } 24 24 25 trap_cleanup() 25 trap_cleanup() 26 { 26 { 27 cleanup 27 cleanup 28 exit 1 28 exit 1 29 } 29 } 30 30 31 trap trap_cleanup EXIT TERM INT 31 trap trap_cleanup EXIT TERM INT 32 32 33 33 34 test_db() 34 test_db() 35 { 35 { 36 echo "DB test" 36 echo "DB test" 37 37 38 # Check if python script is supported 38 # Check if python script is supported 39 if perf version --build-options | grep 39 if perf version --build-options | grep python | grep -q OFF ; then 40 echo "SKIP: python scripting i 40 echo "SKIP: python scripting is not supported" 41 err=2 41 err=2 42 return 42 return 43 fi 43 fi 44 44 45 cat << "_end_of_file_" > "${db_test}" 45 cat << "_end_of_file_" > "${db_test}" 46 perf_db_export_mode = True 46 perf_db_export_mode = True 47 perf_db_export_calls = False 47 perf_db_export_calls = False 48 perf_db_export_callchains = True 48 perf_db_export_callchains = True 49 49 50 def sample_table(*args): 50 def sample_table(*args): 51 print(f'sample_table({args})') 51 print(f'sample_table({args})') 52 52 53 def call_path_table(*args): 53 def call_path_table(*args): 54 print(f'call_path_table({args}') 54 print(f'call_path_table({args}') 55 _end_of_file_ 55 _end_of_file_ 56 case $(uname -m) 56 case $(uname -m) 57 in s390x) 57 in s390x) 58 cmd_flags="--call-graph dwarf 58 cmd_flags="--call-graph dwarf -e cpu-clock";; 59 *) 59 *) 60 cmd_flags="-g";; 60 cmd_flags="-g";; 61 esac 61 esac 62 62 63 perf record $cmd_flags -o "${perfdataf 63 perf record $cmd_flags -o "${perfdatafile}" true 64 # Disable lsan to avoid warnings about 64 # Disable lsan to avoid warnings about python memory leaks. 65 export ASAN_OPTIONS=detect_leaks=0 65 export ASAN_OPTIONS=detect_leaks=0 66 perf script -i "${perfdatafile}" -s "$ 66 perf script -i "${perfdatafile}" -s "${db_test}" 67 export ASAN_OPTIONS= 67 export ASAN_OPTIONS= 68 echo "DB test [Success]" 68 echo "DB test [Success]" 69 } 69 } 70 70 71 test_parallel_perf() 71 test_parallel_perf() 72 { 72 { 73 echo "parallel-perf test" 73 echo "parallel-perf test" 74 if ! python3 --version >/dev/null 2>&1 74 if ! python3 --version >/dev/null 2>&1 ; then 75 echo "SKIP: no python3" 75 echo "SKIP: no python3" 76 err=2 76 err=2 77 return 77 return 78 fi 78 fi 79 pp=$(dirname "$0")/../../scripts/pytho 79 pp=$(dirname "$0")/../../scripts/python/parallel-perf.py 80 if [ ! -f "${pp}" ] ; then 80 if [ ! -f "${pp}" ] ; then 81 echo "SKIP: parallel-perf.py s 81 echo "SKIP: parallel-perf.py script not found " 82 err=2 82 err=2 83 return 83 return 84 fi 84 fi 85 perf_data="${temp_dir}/pp-perf.data" 85 perf_data="${temp_dir}/pp-perf.data" 86 output1_dir="${temp_dir}/output1" 86 output1_dir="${temp_dir}/output1" 87 output2_dir="${temp_dir}/output2" 87 output2_dir="${temp_dir}/output2" 88 perf record -o "${perf_data}" --sample 88 perf record -o "${perf_data}" --sample-cpu uname 89 python3 "${pp}" -o "${output1_dir}" -- 89 python3 "${pp}" -o "${output1_dir}" --jobs 4 --verbose -- perf script -i "${perf_data}" 90 python3 "${pp}" -o "${output2_dir}" -- 90 python3 "${pp}" -o "${output2_dir}" --jobs 4 --verbose --per-cpu -- perf script -i "${perf_data}" 91 echo "parallel-perf test [Success]" 91 echo "parallel-perf test [Success]" 92 } 92 } 93 93 94 test_db 94 test_db 95 test_parallel_perf 95 test_parallel_perf 96 96 97 cleanup 97 cleanup 98 98 99 exit $err 99 exit $err
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.