1 #!/bin/bash 2 # perf script task-analyzer tests 3 # SPDX-License-Identifier: GPL-2.0 4 5 tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX) 6 err=0 7 8 # set PERF_EXEC_PATH to find scripts in the source directory 9 perfdir=$(dirname "$0")/../.. 10 if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then 11 export PERF_EXEC_PATH=$perfdir 12 fi 13 14 # Disable lsan to avoid warnings about python memory leaks. 15 export ASAN_OPTIONS=detect_leaks=0 16 17 cleanup() { 18 rm -f perf.data 19 rm -f perf.data.old 20 rm -f csv 21 rm -f csvsummary 22 rm -rf "$tmpdir" 23 trap - exit term int 24 } 25 26 trap_cleanup() { 27 cleanup 28 exit 1 29 } 30 trap trap_cleanup exit term int 31 32 report() { 33 if [ "$1" = 0 ]; then 34 echo "PASS: \"$2\"" 35 else 36 echo "FAIL: \"$2\" Error message: \"$3\"" 37 err=1 38 fi 39 } 40 41 check_exec_0() { 42 if [ $? != 0 ]; then 43 report 1 "invocation of $1 command failed" 44 fi 45 } 46 47 find_str_or_fail() { 48 grep -q "$1" "$2" 49 if [ "$?" != 0 ]; then 50 report 1 "$3" "Failed to find required string:'${1}'." 51 else 52 report 0 "$3" 53 fi 54 } 55 56 # check if perf is compiled with libtraceevent support 57 skip_no_probe_record_support() { 58 perf check feature -q libtraceevent && return 0 59 return 2 60 } 61 62 prepare_perf_data() { 63 # 1s should be sufficient to catch at least some switches 64 perf record -e sched:sched_switch -a -- sleep 1 > /dev/null 2>&1 65 # check if perf data file got created in above step. 66 if [ ! -e "perf.data" ]; then 67 printf "FAIL: perf record failed to create \"perf.data\" \n" 68 return 1 69 fi 70 } 71 72 # check standard inkvokation with no arguments 73 test_basic() { 74 out="$tmpdir/perf.out" 75 perf script report task-analyzer > "$out" 76 check_exec_0 "perf script report task-analyzer" 77 find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}" 78 } 79 80 test_ns_rename(){ 81 out="$tmpdir/perf.out" 82 perf script report task-analyzer --ns --rename-comms-by-tids 0:random > "$out" 83 check_exec_0 "perf script report task-analyzer --ns --rename-comms-by-tids 0:random" 84 find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}" 85 } 86 87 test_ms_filtertasks_highlight(){ 88 out="$tmpdir/perf.out" 89 perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf \ 90 > "$out" 91 check_exec_0 "perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf" 92 find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}" 93 } 94 95 test_extended_times_timelimit_limittasks() { 96 out="$tmpdir/perf.out" 97 perf script report task-analyzer --extended-times --time-limit :99999 \ 98 --limit-to-tasks perf > "$out" 99 check_exec_0 "perf script report task-analyzer --extended-times --time-limit :99999 --limit-to-tasks perf" 100 find_str_or_fail "Out-Out" "$out" "${FUNCNAME[0]}" 101 } 102 103 test_summary() { 104 out="$tmpdir/perf.out" 105 perf script report task-analyzer --summary > "$out" 106 check_exec_0 "perf script report task-analyzer --summary" 107 find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}" 108 } 109 110 test_summaryextended() { 111 out="$tmpdir/perf.out" 112 perf script report task-analyzer --summary-extended > "$out" 113 check_exec_0 "perf script report task-analyzer --summary-extended" 114 find_str_or_fail "Inter Task Times" "$out" "${FUNCNAME[0]}" 115 } 116 117 test_summaryonly() { 118 out="$tmpdir/perf.out" 119 perf script report task-analyzer --summary-only > "$out" 120 check_exec_0 "perf script report task-analyzer --summary-only" 121 find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}" 122 } 123 124 test_extended_times_summary_ns() { 125 out="$tmpdir/perf.out" 126 perf script report task-analyzer --extended-times --summary --ns > "$out" 127 check_exec_0 "perf script report task-analyzer --extended-times --summary --ns" 128 find_str_or_fail "Out-Out" "$out" "${FUNCNAME[0]}" 129 find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}" 130 } 131 132 test_csv() { 133 perf script report task-analyzer --csv csv > /dev/null 134 check_exec_0 "perf script report task-analyzer --csv csv" 135 find_str_or_fail "Comm;" csv "${FUNCNAME[0]}" 136 } 137 138 test_csv_extended_times() { 139 perf script report task-analyzer --csv csv --extended-times > /dev/null 140 check_exec_0 "perf script report task-analyzer --csv csv --extended-times" 141 find_str_or_fail "Out-Out;" csv "${FUNCNAME[0]}" 142 } 143 144 test_csvsummary() { 145 perf script report task-analyzer --csv-summary csvsummary > /dev/null 146 check_exec_0 "perf script report task-analyzer --csv-summary csvsummary" 147 find_str_or_fail "Comm;" csvsummary "${FUNCNAME[0]}" 148 } 149 150 test_csvsummary_extended() { 151 perf script report task-analyzer --csv-summary csvsummary --summary-extended \ 152 >/dev/null 153 check_exec_0 "perf script report task-analyzer --csv-summary csvsummary --summary-extended" 154 find_str_or_fail "Out-Out;" csvsummary "${FUNCNAME[0]}" 155 } 156 157 skip_no_probe_record_support 158 err=$? 159 if [ $err -ne 0 ]; then 160 echo "WARN: Skipping tests. No libtraceevent support" 161 cleanup 162 exit $err 163 fi 164 prepare_perf_data 165 test_basic 166 test_ns_rename 167 test_ms_filtertasks_highlight 168 test_extended_times_timelimit_limittasks 169 test_summary 170 test_summaryextended 171 test_summaryonly 172 test_extended_times_summary_ns 173 test_csv 174 test_csvsummary 175 test_csv_extended_times 176 test_csvsummary_extended 177 cleanup 178 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.