xref: /linux/tools/perf/tests/shell/base_report/test_basic.sh (revision 68a052239fc4b351e961f698b824f7654a346091)
1#!/bin/bash
2# perf_report :: Basic perf report options (exclusive)
3# SPDX-License-Identifier: GPL-2.0
4
5#
6#	test_basic of perf_report test
7#	Author: Michael Petlan <mpetlan@redhat.com>
8#
9#	Description:
10#
11#		This test tests basic functionality of perf report command.
12#
13#
14
15DIR_PATH="$(dirname $0)"
16TEST_RESULT=0
17
18# include working environment
19. "$DIR_PATH/../common/init.sh"
20
21
22### help message
23
24if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then
25	# test that a help message is shown and looks reasonable
26	$CMD_PERF report --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err
27	PERF_EXIT_CODE=$?
28
29	"$DIR_PATH/../common/check_all_patterns_found.pl" \
30		"PERF-REPORT" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \
31		"OVERHEAD\s+CALCULATION" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log
32	CHECK_EXIT_CODE=$?
33	"$DIR_PATH/../common/check_all_patterns_found.pl" \
34		"input" "verbose" "show-nr-samples" "show-cpu-utilization" \
35		"threads" "comms" "pid" "tid" "dsos" "symbols" "symbol-filter" \
36		< $LOGS_DIR/basic_helpmsg.log
37	(( CHECK_EXIT_CODE += $? ))
38	"$DIR_PATH/../common/check_all_patterns_found.pl" \
39		"hide-unresolved" "sort" "fields" "parent" "exclude-other" \
40		"column-widths" "field-separator" "dump-raw-trace" "children" \
41		< $LOGS_DIR/basic_helpmsg.log
42	(( CHECK_EXIT_CODE += $? ))
43	"$DIR_PATH/../common/check_all_patterns_found.pl" \
44		"call-graph" "max-stack" "inverted" "ignore-callees" "pretty" \
45		"stdio" "tui" "gtk" "vmlinux" "kallsyms" "modules" \
46		< $LOGS_DIR/basic_helpmsg.log
47	(( CHECK_EXIT_CODE += $? ))
48	"$DIR_PATH/../common/check_all_patterns_found.pl" \
49		"force" "symfs" "cpu" "disassembler-style" "source" "asm-raw" \
50		"show-total-period" "show-info" "branch-stack" "group" \
51		< $LOGS_DIR/basic_helpmsg.log
52	(( CHECK_EXIT_CODE += $? ))
53	"$DIR_PATH/../common/check_all_patterns_found.pl" \
54		"branch-history" "objdump" "demangle" "percent-limit" "percentage" \
55		"header" "itrace" "full-source-path" "show-ref-call-graph" \
56		< $LOGS_DIR/basic_helpmsg.log
57	(( CHECK_EXIT_CODE += $? ))
58	"$DIR_PATH/../common/check_no_patterns_found.pl" \
59		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err
60	(( CHECK_EXIT_CODE += $? ))
61
62	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message"
63	(( TEST_RESULT += $? ))
64else
65	print_testcase_skipped "help message"
66fi
67
68
69### basic execution
70
71# test that perf report is even working
72$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio > $LOGS_DIR/basic_basic.log 2> $LOGS_DIR/basic_basic.err
73PERF_EXIT_CODE=$?
74
75REGEX_LOST_SAMPLES_INFO="#\s*Total Lost Samples:\s+$RE_NUMBER"
76REGEX_SAMPLES_INFO="#\s*Samples:\s+(?:$RE_NUMBER)\w?\s+of\s+event\s+'$RE_EVENT_ANY'"
77REGEX_LINES_HEADER="#\s*Children\s+Self\s+Command\s+Shared Object\s+Symbol"
78REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
79"$DIR_PATH/../common/check_all_patterns_found.pl" \
80	"$REGEX_LOST_SAMPLES_INFO" "$REGEX_SAMPLES_INFO" \
81	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_basic.log
82CHECK_EXIT_CODE=$?
83"$DIR_PATH/../common/check_errors_whitelisted.pl" \
84	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err
85(( CHECK_EXIT_CODE += $? ))
86
87print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution"
88(( TEST_RESULT += $? ))
89
90
91### number of samples
92
93# '--show-nr-samples' should show number of samples for each symbol
94$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --show-nr-samples > $LOGS_DIR/basic_nrsamples.log 2> $LOGS_DIR/basic_nrsamples.err
95PERF_EXIT_CODE=$?
96
97REGEX_LINES_HEADER="#\s*Children\s+Self\s+Samples\s+Command\s+Shared Object\s+Symbol"
98REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
99"$DIR_PATH/../common/check_all_patterns_found.pl" \
100	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_nrsamples.log
101CHECK_EXIT_CODE=$?
102"$DIR_PATH/../common/check_errors_whitelisted.pl" \
103	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_nrsamples.err
104(( CHECK_EXIT_CODE += $? ))
105
106print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "number of samples"
107(( TEST_RESULT += $? ))
108
109
110### header
111
112# '--header' and '--header-only' should show perf report header
113$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --header-only > $LOGS_DIR/basic_header.log
114PERF_EXIT_CODE=$?
115
116REGEX_LINE_TIMESTAMP="#\s+captured on\s*:\s*$RE_DATE_TIME"
117REGEX_LINE_HOSTNAME="#\s+hostname\s*:\s*$MY_HOSTNAME"
118REGEX_LINE_KERNEL="#\s+os release\s*:\s*${MY_KERNEL_VERSION//+/\\+}"
119REGEX_LINE_PERF="#\s+perf version\s*:\s*"
120REGEX_LINE_ARCH="#\s+arch\s*:\s*$MY_ARCH"
121REGEX_LINE_CPUS_ONLINE="#\s+nrcpus online\s*:\s*$MY_CPUS_ONLINE"
122REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$MY_CPUS_AVAILABLE"
123# disable precise check for "nrcpus avail" in BASIC runmode
124test $PERFTOOL_TESTSUITE_RUNMODE -lt $RUNMODE_STANDARD && REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$RE_NUMBER"
125"$DIR_PATH/../common/check_all_patterns_found.pl" \
126	"$REGEX_LINE_TIMESTAMP" "$REGEX_LINE_HOSTNAME" "$REGEX_LINE_KERNEL" \
127	"$REGEX_LINE_PERF" "$REGEX_LINE_ARCH" "$REGEX_LINE_CPUS_ONLINE" \
128	"$REGEX_LINE_CPUS_AVAIL" < $LOGS_DIR/basic_header.log
129CHECK_EXIT_CODE=$?
130
131print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header"
132(( TEST_RESULT += $? ))
133
134# '--header' and '--header-only' should use creation time
135OLD_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $CURRENT_TEST_DIR/perf.data | grep "captured on"`
136PERF_EXIT_CODE=$?
137
138( tar -C $CURRENT_TEST_DIR -c perf.data | xz > $CURRENT_TEST_DIR/perf.data.tar.xz ; xzcat $CURRENT_TEST_DIR/perf.data.tar.xz | tar x -C $HEADER_TAR_DIR )
139(( PERF_EXIT_CODE += $? ))
140
141NEW_TIMESTAMP=`$CMD_PERF report --stdio --header-only -i $HEADER_TAR_DIR/perf.data | grep "captured on"`
142(( PERF_EXIT_CODE += $? ))
143
144test "$OLD_TIMESTAMP" = "$NEW_TIMESTAMP"
145CHECK_EXIT_CODE=$?
146
147print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header timestamp"
148(( TEST_RESULT += $? ))
149
150
151### show CPU utilization
152
153# '--showcpuutilization' should show percentage for both system and userspace mode
154$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data --stdio --showcpuutilization > $LOGS_DIR/basic_cpuut.log 2> $LOGS_DIR/basic_cpuut.err
155PERF_EXIT_CODE=$?
156
157REGEX_LINES_HEADER="#\s*Children\s+Self\s+sys\s+usr\s+Command\s+Shared Object\s+Symbol"
158REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+"
159"$DIR_PATH/../common/check_all_patterns_found.pl" \
160	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_cpuut.log
161CHECK_EXIT_CODE=$?
162"$DIR_PATH/../common/check_errors_whitelisted.pl" \
163	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_cpuut.err
164(( CHECK_EXIT_CODE += $? ))
165
166print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "show CPU utilization"
167(( TEST_RESULT += $? ))
168
169
170### pid
171
172# '--pid=' should limit the output for a process with the given pid only
173$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --pid=1 > $LOGS_DIR/basic_pid.log 2> $LOGS_DIR/basic_pid.err
174PERF_EXIT_CODE=$?
175
176grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | \
177	"$DIR_PATH/../common/check_all_lines_matched.pl" "systemd|init"
178CHECK_EXIT_CODE=$?
179"$DIR_PATH/../common/check_errors_whitelisted.pl" \
180	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_pid.err
181(( CHECK_EXIT_CODE += $? ))
182
183print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "pid"
184(( TEST_RESULT += $? ))
185
186
187### non-existing symbol
188
189# '--symbols' should show only the given symbols
190$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbols=dummynonexistingsymbol > $LOGS_DIR/basic_symbols.log 2> $LOGS_DIR/basic_symbols.err
191PERF_EXIT_CODE=$?
192
193"$DIR_PATH/../common/check_all_lines_matched.pl" \
194	"$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/basic_symbols.log
195CHECK_EXIT_CODE=$?
196"$DIR_PATH/../common/check_errors_whitelisted.pl" \
197	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_symbols.err
198(( CHECK_EXIT_CODE += $? ))
199
200print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing symbol"
201(( TEST_RESULT += $? ))
202
203
204### symbol filter
205
206# '--symbol-filter' should filter symbols based on substrings
207$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbol-filter=map > $LOGS_DIR/basic_symbolfilter.log 2> $LOGS_DIR/basic_symbolfilter.err
208PERF_EXIT_CODE=$?
209
210grep -P -v '^#' $LOGS_DIR/basic_symbolfilter.log | grep -P '\s+[\d\.]+%' | \
211	"$DIR_PATH/../common/check_all_lines_matched.pl" "\[[k\.]\]\s+.*map"
212CHECK_EXIT_CODE=$?
213"$DIR_PATH/../common/check_errors_whitelisted.pl" \
214	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_symbolfilter.err
215(( CHECK_EXIT_CODE += $? ))
216
217print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "symbol filter"
218(( TEST_RESULT += $? ))
219
220
221### latency and parallelism
222
223# Record with --latency should record with context switches.
224$CMD_PERF report -i $CURRENT_TEST_DIR/perf.data.1 --stdio --header-only > $LOGS_DIR/latency_header.log
225PERF_EXIT_CODE=$?
226
227"$DIR_PATH/../common/check_all_patterns_found.pl" \
228	", context_switch = 1, " < $LOGS_DIR/latency_header.log
229CHECK_EXIT_CODE=$?
230
231print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency header"
232(( TEST_RESULT += $? ))
233
234
235# The default report for latency profile should show Overhead and Latency fields (in that order).
236$CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/latency_default.log 2> $LOGS_DIR/latency_default.err
237PERF_EXIT_CODE=$?
238
239"$DIR_PATH/../common/check_all_patterns_found.pl" \
240	"# Overhead   Latency  Command" < $LOGS_DIR/latency_default.log
241CHECK_EXIT_CODE=$?
242"$DIR_PATH/../common/check_errors_whitelisted.pl" \
243	"stderr-whitelist.txt" < $LOGS_DIR/latency_default.err
244(( CHECK_EXIT_CODE += $? ))
245
246print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "default report for latency profile"
247(( TEST_RESULT += $? ))
248
249
250# The latency report for latency profile should show Latency and Overhead fields (in that order).
251$CMD_PERF report --latency --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/latency_latency.log 2> $LOGS_DIR/latency_latency.err
252PERF_EXIT_CODE=$?
253
254"$DIR_PATH/../common/check_all_patterns_found.pl" \
255	"#  Latency  Overhead  Command" < $LOGS_DIR/latency_latency.log
256CHECK_EXIT_CODE=$?
257"$DIR_PATH/../common/check_errors_whitelisted.pl" \
258	"stderr-whitelist.txt" < $LOGS_DIR/latency_latency.err
259(( CHECK_EXIT_CODE += $? ))
260
261print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency report for latency profile"
262(( TEST_RESULT += $? ))
263
264
265# Ensure parallelism histogram with parallelism filter does not fail/crash.
266$CMD_PERF report --hierarchy --sort latency,parallelism,comm,symbol --parallelism=1,2 --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/parallelism_hierarchy.log 2> $LOGS_DIR/parallelism_hierarchy.err
267PERF_EXIT_CODE=$?
268
269"$DIR_PATH/../common/check_all_patterns_found.pl" \
270	"#           Latency  Parallelism / Command / Symbol" \
271	< $LOGS_DIR/parallelism_hierarchy.log
272CHECK_EXIT_CODE=$?
273"$DIR_PATH/../common/check_errors_whitelisted.pl" \
274	"stderr-whitelist.txt" < $LOGS_DIR/parallelism_hierarchy.err
275(( CHECK_EXIT_CODE += $? ))
276
277print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "parallelism histogram"
278(( TEST_RESULT += $? ))
279
280
281# TODO: $CMD_PERF report -n --showcpuutilization -TUxDg 2> 01.log
282
283# print overall results
284print_overall_results "$TEST_RESULT"
285exit $?
286