/usr/sbin/reset-ftrace-perf is in perf-tools-unstable 0.0.1~20160212+git0c13e83-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #!/bin/bash
#
# reset-ftrace - reset state of ftrace, disabling all tracing.
# Written for Linux ftrace.
#
# This may only be of use to ftrace hackers who, in the process of developing
# ftrace software, often get the subsystem into a partially active state, and
# would like a quick way to reset state. Check the end of this script for the
# actually files reset, and add more if you need.
#
# USAGE: ./reset-ftrace [-fhq]
#
# REQUIREMENTS: FTRACE CONFIG.
#
# From perf-tools: https://github.com/brendangregg/perf-tools
#
# See the reset-ftrace(8) man page (in perf-tools) for more info.
#
# COPYRIGHT: Copyright (c) 2014 Brendan Gregg.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# (http://www.gnu.org/copyleft/gpl.html)
#
# 20-Jul-2014 Brendan Gregg Created this.
tracing=/sys/kernel/debug/tracing
flock=/var/tmp/.ftrace-lock
opt_force=0; opt_quiet=0
function usage {
cat <<-END >&2
USAGE: reset-ftrace [-fhq]
-f # force: delete ftrace lock file
-q # quiet: reset, but say nothing
-h # this usage message
eg,
reset-ftrace # disable active ftrace session
END
exit
}
function warn {
if ! eval "$@"; then
echo >&2 "WARNING: command failed \"$@\""
fi
}
function die {
echo >&2 "$@"
exit 1
}
function vecho {
(( opt_quiet )) && return
echo "$@"
}
# write to file
function writefile {
file=$1
string=$2 # optional
if [[ ! -w $file ]]; then
echo >&2 "WARNING: file $file not writable/exists. Skipping."
return
fi
vecho "$file, before:"
(( ! opt_quiet )) && cat -n $file
warn "echo $string > $file"
vecho "$file, after:"
(( ! opt_quiet )) && cat -n $file
vecho
}
### process options
while getopts fhq opt
do
case $opt in
f) opt_force=1 ;;
q) opt_quiet=1 ;;
h|?) usage ;;
esac
done
shift $(( $OPTIND - 1 ))
### ftrace lock
if [[ -e $flock ]]; then
if (( opt_force )); then
warn rm $flock
else
echo -e >&2 "ERROR: ftrace lock ($flock) exists. It shows" \
"ftrace may be in use by PID $(cat $flock).\nDouble check" \
"to see if that PID is still active. If not, consider" \
"using -f to force a reset. Exiting."
exit 1
fi
fi
### reset ftrace state
vecho "Reseting ftrace state..."
vecho
cd $tracing || die "ERROR: accessing tracing. Root user? Kernel has FTRACE?"
writefile current_tracer nop
writefile set_ftrace_filter
writefile set_graph_function
writefile set_ftrace_pid
writefile events/enable 0
writefile tracing_thresh 0
writefile kprobe_events
writefile tracing_on 1
vecho "Done."
|