1#!/bin/sh 2# Use vfs_getname probe to get syscall args filenames (exclusive) 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[ "$(id -u)" = 0 ] || exit 2 17 18# shellcheck source=lib/probe_vfs_getname.sh 19. "$(dirname "$0")/lib/probe_vfs_getname.sh" 20 21record_open_file() { 22 echo "Recording open file:" 23 # Check presence of libtraceevent support to run perf record 24 skip_no_probe_record_support "probe:vfs_getname*" 25 if [ $? -eq 2 ]; then 26 echo "WARN: Skipping test record_open_file. No libtraceevent support" 27 return 2 28 fi 29 perf record -o ${perfdata} -e probe:vfs_getname\* touch $file 30} 31 32perf_script_filenames() { 33 echo "Looking at perf.data file for vfs_getname records for the file we touched:" 34 perf script -i ${perfdata} | \ 35 grep -E " +touch +[0-9]+ +\[[0-9]+\] +[0-9]+\.[0-9]+: +probe:vfs_getname[_0-9]*: +\([[:xdigit:]]+\) +pathname=\"${file}\"" 36} 37 38add_probe_vfs_getname || skip_if_no_debuginfo 39err=$? 40if [ $err -ne 0 ] ; then 41 exit $err 42fi 43 44perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 45file=$(mktemp /tmp/temporary_file.XXXXX) 46 47record_open_file && perf_script_filenames 48err=$? 49rm -f ${perfdata} 50rm -f ${file} 51cleanup_probe_vfs_getname 52exit $err 53