Skip to content

Commit 2aefb4c

Browse files
committed
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 <[email protected]> Cc: Hao Luo <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent f602705 commit 2aefb4c

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tools/perf/tests/shell/lock_contention.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,41 @@ test_aggr_task_stack_filter()
233233
fi
234234
}
235235

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+
236271
check
237272

238273
test_record
@@ -244,5 +279,6 @@ test_type_filter
244279
test_lock_filter
245280
test_stack_filter
246281
test_aggr_task_stack_filter
282+
test_csv_output
247283

248284
exit ${err}

0 commit comments

Comments
 (0)