2 # SPDX-License-Identifier: GPL-2.0-only
5 echo "Ftrace boottime trace test tool"
6 echo "Usage: $0 [--apply|--init] [--debug] BOOTCONFIG-FILE"
7 echo " --apply: Test actual apply to tracefs (need sudo)"
8 echo " --init: Initialize ftrace before applying (imply --apply)"
18 while [ x
"$1" != x
]; do
34 if [ x
"$APPLY" != x
]; then
35 if [ `id -u` -ne 0 ]; then
36 echo "This must be run by root user. Try sudo." 1>&2
37 exec sudo
$0 $DEBUG $APPLY $BCONF
43 if [ x
"$APPLY" != x
]; then # apply command
48 if [ x
"$DEBUG" != x
]; then
52 TRACEFS
=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "`
53 if [ -z "$TRACEFS" ]; then
54 if ! grep -wq debugfs
/proc
/mounts
; then
55 echo "Error: No tracefs/debugfs was mounted." 1>&2
58 TRACEFS
=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing
59 if [ ! -d $TRACEFS ]; then
60 echo "Error: ftrace is not enabled on this kernel." 1>&2
65 if [ x
"$INIT" != x
]; then
66 .
`dirname $0`/ftrace.sh
67 (cd $TRACEFS; initialize_ftrace
)
72 ######## main #########
77 set_value_of
() { # key file
78 if xbc_has_key
$1; then
79 val
=`xbc_get_val $1 1`
80 run_cmd
"echo '$val' >> $2"
84 set_array_of
() { # key file
85 if xbc_has_key
$1; then
86 xbc_get_val
$1 |
while read line
; do
87 run_cmd
"echo '$line' >> $2"
92 compose_synth
() { # event_name branch
94 xbc_get_val
$2 |
while read field
; do echo -n "$field; "; done
97 setup_event
() { # prefix group event [instance]
100 eventdir
="$TRACEFS/instances/$4/events/$2/$3"
102 eventdir
="$TRACEFS/events/$2/$3"
106 xbc_get_val
${branch}.probes |
while read line
; do
107 run_cmd
"echo 'p:kprobes/$3 $line' >> $TRACEFS/kprobe_events"
111 run_cmd
"echo '`compose_synth $3 ${branch}.fields`' >> $TRACEFS/synthetic_events"
115 set_value_of
${branch}.filter
${eventdir}/filter
116 set_array_of
${branch}.actions
${eventdir}/trigger
118 if xbc_has_key
${branch}.
enable; then
119 run_cmd
"echo 1 > ${eventdir}/enable"
123 setup_events
() { # prefix("ftrace" or "ftrace.instance.INSTANCE") [instance]
125 if xbc_has_branch
${1}.event
; then
126 for grpev
in `xbc_subkeys ${1}.event 2`; do
127 setup_event
$prefix ${grpev%.*} ${grpev#*.} $2
132 size2kb
() { # size[KB|MB]
137 expr ${1%MB} \
* 1024;;
143 setup_instance
() { # [instance]
145 instance
="ftrace.instance.${1}"
146 instancedir
=$TRACEFS/instances
/$1
152 set_array_of
${instance}.options
${instancedir}/trace_options
153 set_value_of
${instance}.trace_clock
${instancedir}/trace_clock
154 set_value_of
${instance}.cpumask
${instancedir}/tracing_cpumask
155 set_value_of
${instance}.tracer
${instancedir}/current_tracer
156 set_array_of
${instance}.ftrace.filters \
157 ${instancedir}/set_ftrace_filter
158 set_array_of
${instance}.ftrace.notrace \
159 ${instancedir}/set_ftrace_notrace
161 if xbc_has_key
${instance}.alloc_snapshot
; then
162 run_cmd
"echo 1 > ${instancedir}/snapshot"
165 if xbc_has_key
${instance}.buffer_size
; then
166 size
=`xbc_get_val ${instance}.buffer_size 1`
167 size
=`eval size2kb $size`
168 run_cmd
"echo $size >> ${instancedir}/buffer_size_kb"
171 setup_events
${instance} $1
172 set_array_of
${instance}.events
${instancedir}/set_event
175 # ftrace global configs (kernel.*)
176 if xbc_has_key
"kernel.dump_on_oops"; then
177 dump_mode
=`xbc_get_val "kernel.dump_on_oops" 1`
178 [ "$dump_mode" ] && dump_mode
=`eval echo $dump_mode` || dump_mode
=1
179 run_cmd
"echo \"$dump_mode\" > /proc/sys/kernel/ftrace_dump_on_oops"
182 set_value_of kernel.fgraph_max_depth
$TRACEFS/max_graph_depth
183 set_array_of kernel.fgraph_filters
$TRACEFS/set_graph_function
184 set_array_of kernel.fgraph_notraces
$TRACEFS/set_graph_notrace
186 # Per-instance/per-event configs
187 if ! xbc_has_branch
"ftrace" ; then
191 setup_instance
# root instance
193 if xbc_has_branch
"ftrace.instance"; then
194 for i
in `xbc_subkeys "ftrace.instance" 1`; do
195 run_cmd
"mkdir -p $TRACEFS/instances/$i"