Linux Audio

Check our new training course

Loading...
v6.8
  1#!/bin/bash
  2# perf script task-analyzer tests
  3# SPDX-License-Identifier: GPL-2.0
  4
  5tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
  6err=0
  7
  8# set PERF_EXEC_PATH to find scripts in the source directory
  9perfdir=$(dirname "$0")/../..
 10if [ -e "$perfdir/scripts/python/Perf-Trace-Util" ]; then
 11  export PERF_EXEC_PATH=$perfdir
 12fi
 13
 14cleanup() {
 15  rm -f perf.data
 16  rm -f perf.data.old
 17  rm -f csv
 18  rm -f csvsummary
 19  rm -rf "$tmpdir"
 20  trap - exit term int
 21}
 22
 23trap_cleanup() {
 24  cleanup
 25  exit 1
 26}
 27trap trap_cleanup exit term int
 28
 29report() {
 30	if [ "$1" = 0 ]; then
 31		echo "PASS: \"$2\""
 32	else
 33		echo "FAIL: \"$2\" Error message: \"$3\""
 34		err=1
 35	fi
 36}
 37
 38check_exec_0() {
 39	if [ $? != 0 ]; then
 40		report 1 "invocation of $1 command failed"
 41	fi
 42}
 43
 44find_str_or_fail() {
 45	grep -q "$1" "$2"
 46	if [ "$?" != 0 ]; then
 47		report 1 "$3" "Failed to find required string:'${1}'."
 48	else
 49		report 0 "$3"
 50	fi
 51}
 52
 53# check if perf is compiled with libtraceevent support
 54skip_no_probe_record_support() {
 55	perf version --build-options | grep -q " OFF .* HAVE_LIBTRACEEVENT" && return 2
 56	return 0
 57}
 58
 59prepare_perf_data() {
 60	# 1s should be sufficient to catch at least some switches
 61	perf record -e sched:sched_switch -a -- sleep 1 > /dev/null 2>&1
 62	# check if perf data file got created in above step.
 63	if [ ! -e "perf.data" ]; then
 64		printf "FAIL: perf record failed to create \"perf.data\" \n"
 65		return 1
 66	fi
 67}
 68
 69# check standard inkvokation with no arguments
 70test_basic() {
 71	out="$tmpdir/perf.out"
 72	perf script report task-analyzer > "$out"
 73	check_exec_0 "perf script report task-analyzer"
 74	find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}"
 75}
 76
 77test_ns_rename(){
 78	out="$tmpdir/perf.out"
 79	perf script report task-analyzer --ns --rename-comms-by-tids 0:random > "$out"
 80	check_exec_0 "perf script report task-analyzer --ns --rename-comms-by-tids 0:random"
 81	find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}"
 82}
 83
 84test_ms_filtertasks_highlight(){
 85	out="$tmpdir/perf.out"
 86	perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf \
 87	> "$out"
 88	check_exec_0 "perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf"
 89	find_str_or_fail "Comm" "$out" "${FUNCNAME[0]}"
 90}
 91
 92test_extended_times_timelimit_limittasks() {
 93	out="$tmpdir/perf.out"
 94	perf script report task-analyzer --extended-times --time-limit :99999 \
 95	--limit-to-tasks perf > "$out"
 96	check_exec_0 "perf script report task-analyzer --extended-times --time-limit :99999 --limit-to-tasks perf"
 97	find_str_or_fail "Out-Out" "$out" "${FUNCNAME[0]}"
 98}
 99
