xref: /linux/tools/perf/tests/shell/record+script_probe_vfs_getname.sh (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1#!/bin/sh
2# Use vfs_getname probe to get syscall args filenames
3
4# Uses the 'perf test shell' library to add probe:vfs_getname to the system
5# then use it with 'perf record' using 'touch' to write to a temp file, then
6# checks that that was captured by the vfs_getname probe in the generated
7# perf.data file, with the temp file name as the pathname argument.
8
9# SPDX-License-Identifier: GPL-2.0
10# Arnaldo Carvalho de Melo <acme@kernel.org>, 2017
11
12# shellcheck source=lib/probe.sh
13. "$(dirname "$0")/lib/probe.sh"
14
15skip_if_no_perf_probe || exit 2
16
17# shellcheck source=lib/probe_vfs_getname.sh
18. "$(dirname "$0")/lib/probe_vfs_getname.sh"
19
20record_open_file() {
21	echo "Recording open file:"
22	# Check presence of libtraceevent support to run perf record
23	skip_no_probe_record_support "probe:vfs_getname*"
24	if [ $? -eq 2 ]; then
25		echo "WARN: Skipping test record_open_file. No libtraceevent support"
26		return 2
27	fi
28	perf record -o ${perfdata} -e probe:vfs_getname\* touch $file
29}
30
31perf_script_filenames() {
32	echo "Looking at perf.data file for vfs_getname records for the file we touched:"
33	perf script -i ${perfdata} | \
34	grep -E " +touch +[0-9]+ +\[[0-9]+\] +[0-9]+\.[0-9]+: +probe:vfs_getname[_0-9]*: +\([[:xdigit:]]+\) +pathname=\"${file}\""
35}
36
37add_probe_vfs_getname || skip_if_no_debuginfo
38err=$?
39if [ $err -ne 0 ] ; then
40	exit $err
41fi
42
43perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
44file=$(mktemp /tmp/temporary_file.XXXXX)
45
46record_open_file && perf_script_filenames
47err=$?
48rm -f ${perfdata}
49rm -f ${file}
50cleanup_probe_vfs_getname
51exit $err
52