xref: /linux/tools/perf/tests/shell/script.sh (revision a36e9f5cfe9eb3a1dce8769c7058251c42705357)
1#!/bin/sh
2# perf script tests
3# SPDX-License-Identifier: GPL-2.0
4
5set -e
6
7temp_dir=$(mktemp -d /tmp/perf-test-script.XXXXXXXXXX)
8
9perfdatafile="${temp_dir}/perf.data"
10db_test="${temp_dir}/db_test.py"
11
12err=0
13
14cleanup()
15{
16	trap - EXIT TERM INT
17	sane=$(echo "${temp_dir}" | cut -b 1-21)
18	if [ "${sane}" = "/tmp/perf-test-script" ] ; then
19		echo "--- Cleaning up ---"
20		rm -rf "${temp_dir:?}/"*
21		rmdir "${temp_dir}"
22	fi
23}
24
25trap_cleanup()
26{
27	cleanup
28	exit 1
29}
30
31trap trap_cleanup EXIT TERM INT
32
33
34test_db()
35{
36	echo "DB test"
37
38	# Check if python script is supported
39        if perf version --build-options | grep python | grep -q OFF ; then
40		echo "SKIP: python scripting is not supported"
41		err=2
42		return
43	fi
44
45	cat << "_end_of_file_" > "${db_test}"
46perf_db_export_mode = True
47perf_db_export_calls = False
48perf_db_export_callchains = True
49
50def sample_table(*args):
51    print(f'sample_table({args})')
52
53def call_path_table(*args):
54    print(f'call_path_table({args}')
55_end_of_file_
56	case $(uname -m)
57	in s390x)
58		cmd_flags="--call-graph dwarf -e cpu-clock";;
59	*)
60		cmd_flags="-g";;
61	esac
62
63	perf record $cmd_flags -o "${perfdatafile}" true
64	perf script -i "${perfdatafile}" -s "${db_test}"
65	echo "DB test [Success]"
66}
67
68test_parallel_perf()
69{
70	echo "parallel-perf test"
71	if ! python3 --version >/dev/null 2>&1 ; then
72		echo "SKIP: no python3"
73		err=2
74		return
75	fi
76	pp=$(dirname "$0")/../../scripts/python/parallel-perf.py
77	if [ ! -f "${pp}" ] ; then
78		echo "SKIP: parallel-perf.py script not found "
79		err=2
80		return
81	fi
82	perf_data="${temp_dir}/pp-perf.data"
83	output1_dir="${temp_dir}/output1"
84	output2_dir="${temp_dir}/output2"
85	perf record -o "${perf_data}" --sample-cpu uname
86	python3 "${pp}" -o "${output1_dir}" --jobs 4 --verbose -- perf script -i "${perf_data}"
87	python3 "${pp}" -o "${output2_dir}" --jobs 4 --verbose --per-cpu -- perf script -i "${perf_data}"
88	echo "parallel-perf test [Success]"
89}
90
91test_db
92test_parallel_perf
93
94cleanup
95
96exit $err
97