1#!/bin/bash 2# perf script task-analyzer tests 3# SPDX-License-Identifier: GPL-2.0 4 5tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX) 6err=0 7 8# set PERF_EXEC_PATH to find scripts in the source directory 9perfdir=$(dirname "$0")/../.. 10if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then 11 export PERF_EXEC_PATH=$perfdir 12fi 13 14# Disable lsan to avoid warnings about python memory leaks. 15export ASAN_OPTIONS=detect_leaks=0 16 17cleanup() { 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 26trap_cleanup() { 27 cleanup 28 exit 1 29} 30trap trap_cleanup exit term int 31 32report() { 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 41check_exec_0() { 42 if [ $? != 0 ]; then 43 report 1 "invocation of $1 command failed" 44 fi 45} 46 47find_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 57skip_no_probe_record_support() { 58 perf check feature -q libtraceevent && return 0 59 return 2 60} 61 62prepare_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 73test_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 80test_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 87test_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 95test_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 103test_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 110test_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 117test_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 124test_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 132test_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 138test_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 144test_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 150test_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 157skip_no_probe_record_support 158err=$? 159if [ $err -ne 0 ]; then 160 echo "WARN: Skipping tests. No libtraceevent support" 161 cleanup 162 exit $err 163fi 164prepare_perf_data 165test_basic 166test_ns_rename 167test_ms_filtertasks_highlight 168test_extended_times_timelimit_limittasks 169test_summary 170test_summaryextended 171test_summaryonly 172test_extended_times_summary_ns 173test_csv 174test_csvsummary 175test_csv_extended_times 176test_csvsummary_extended 177cleanup 178exit $err 179