xref: /linux/tools/perf/tests/shell/trace_summary.sh (revision 0939bd2fcf337243133b0271335a2838857c319f)
12d099ccaSNamhyung Kim#!/bin/sh
29e893dabSArnaldo Carvalho de Melo# perf trace summary (exclusive)
32d099ccaSNamhyung Kim# SPDX-License-Identifier: GPL-2.0
42d099ccaSNamhyung Kim
52d099ccaSNamhyung Kim# Check that perf trace works with various summary mode
62d099ccaSNamhyung Kim
72d099ccaSNamhyung Kim# shellcheck source=lib/probe.sh
82d099ccaSNamhyung Kim. "$(dirname $0)"/lib/probe.sh
92d099ccaSNamhyung Kim
102d099ccaSNamhyung Kimskip_if_no_perf_trace || exit 2
112d099ccaSNamhyung Kim[ "$(id -u)" = 0 ] || exit 2
122d099ccaSNamhyung Kim
132d099ccaSNamhyung KimOUTPUT=$(mktemp /tmp/perf_trace_test.XXXXX)
142d099ccaSNamhyung Kim
152d099ccaSNamhyung Kimtest_perf_trace() {
162d099ccaSNamhyung Kim    args=$1
172d099ccaSNamhyung Kim    workload="true"
182d099ccaSNamhyung Kim    search="^\s*(open|read|close).*[0-9]+%$"
192d099ccaSNamhyung Kim
202d099ccaSNamhyung Kim    echo "testing: perf trace ${args} -- ${workload}"
212d099ccaSNamhyung Kim    perf trace ${args} -- ${workload} >${OUTPUT} 2>&1
222d099ccaSNamhyung Kim    if [ $? -ne 0 ]; then
232d099ccaSNamhyung Kim        echo "Error: perf trace ${args} failed unexpectedly"
242d099ccaSNamhyung Kim        cat ${OUTPUT}
252d099ccaSNamhyung Kim        rm -f ${OUTPUT}
262d099ccaSNamhyung Kim        exit 1
272d099ccaSNamhyung Kim    fi
282d099ccaSNamhyung Kim
292d099ccaSNamhyung Kim    count=$(grep -E -c -m 3 "${search}" ${OUTPUT})
302d099ccaSNamhyung Kim    if [ "${count}" != "3" ]; then
312d099ccaSNamhyung Kim	echo "Error: cannot find enough pattern ${search} in the output"
322d099ccaSNamhyung Kim	cat ${OUTPUT}
332d099ccaSNamhyung Kim	rm -f ${OUTPUT}
342d099ccaSNamhyung Kim	exit 1
352d099ccaSNamhyung Kim    fi
362d099ccaSNamhyung Kim}
372d099ccaSNamhyung Kim
382d099ccaSNamhyung Kim# summary only for a process
392d099ccaSNamhyung Kimtest_perf_trace "-s"
402d099ccaSNamhyung Kim
412d099ccaSNamhyung Kim# normal output with summary at the end
422d099ccaSNamhyung Kimtest_perf_trace "-S"
432d099ccaSNamhyung Kim
442d099ccaSNamhyung Kim# summary only with an explicit summary mode
452d099ccaSNamhyung Kimtest_perf_trace "-s --summary-mode=thread"
462d099ccaSNamhyung Kim
472d099ccaSNamhyung Kim# summary with normal output - total summary mode
482d099ccaSNamhyung Kimtest_perf_trace "-S --summary-mode=total"
492d099ccaSNamhyung Kim
502d099ccaSNamhyung Kim# summary only for system wide - per-thread summary
512d099ccaSNamhyung Kimtest_perf_trace "-as --summary-mode=thread --no-bpf-summary"
522d099ccaSNamhyung Kim
532d099ccaSNamhyung Kim# summary only for system wide - total summary mode
542d099ccaSNamhyung Kimtest_perf_trace "-as --summary-mode=total --no-bpf-summary"
552d099ccaSNamhyung Kim
56*6dd7a0fdSIan Rogersif ! perf check feature -q bpf; then
57*6dd7a0fdSIan Rogers    echo "Skip --bpf-summary tests as perf built without libbpf"
58*6dd7a0fdSIan Rogers    rm -f ${OUTPUT}
59*6dd7a0fdSIan Rogers    exit 2
60*6dd7a0fdSIan Rogersfi
61*6dd7a0fdSIan Rogers
622d099ccaSNamhyung Kim# summary only for system wide - per-thread summary with BPF
632d099ccaSNamhyung Kimtest_perf_trace "-as --summary-mode=thread --bpf-summary"
642d099ccaSNamhyung Kim
652d099ccaSNamhyung Kim# summary only for system wide - total summary mode with BPF
662d099ccaSNamhyung Kimtest_perf_trace "-as --summary-mode=total --bpf-summary"
672d099ccaSNamhyung Kim
682d099ccaSNamhyung Kim# summary with normal output for system wide - total summary mode with BPF
692d099ccaSNamhyung Kimtest_perf_trace "-aS --summary-mode=total --bpf-summary"
702d099ccaSNamhyung Kim
71dd8633bdSNamhyung Kim# summary only for system wide - cgroup summary mode with BPF
72dd8633bdSNamhyung Kimtest_perf_trace "-as --summary-mode=cgroup --bpf-summary"
73dd8633bdSNamhyung Kim
74dd8633bdSNamhyung Kim# summary with normal output for system wide - cgroup summary mode with BPF
75dd8633bdSNamhyung Kimtest_perf_trace "-aS --summary-mode=cgroup --bpf-summary"
76dd8633bdSNamhyung Kim
772d099ccaSNamhyung Kimrm -f ${OUTPUT}
78