trace+probe_vfs_getname.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. # Check open filename arg using perf trace + vfs_getname (exclusive)
  3. # Uses the 'perf test shell' library to add probe:vfs_getname to the system
  4. # then use it with 'perf trace' using 'touch' to write to a temp file, then
  5. # checks that that was captured by the vfs_getname was used by 'perf trace',
  6. # that already handles "probe:vfs_getname" if present, and used in the
  7. # "open" syscall "filename" argument beautifier.
  8. # SPDX-License-Identifier: GPL-2.0
  9. # Arnaldo Carvalho de Melo <acme@kernel.org>, 2017
  10. # shellcheck source=lib/probe.sh
  11. . "$(dirname $0)"/lib/probe.sh
  12. skip_if_no_perf_probe || exit 2
  13. skip_if_no_perf_trace || exit 2
  14. [ "$(id -u)" = 0 ] || exit 2
  15. . "$(dirname $0)"/lib/probe_vfs_getname.sh
  16. trace_open_vfs_getname() {
  17. evts="$(echo "$(perf list tracepoint 2>/dev/null | grep -E 'syscalls:sys_enter_open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/')" | sed ':a;N;s:\n:,:g')"
  18. perf trace -e $evts touch $file 2>&1 | \
  19. grep -E " +[0-9]+\.[0-9]+ +\( +[0-9]+\.[0-9]+ ms\): +touch/[0-9]+ open(at)?\((dfd: +CWD, +)?filename: +\"?${file}\"?, +flags: CREAT\|NOCTTY\|NONBLOCK\|WRONLY, +mode: +IRUGO\|IWUGO\) += +[0-9]+$"
  20. }
  21. add_probe_vfs_getname
  22. err=$?
  23. if [ $err -eq 1 ] ; then
  24. skip_if_no_debuginfo
  25. err=$?
  26. fi
  27. if [ $err -ne 0 ] ; then
  28. exit $err
  29. fi
  30. file=$(mktemp /tmp/temporary_file.XXXXX)
  31. # Do not use whatever ~/.perfconfig file, it may change the output
  32. # via trace.{show_timestamp,show_prefix,etc}
  33. export PERF_CONFIG=/dev/null
  34. trace_open_vfs_getname
  35. err=$?
  36. rm -f ${file}
  37. cleanup_probe_vfs_getname
  38. exit $err