100test_summary() {
101	out="$tmpdir/perf.out"
102	perf script report task-analyzer --summary > "$out"
103	check_exec_0 "perf script report task-analyzer --summary"
104	find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}"
105}
106
107test_summaryextended() {
108	out="$tmpdir/perf.out"
109	perf script report task-analyzer --summary-extended > "$out"
110	check_exec_0 "perf script report task-analyzer --summary-extended"
111	find_str_or_fail "Inter Task Times" "$out" "${FUNCNAME[0]}"
112}
113
114test_summaryonly() {
115	out="$tmpdir/perf.out"
116	perf script report task-analyzer --summary-only > "$out"
117	check_exec_0 "perf script report task-analyzer --summary-only"
118	find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}"
119}
120
121test_extended_times_summary_ns() {
122	out="$tmpdir/perf.out"
123	perf script report task-analyzer --extended-times --summary --ns > "$out"
124	check_exec_0 "perf script report task-analyzer --extended-times --summary --ns"
125	find_str_or_fail "Out-Out" "$out" "${FUNCNAME[0]}"
126	find_str_or_fail "Summary" "$out" "${FUNCNAME[0]}"
127}
128
129test_csv() {
130	perf script report task-analyzer --csv csv > /dev/null
131	check_exec_0 "perf script report task-analyzer --csv csv"
132	find_str_or_fail "Comm;" csv "${FUNCNAME[0]}"
133}
134
135test_csv_extended_times() {
136	perf script report task-analyzer --csv csv --extended-times > /dev/null
137	check_exec_0 "perf script report task-analyzer --csv csv --extended-times"
138	find_str_or_fail "Out-Out;" csv "${FUNCNAME[0]}"
139}
140
141test_csvsummary() {
142	perf script report task-analyzer --csv-summary csvsummary > /dev/null
143	check_exec_0 "perf script report task-analyzer --csv-summary csvsummary"
144	find_str_or_fail "Comm;" csvsummary "${FUNCNAME[0]}"
145}
146
147test_csvsummary_extended() {
148	perf script report task-analyzer --csv-summary csvsummary --summary-extended \
149	>/dev/null
150	check_exec_0 "perf script report task-analyzer --csv-summary csvsummary --summary-extended"
151	find_str_or_fail "Out-Out;" csvsummary "${FUNCNAME[0]}"
152}
153
154skip_no_probe_record_support
155err=$?
156if [ $err -ne 0 ]; then
157	echo "WARN: Skipping tests. No libtraceevent support"
158	cleanup
159	exit $err
160fi
161prepare_perf_data
162test_basic
163test_ns_rename
164test_ms_filtertasks_highlight
165test_extended_times_timelimit_limittasks
166test_summary
167test_summaryextended
168test_summaryonly
169test_extended_times_summary_ns
170test_csv
171test_csvsummary
172test_csv_extended_times
173test_csvsummary_extended
174cleanup
175exit $err
v6.2
  1#!/bin/bash
  2# perf script task-analyzer tests
  3# SPDX-License-Identifier: GPL-2.0
  4
  5tmpdir=$(mktemp -d /tmp/perf-script-task-analyzer-XXXXX)
  6err=0
  7
 
 
 
 
 
 
  8cleanup() {
  9  rm -f perf.data
 10  rm -f perf.data.old
 11  rm -f csv
 12  rm -f csvsummary
 13  rm -rf $tmpdir
 14  trap - exit term int
 15}
 16
 17trap_cleanup() {
 18  cleanup
 19  exit 1
 20}
 21trap trap_cleanup exit term int
 22
 23report() {
 24	if [ $1 = 0 ]; then
 25		echo "PASS: \"$2\""
 26	else
 27		echo "FAIL: \"$2\" Error message: \"$3\""
 28		err=1
 29	fi
 30}
 31
 32check_exec_0() {
 33	if [ $? != 0 ]; then
 34		report 1 "invokation of ${$1} command failed"
 35	fi
 36}
 37
 38find_str_or_fail() {
 39	grep -q "$1" $2
 40	if [ $? != 0 ]; then
 41		report 1 $3 "Failed to find required string:'${1}'."
 42	else
 43		report 0 $3
 44	fi
 45}
 46
 
 
 
 
 
 
 47prepare_perf_data() {
 48	# 1s should be sufficient to catch at least some switches
 49	perf record -e sched:sched_switch -a -- sleep 1 > /dev/null 2>&1
 
 
 
 
 
 50}
 51
 52# check standard inkvokation with no arguments
 53test_basic() {
 54	out="$tmpdir/perf.out"
 55	perf script report task-analyzer > $out
 56	check_exec_0 "perf"
 57	find_str_or_fail "Comm" $out ${FUNCNAME[0]}
 58}
 59
 60test_ns_rename(){
 61	out="$tmpdir/perf.out"
 62	perf script report task-analyzer --ns --rename-comms-by-tids 0:random > $out
 63	check_exec_0 "perf"
 64	find_str_or_fail "Comm" $out ${FUNCNAME[0]}
 65}
 66
 67test_ms_filtertasks_highlight(){
 68	out="$tmpdir/perf.out"
 69	perf script report task-analyzer --ms --filter-tasks perf --highlight-tasks perf \
 70	> $out
 71	check_exec_0 "perf"
 72	find_str_or_fail "Comm" $out ${FUNCNAME[0]}
 73}
 74
 75test_extended_times_timelimit_limittasks() {
 76	out="$tmpdir/perf.out"
 77	perf script report task-analyzer --extended-times --time-limit :99999 \
 78	--limit-to-tasks perf > $out
 79	check_exec_0 "perf"
 80	find_str_or_fail "Out-Out" $out ${FUNCNAME[0]}
 81}
 82
 83test_summary() {
 84	out="$tmpdir/perf.out"
 85	perf script report task-analyzer --summary > $out
 86	check_exec_0 "perf"
 87	find_str_or_fail "Summary" $out ${FUNCNAME[0]}
 88}
 89
 90test_summaryextended() {
 91	out="$tmpdir/perf.out"
 92	perf script report task-analyzer --summary-extended > $out
 93	check_exec_0 "perf"
 94	find_str_or_fail "Inter Task Times" $out ${FUNCNAME[0]}
 95}
 96
 97test_summaryonly() {
 98	out="$tmpdir/perf.out"
 99	perf script report task-analyzer --summary-only > $out
100	check_exec_0 "perf"
101	find_str_or_fail "Summary" $out ${FUNCNAME[0]}
102}
103
104test_extended_times_summary_ns() {
105	out="$tmpdir/perf.out"
106	perf script report task-analyzer --extended-times --summary --ns > $out
107	check_exec_0 "perf"
108	find_str_or_fail "Out-Out" $out ${FUNCNAME[0]}
109	find_str_or_fail "Summary" $out ${FUNCNAME[0]}
110}
111
112test_csv() {
113	perf script report task-analyzer --csv csv > /dev/null
114	check_exec_0 "perf"
115	find_str_or_fail "Comm;" csv ${FUNCNAME[0]}
116}
117
118test_csv_extended_times() {
119	perf script report task-analyzer --csv csv --extended-times > /dev/null
120	check_exec_0 "perf"
121	find_str_or_fail "Out-Out;" csv ${FUNCNAME[0]}
122}
123
124test_csvsummary() {
125	perf script report task-analyzer --csv-summary csvsummary > /dev/null
126	check_exec_0 "perf"
127	find_str_or_fail "Comm;" csvsummary ${FUNCNAME[0]}
128}
129
130test_csvsummary_extended() {
131	perf script report task-analyzer --csv-summary csvsummary --summary-extended \
132	>/dev/null
133	check_exec_0 "perf"
134	find_str_or_fail "Out-Out;" csvsummary ${FUNCNAME[0]}
135}
136
 
 
 
 
 
 
 
137prepare_perf_data
138test_basic
139test_ns_rename
140test_ms_filtertasks_highlight
141test_extended_times_timelimit_limittasks
142test_summary
143test_summaryextended
144test_summaryonly
145test_extended_times_summary_ns
146test_csv
147test_csvsummary
148test_csv_extended_times
149test_csvsummary_extended
150cleanup
151exit $err