Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Move all the check functions of stat CSV output to lib

These functions can be shared with the stat std output test.

There is no functional change.

Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ahmad Yasin <ahmad.yasin@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20230616031420.3751973-4-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Kan Liang and committed by
Arnaldo Carvalho de Melo
fc51fc87 6a80d794

+184 -173
+169
tools/perf/tests/shell/lib/stat_output.sh
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + 3 + # Return true if perf_event_paranoid is > $1 and not running as root. 4 + function ParanoidAndNotRoot() 5 + { 6 + [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 7 + } 8 + 9 + # $1 name $2 extra_opt 10 + check_no_args() 11 + { 12 + echo -n "Checking $1 output: no args" 13 + perf stat $2 true 14 + commachecker --no-args 15 + echo "[Success]" 16 + } 17 + 18 + check_system_wide() 19 + { 20 + echo -n "Checking $1 output: system wide " 21 + if ParanoidAndNotRoot 0 22 + then 23 + echo "[Skip] paranoid and not root" 24 + return 25 + fi 26 + perf stat -a $2 true 27 + commachecker --system-wide 28 + echo "[Success]" 29 + } 30 + 31 + check_system_wide_no_aggr() 32 + { 33 + echo -n "Checking $1 output: system wide no aggregation " 34 + if ParanoidAndNotRoot 0 35 + then 36 + echo "[Skip] paranoid and not root" 37 + return 38 + fi 39 + perf stat -A -a --no-merge $2 true 40 + commachecker --system-wide-no-aggr 41 + echo "[Success]" 42 + } 43 + 44 + check_interval() 45 + { 46 + echo -n "Checking $1 output: interval " 47 + perf stat -I 1000 $2 true 48 + commachecker --interval 49 + echo "[Success]" 50 + } 51 + 52 + check_event() 53 + { 54 + echo -n "Checking $1 output: event " 55 + perf stat -e cpu-clock $2 true 56 + commachecker --event 57 + echo "[Success]" 58 + } 59 + 60 + check_per_core() 61 + { 62 + echo -n "Checking $1 output: per core " 63 + if ParanoidAndNotRoot 0 64 + then 65 + echo "[Skip] paranoid and not root" 66 + return 67 + fi 68 + perf stat --per-core -a $2 true 69 + commachecker --per-core 70 + echo "[Success]" 71 + } 72 + 73 + check_per_thread() 74 + { 75 + echo -n "Checking $1 output: per thread " 76 + if ParanoidAndNotRoot 0 77 + then 78 + echo "[Skip] paranoid and not root" 79 + return 80 + fi 81 + perf stat --per-thread -a $2 true 82 + commachecker --per-thread 83 + echo "[Success]" 84 + } 85 + 86 + check_per_cache_instance() 87 + { 88 + echo -n "Checking $1 output: per cache instance " 89 + if ParanoidAndNotRoot 0 90 + then 91 + echo "[Skip] paranoid and not root" 92 + return 93 + fi 94 + perf stat --per-cache -a $2 true 95 + commachecker --per-cache 96 + echo "[Success]" 97 + } 98 + 99 + check_per_die() 100 + { 101 + echo -n "Checking $1 output: per die " 102 + if ParanoidAndNotRoot 0 103 + then 104 + echo "[Skip] paranoid and not root" 105 + return 106 + fi 107 + perf stat --per-die -a $2 true 108 + commachecker --per-die 109 + echo "[Success]" 110 + } 111 + 112 + check_per_node() 113 + { 114 + echo -n "Checking $1 output: per node " 115 + if ParanoidAndNotRoot 0 116 + then 117 + echo "[Skip] paranoid and not root" 118 + return 119 + fi 120 + perf stat --per-node -a $2 true 121 + commachecker --per-node 122 + echo "[Success]" 123 + } 124 + 125 + check_per_socket() 126 + { 127 + echo -n "Checking $1 output: per socket " 128 + if ParanoidAndNotRoot 0 129 + then 130 + echo "[Skip] paranoid and not root" 131 + return 132 + fi 133 + perf stat --per-socket -a $2 true 134 + commachecker --per-socket 135 + echo "[Success]" 136 + } 137 + 138 + # The perf stat options for per-socket, per-core, per-die 139 + # and -A ( no_aggr mode ) uses the info fetched from this 140 + # directory: "/sys/devices/system/cpu/cpu*/topology". For 141 + # example, socket value is fetched from "physical_package_id" 142 + # file in topology directory. 143 + # Reference: cpu__get_topology_int in util/cpumap.c 144 + # If the platform doesn't expose topology information, values 145 + # will be set to -1. For example, incase of pSeries platform 146 + # of powerpc, value for "physical_package_id" is restricted 147 + # and set to -1. Check here validates the socket-id read from 148 + # topology file before proceeding further 149 + 150 + FILE_LOC="/sys/devices/system/cpu/cpu*/topology/" 151 + FILE_NAME="physical_package_id" 152 + 153 + function check_for_topology() 154 + { 155 + if ! ParanoidAndNotRoot 0 156 + then 157 + socket_file=`ls $FILE_LOC/$FILE_NAME | head -n 1` 158 + [ -z $socket_file ] && { 159 + echo 0 160 + return 161 + } 162 + socket_id=`cat $socket_file` 163 + [ $socket_id == -1 ] && { 164 + echo 1 165 + return 166 + } 167 + fi 168 + echo 0 169 + }
+15 -173
tools/perf/tests/shell/stat+csv_output.sh
··· 6 6 7 7 set -e 8 8 9 - skip_test=0 9 + . $(dirname $0)/lib/stat_output.sh 10 + 10 11 csv_sep=@ 11 12 12 13 stat_output=$(mktemp /tmp/__perf_test.stat_output.csv.XXXXX) ··· 64 63 return 0 65 64 } 66 65 67 - # Return true if perf_event_paranoid is > $1 and not running as root. 68 - function ParanoidAndNotRoot() 69 - { 70 - [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] 71 - } 66 + perf_cmd="-x$csv_sep -o ${stat_output}" 72 67 73 - check_no_args() 74 - { 75 - echo -n "Checking CSV output: no args " 76 - perf stat -x$csv_sep -o "${stat_output}" true 77 - commachecker --no-args 78 - echo "[Success]" 79 - } 80 - 81 - check_system_wide() 82 - { 83 - echo -n "Checking CSV output: system wide " 84 - if ParanoidAndNotRoot 0 85 - then 86 - echo "[Skip] paranoid and not root" 87 - return 88 - fi 89 - perf stat -x$csv_sep -a -o "${stat_output}" true 90 - commachecker --system-wide 91 - echo "[Success]" 92 - } 93 - 94 - check_system_wide_no_aggr() 95 - { 96 - echo -n "Checking CSV output: system wide no aggregation " 97 - if ParanoidAndNotRoot 0 98 - then 99 - echo "[Skip] paranoid and not root" 100 - return 101 - fi 102 - perf stat -x$csv_sep -A -a --no-merge -o "${stat_output}" true 103 - commachecker --system-wide-no-aggr 104 - echo "[Success]" 105 - } 106 - 107 - check_interval() 108 - { 109 - echo -n "Checking CSV output: interval " 110 - perf stat -x$csv_sep -I 1000 -o "${stat_output}" true 111 - commachecker --interval 112 - echo "[Success]" 113 - } 114 - 115 - 116 - check_event() 117 - { 118 - echo -n "Checking CSV output: event " 119 - perf stat -x$csv_sep -e cpu-clock -o "${stat_output}" true 120 - commachecker --event 121 - echo "[Success]" 122 - } 123 - 124 - check_per_core() 125 - { 126 - echo -n "Checking CSV output: per core " 127 - if ParanoidAndNotRoot 0 128 - then 129 - echo "[Skip] paranoid and not root" 130 - return 131 - fi 132 - perf stat -x$csv_sep --per-core -a -o "${stat_output}" true 133 - commachecker --per-core 134 - echo "[Success]" 135 - } 136 - 137 - check_per_thread() 138 - { 139 - echo -n "Checking CSV output: per thread " 140 - if ParanoidAndNotRoot 0 141 - then 142 - echo "[Skip] paranoid and not root" 143 - return 144 - fi 145 - perf stat -x$csv_sep --per-thread -a -o "${stat_output}" true 146 - commachecker --per-thread 147 - echo "[Success]" 148 - } 149 - 150 - check_per_cache_instance() 151 - { 152 - echo -n "Checking CSV output: per cache instance " 153 - if ParanoidAndNotRoot 0 154 - then 155 - echo "[Skip] paranoid and not root" 156 - return 157 - fi 158 - perf stat -x$csv_sep --per-cache -a true 2>&1 | commachecker --per-cache 159 - echo "[Success]" 160 - } 161 - 162 - check_per_die() 163 - { 164 - echo -n "Checking CSV output: per die " 165 - if ParanoidAndNotRoot 0 166 - then 167 - echo "[Skip] paranoid and not root" 168 - return 169 - fi 170 - perf stat -x$csv_sep --per-die -a -o "${stat_output}" true 171 - commachecker --per-die 172 - echo "[Success]" 173 - } 174 - 175 - check_per_node() 176 - { 177 - echo -n "Checking CSV output: per node " 178 - if ParanoidAndNotRoot 0 179 - then 180 - echo "[Skip] paranoid and not root" 181 - return 182 - fi 183 - perf stat -x$csv_sep --per-node -a -o "${stat_output}" true 184 - commachecker --per-node 185 - echo "[Success]" 186 - } 187 - 188 - check_per_socket() 189 - { 190 - echo -n "Checking CSV output: per socket " 191 - if ParanoidAndNotRoot 0 192 - then 193 - echo "[Skip] paranoid and not root" 194 - return 195 - fi 196 - perf stat -x$csv_sep --per-socket -a -o "${stat_output}" true 197 - commachecker --per-socket 198 - echo "[Success]" 199 - } 200 - 201 - # The perf stat options for per-socket, per-core, per-die 202 - # and -A ( no_aggr mode ) uses the info fetched from this 203 - # directory: "/sys/devices/system/cpu/cpu*/topology". For 204 - # example, socket value is fetched from "physical_package_id" 205 - # file in topology directory. 206 - # Reference: cpu__get_topology_int in util/cpumap.c 207 - # If the platform doesn't expose topology information, values 208 - # will be set to -1. For example, incase of pSeries platform 209 - # of powerpc, value for "physical_package_id" is restricted 210 - # and set to -1. Check here validates the socket-id read from 211 - # topology file before proceeding further 212 - 213 - FILE_LOC="/sys/devices/system/cpu/cpu*/topology/" 214 - FILE_NAME="physical_package_id" 215 - 216 - check_for_topology() 217 - { 218 - if ! ParanoidAndNotRoot 0 219 - then 220 - socket_file=`ls $FILE_LOC/$FILE_NAME | head -n 1` 221 - [ -z $socket_file ] && return 0 222 - socket_id=`cat $socket_file` 223 - [ $socket_id == -1 ] && skip_test=1 224 - return 0 225 - fi 226 - } 227 - 228 - check_for_topology 229 - check_no_args 230 - check_system_wide 231 - check_interval 232 - check_event 233 - check_per_thread 234 - check_per_node 68 + skip_test=$(check_for_topology) 69 + check_no_args "CSV" "$perf_cmd" 70 + check_system_wide "CSV" "$perf_cmd" 71 + check_interval "CSV" "$perf_cmd" 72 + check_event "CSV" "$perf_cmd" 73 + check_per_thread "CSV" "$perf_cmd" 74 + check_per_node "CSV" "$perf_cmd" 235 75 if [ $skip_test -ne 1 ] 236 76 then 237 - check_system_wide_no_aggr 238 - check_per_core 239 - check_per_cache_instance 240 - check_per_die 241 - check_per_socket 77 + check_system_wide_no_aggr "CSV" "$perf_cmd" 78 + check_per_core "CSV" "$perf_cmd" 79 + check_per_cache_instance "CSV" "$perf_cmd" 80 + check_per_die "CSV" "$perf_cmd" 81 + check_per_socket "CSV" "$perf_cmd" 242 82 else 243 83 echo "[Skip] Skipping tests for system_wide_no_aggr, per_core, per_die and per_socket since socket id exposed via topology is invalid" 244 84 fi