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

perf test: Test perf lock contention CSV output

To verify CSV output, just check the number of separators (",") using
the tr and wc commands like this.

grep -v "^#" ${result} | tr -d -c | wc -c

Now it expects 6 columns (and 5 separators) in the output, but it may
be changed later so count the field in the header first and compare it
to the actual output lines.

$ cat ${result}
# output: contended, total wait, max wait, avg wait, type, caller
1, 28787, 28787, 28787, spinlock, raw_spin_rq_lock_nested+0x1b

The test looks like below now:

$ sudo ./perf test -v contention
86: kernel lock contention analysis test :
--- start ---
test child forked, pid 2705822
Testing perf lock record and perf lock contention
Testing perf lock contention --use-bpf
Testing perf lock record and perf lock contention at the same time
Testing perf lock contention --threads
Testing perf lock contention --lock-addr
Testing perf lock contention --type-filter (w/ spinlock)
Testing perf lock contention --lock-filter (w/ tasklist_lock)
Testing perf lock contention --callstack-filter (w/ unix_stream)
Testing perf lock contention --callstack-filter with task aggregation
Testing perf lock contention CSV output
test child finished with 0
---- end ----
kernel lock contention analysis test: Ok

Acked-by: Ian Rogers <irogers@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20230628200141.2739587-5-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

+36
+36
tools/perf/tests/shell/lock_contention.sh
··· 233 233 fi 234 234 } 235 235 236 + test_csv_output() 237 + { 238 + echo "Testing perf lock contention CSV output" 239 + perf lock contention -i ${perfdata} -E 1 -x , --output ${result} 240 + # count the number of commas in the header 241 + # it should have 5: contended, total-wait, max-wait, avg-wait, type, caller 242 + header=$(grep "# output:" ${result} | tr -d -c , | wc -c) 243 + if [ "${header}" != "5" ]; then 244 + echo "[Fail] Recorded result does not have enough output columns: ${header} != 5" 245 + err=1 246 + exit 247 + fi 248 + # count the number of commas in the output 249 + output=$(grep -v "^#" ${result} | tr -d -c , | wc -c) 250 + if [ "${header}" != "${output}" ]; then 251 + echo "[Fail] Recorded result does not match the number of commas: ${header} != ${output}" 252 + err=1 253 + exit 254 + fi 255 + 256 + if ! perf lock con -b true > /dev/null 2>&1 ; then 257 + echo "[Skip] No BPF support" 258 + return 259 + fi 260 + 261 + # the perf lock contention output goes to the stderr 262 + perf lock con -a -b -E 1 -x , --output ${result} -- perf bench sched messaging > /dev/null 2>&1 263 + output=$(grep -v "^#" ${result} | tr -d -c , | wc -c) 264 + if [ "${header}" != "${output}" ]; then 265 + echo "[Fail] BPF result does not match the number of commas: ${header} != ${output}" 266 + err=1 267 + exit 268 + fi 269 + } 270 + 236 271 check 237 272 238 273 test_record ··· 279 244 test_lock_filter 280 245 test_stack_filter 281 246 test_aggr_task_stack_filter 247 + test_csv_output 282 248 283 249 exit ${err}