1#!/bin/sh 2# perf trace summary (exclusive) 3# SPDX-License-Identifier: GPL-2.0 4 5# Check that perf trace works with various summary mode 6 7# shellcheck source=lib/probe.sh 8. "$(dirname $0)"/lib/probe.sh 9 10skip_if_no_perf_trace || exit 2 11[ "$(id -u)" = 0 ] || exit 2 12 13OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX) 14 15test_perf_trace() { 16 args=$1 17 workload="true" 18 search="^\s*(open|read|close).*[0-9]+%$" 19 20 echo "testing: perf trace ${args} -- ${workload}" 21 perf trace ${args} -- ${workload} >${OUTPUT} 2>&1 22 if [ $? -ne 0 ]; then 23 echo "Error: perf trace ${args} failed unexpectedly" 24 cat ${OUTPUT} 25 rm -f ${OUTPUT} 26 exit 1 27 fi 28 29 count=$(grep -E -c -m 3 "${search}" ${OUTPUT}) 30 if [ "${count}" != "3" ]; then 31 echo "Error: cannot find enough pattern ${search} in the output" 32 cat ${OUTPUT} 33 rm -f ${OUTPUT} 34 exit 1 35 fi 36} 37 38# summary only for a process 39test_perf_trace "-s" 40 41# normal output with summary at the end 42test_perf_trace "-S" 43 44# summary only with an explicit summary mode 45test_perf_trace "-s --summary-mode=thread" 46 47# summary with normal output - total summary mode 48test_perf_trace "-S --summary-mode=total" 49 50# summary only for system wide - per-thread summary 51test_perf_trace "-as --summary-mode=thread --no-bpf-summary" 52 53# summary only for system wide - total summary mode 54test_perf_trace "-as --summary-mode=total --no-bpf-summary" 55 56if ! perf check feature -q bpf; then 57 echo "Skip --bpf-summary tests as perf built without libbpf" 58 rm -f ${OUTPUT} 59 exit 2 60fi 61 62# summary only for system wide - per-thread summary with BPF 63test_perf_trace "-as --summary-mode=thread --bpf-summary" 64 65# summary only for system wide - total summary mode with BPF 66test_perf_trace "-as --summary-mode=total --bpf-summary" 67 68# summary with normal output for system wide - total summary mode with BPF 69test_perf_trace "-aS --summary-mode=total --bpf-summary" 70 71# summary only for system wide - cgroup summary mode with BPF 72test_perf_trace "-as --summary-mode=cgroup --bpf-summary" 73 74# summary with normal output for system wide - cgroup summary mode with BPF 75test_perf_trace "-aS --summary-mode=cgroup --bpf-summary" 76 77rm -f ${OUTPUT} 78