1 #!/bin/bash 2 3 # SPDX-License-Identifier: GPL-2.0 4 5 # 6 # test_basic of perf_report test 7 # Author: Michael Petlan <mpetlan@redhat.com> 8 # 9 # Description: 10 # 11 # This test tests basic functionality of perf report command. 12 # 13 # 14 15 # include working environment 16 . ../common/init.sh 17 18 TEST_RESULT=0 19 20 21 ### help message 22 23 if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then 24 # test that a help message is shown and looks reasonable 25 $CMD_PERF report --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err 26 PERF_EXIT_CODE=$? 27 28 ../common/check_all_patterns_found.pl "PERF-REPORT" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "OVERHEAD\s+CALCULATION" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log 29 CHECK_EXIT_CODE=$? 30 ../common/check_all_patterns_found.pl "input" "verbose" "show-nr-samples" "show-cpu-utilization" "threads" "comms" "pid" "tid" "dsos" "symbols" "symbol-filter" < $LOGS_DIR/basic_helpmsg.log 31 (( CHECK_EXIT_CODE += $? )) 32 ../common/check_all_patterns_found.pl "hide-unresolved" "sort" "fields" "parent" "exclude-other" "column-widths" "field-separator" "dump-raw-trace" "children" < $LOGS_DIR/basic_helpmsg.log 33 (( CHECK_EXIT_CODE += $? )) 34 ../common/check_all_patterns_found.pl "call-graph" "max-stack" "inverted" "ignore-callees" "pretty" "stdio" "tui" "gtk" "vmlinux" "kallsyms" "modules" < $LOGS_DIR/basic_helpmsg.log 35 (( CHECK_EXIT_CODE += $? )) 36 ../common/check_all_patterns_found.pl "force" "symfs" "cpu" "disassembler-style" "source" "asm-raw" "show-total-period" "show-info" "branch-stack" "group" < $LOGS_DIR/basic_helpmsg.log 37 (( CHECK_EXIT_CODE += $? )) 38 ../common/check_all_patterns_found.pl "branch-history" "objdump" "demangle" "percent-limit" "percentage" "header" "itrace" "full-source-path" "show-ref-call-graph" < $LOGS_DIR/basic_helpmsg.log 39 (( CHECK_EXIT_CODE += $? )) 40 ../common/check_no_patterns_found.pl "No manual entry for" < $LOGS_DIR/basic_helpmsg.err 41 (( CHECK_EXIT_CODE += $? )) 42 43 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message" 44 (( TEST_RESULT += $? )) 45 else 46 print_testcase_skipped "help message" 47 fi 48 49 50 ### basic execution 51 52 # test that perf report is even working 53 $CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio > $LOGS_DIR/basic_basic.log 2> $LOGS_DIR/basic_basic.err 54 PERF_EXIT_CODE=$? 55 56 REGEX_LOST_SAMPLES_INFO="#\s*Total Lost Samples:\s+$RE_NUMBER" 57 REGEX_SAMPLES_INFO="#\s*Samples:\s+(?:$RE_NUMBER)\w?\s+of\s+event\s+'$RE_EVENT_ANY'" 58 REGEX_LINES_HEADER="#\s*Children\s+Self\s+Command\s+Shared Object\s+Symbol" 59 REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" 60 ../common/check_all_patterns_found.pl "$REGEX_LOST_SAMPLES_INFO" "$REGEX_SAMPLES_INFO" "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_basic.log 61 CHECK_EXIT_CODE=$? 62 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err 63 (( CHECK_EXIT_CODE += $? )) 64 65 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution" 66 (( TEST_RESULT += $? )) 67 68 69 ### number of samples 70 71 # '--show-nr-samples' should show number of samples for each symbol 72 $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --show-nr-samples > $LOGS_DIR/basic_nrsamples.log 2> $LOGS_DIR/basic_nrsamples.err 73 PERF_EXIT_CODE=$? 74 75 REGEX_LINES_HEADER="#\s*Children\s+Self\s+Samples\s+Command\s+Shared Object\s+Symbol" 76 REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" 77 ../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_nrsamples.log 78 CHECK_EXIT_CODE=$? 79 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_nrsamples.err 80 (( CHECK_EXIT_CODE += $? )) 81 82 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "number of samples" 83 (( TEST_RESULT += $? )) 84 85 86 ### header 87 88 # '--header' and '--header-only' should show perf report header 89 $CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --header-only > $LOGS_DIR/basic_header.log 90 PERF_EXIT_CODE=$? 91 92 REGEX_LINE_TIMESTAMP="#\s+captured on\s*:\s*$RE_DATE_TIME" 93 REGEX_LINE_HOSTNAME="#\s+hostname\s*:\s*$MY_HOSTNAME" 94 REGEX_LINE_KERNEL="#\s+os release\s*:\s*${MY_KERNEL_VERSION//+/\\+}" 95 REGEX_LINE_PERF="#\s+perf version\s*:\s*" 96 REGEX_LINE_ARCH="#\s+arch\s*:\s*$MY_ARCH" 97 REGEX_LINE_CPUS_ONLINE="#\s+nrcpus online\s*:\s*$MY_CPUS_ONLINE" 98 REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$MY_CPUS_AVAILABLE" 99 # disable precise check for "nrcpus avail" in BASIC runmode 100 test $PERFTOOL_TESTSUITE_RUNMODE -lt $RUNMODE_STANDARD && REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$RE_NUMBER" 101 ../common/check_all_patterns_found.pl "$REGEX_LINE_TIMESTAMP" "$REGEX_LINE_HOSTNAME" "$REGEX_LINE_KERNEL" "$REGEX_LINE_PERF" "$REGEX_LINE_ARCH" "$REGEX_LINE_CPUS_ONLINE" "$REGEX_LINE_CPUS_AVAIL" < $LOGS_DIR/basic_header.log 102 CHECK_EXIT_CODE=$? 103 104 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header" 105 (( TEST_RESULT += $? )) 106 107 # '--header' and '--header-only' should use creation time 108 OLD_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $CURRENT_TEST_DIR/perf.data | grep "captured on"` 109 PERF_EXIT_CODE=$? 110 111 ( tar -C $CURRENT_TEST_DIR -c perf.data | xz > $CURRENT_TEST_DIR/perf.data.tar.xz ; xzcat $CURRENT_TEST_DIR/perf.data.tar.xz | tar x -C $HEADER_TAR_DIR ) 112 (( PERF_EXIT_CODE += $? )) 113 114 NEW_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $HEADER_TAR_DIR/perf.data | grep "captured on"` 115 (( PERF_EXIT_CODE += $? )) 116 117 test "$OLD_TIMESTAMP" = "$NEW_TIMESTAMP" 118 CHECK_EXIT_CODE=$? 119 120 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header timestamp" 121 (( TEST_RESULT += $? )) 122 123 124 ### show CPU utilization 125 126 # '--showcpuutilization' should show percentage for both system and userspace mode 127 $CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --showcpuutilization > $LOGS_DIR/basic_cpuut.log 2> $LOGS_DIR/basic_cpuut.err 128 PERF_EXIT_CODE=$? 129 130 REGEX_LINES_HEADER="#\s*Children\s+Self\s+sys\s+usr\s+Command\s+Shared Object\s+Symbol" 131 REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" 132 ../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_cpuut.log 133 CHECK_EXIT_CODE=$? 134 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_cpuut.err 135 (( CHECK_EXIT_CODE += $? )) 136 137 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "show CPU utilization" 138 (( TEST_RESULT += $? )) 139 140 141 ### pid 142 143 # '--pid=' should limit the output for a process with the given pid only 144 $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --pid=1 > $LOGS_DIR/basic_pid.log 2> $LOGS_DIR/basic_pid.err 145 PERF_EXIT_CODE=$? 146 147 grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "systemd|init" 148 CHECK_EXIT_CODE=$? 149 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_pid.err 150 (( CHECK_EXIT_CODE += $? )) 151 152 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "pid" 153 (( TEST_RESULT += $? )) 154 155 156 ### non-existing symbol 157 158 # '--symbols' should show only the given symbols 159 $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbols=dummynonexistingsymbol > $LOGS_DIR/basic_symbols.log 2> $LOGS_DIR/basic_symbols.err 160 PERF_EXIT_CODE=$? 161 162 ../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/basic_symbols.log 163 CHECK_EXIT_CODE=$? 164 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbols.err 165 (( CHECK_EXIT_CODE += $? )) 166 167 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing symbol" 168 (( TEST_RESULT += $? )) 169 170 171 ### symbol filter 172 173 # '--symbol-filter' should filter symbols based on substrings 174 $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbol-filter=map > $LOGS_DIR/basic_symbolfilter.log 2> $LOGS_DIR/basic_symbolfilter.err 175 PERF_EXIT_CODE=$? 176 177 grep -P -v '^#' $LOGS_DIR/basic_symbolfilter.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "\[[k\.]\]\s+.*map" 178 CHECK_EXIT_CODE=$? 179 ../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbolfilter.err 180 (( CHECK_EXIT_CODE += $? )) 181 182 print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "symbol filter" 183 (( TEST_RESULT += $? )) 184 185 186 # TODO: $CMD_PERF report -n --showcpuutilization -TUxDg 2> 01.log 187 188 # print overall results 189 print_overall_results "$TEST_RESULT" 190 exit $?
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.