|
| 1 | +#!/bin/sh |
| 2 | +# perf trace summary |
| 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 | + |
| 10 | +skip_if_no_perf_trace || exit 2 |
| 11 | +[ "$(id -u)" = 0 ] || exit 2 |
| 12 | + |
| 13 | +OUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX) |
| 14 | + |
| 15 | +test_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 |
| 39 | +test_perf_trace "-s" |
| 40 | + |
| 41 | +# normal output with summary at the end |
| 42 | +test_perf_trace "-S" |
| 43 | + |
| 44 | +# summary only with an explicit summary mode |
| 45 | +test_perf_trace "-s --summary-mode=thread" |
| 46 | + |
| 47 | +# summary with normal output - total summary mode |
| 48 | +test_perf_trace "-S --summary-mode=total" |
| 49 | + |
| 50 | +# summary only for system wide - per-thread summary |
| 51 | +test_perf_trace "-as --summary-mode=thread --no-bpf-summary" |
| 52 | + |
| 53 | +# summary only for system wide - total summary mode |
| 54 | +test_perf_trace "-as --summary-mode=total --no-bpf-summary" |
| 55 | + |
| 56 | +# summary only for system wide - per-thread summary with BPF |
| 57 | +test_perf_trace "-as --summary-mode=thread --bpf-summary" |
| 58 | + |
| 59 | +# summary only for system wide - total summary mode with BPF |
| 60 | +test_perf_trace "-as --summary-mode=total --bpf-summary" |
| 61 | + |
| 62 | +# summary with normal output for system wide - total summary mode with BPF |
| 63 | +test_perf_trace "-aS --summary-mode=total --bpf-summary" |
| 64 | + |
| 65 | +rm -f ${OUTPUT} |
0 commit comments