2 # SPDX-License-Identifier: GPL-2.0-only
5 echo "Ftrace boottime trace test tool"
6 echo "Usage: $0 [--apply] [--debug] BOOTCONFIG-FILE"
7 echo " --apply: Test actual apply to tracefs (need sudo)"
16 while [ x"$1" != x ]; do
29 if [ x"$APPLY" != x ]; then
30 if [ `id -u` -ne 0 ]; then
31 echo "This must be run by root user. Try sudo." 1>&2
32 exec sudo $0 $DEBUG $APPLY $BCONF
38 if [ x"$APPLY" != x ]; then # apply command
43 if [ x"$DEBUG" != x ]; then
47 TRACEFS=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "`
48 if [ -z "$TRACEFS" ]; then
49 if ! grep -wq debugfs /proc/mounts; then
50 echo "Error: No tracefs/debugfs was mounted." 1>&2
53 TRACEFS=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing
54 if [ ! -d $TRACEFS ]; then
55 echo "Error: ftrace is not enabled on this kernel." 1>&2
62 ######## main #########
67 set_value_of() { # key file
68 if xbc_has_key $1; then
69 val=`xbc_get_val $1 1`
70 run_cmd "echo '$val' >> $2"
74 set_array_of() { # key file
75 if xbc_has_key $1; then
76 xbc_get_val $1 | while read line; do
77 run_cmd "echo '$line' >> $2"
82 compose_synth() { # event_name branch
84 xbc_get_val $2 | while read field; do echo -n "$field; "; done
87 setup_event() { # prefix group event [instance]
90 eventdir="$TRACEFS/instances/$4/events/$2/$3"
92 eventdir="$TRACEFS/events/$2/$3"
96 xbc_get_val ${branch}.probes | while read line; do
97 run_cmd "echo 'p:kprobes/$3 $line' >> $TRACEFS/kprobe_events"
101 run_cmd "echo '`compose_synth $3 ${branch}.fields`' >> $TRACEFS/synthetic_events"
105 set_value_of ${branch}.filter ${eventdir}/filter
106 set_array_of ${branch}.actions ${eventdir}/trigger
108 if xbc_has_key ${branch}.enable; then
109 run_cmd "echo 1 > ${eventdir}/enable"
113 setup_events() { # prefix("ftrace" or "ftrace.instance.INSTANCE") [instance]
115 if xbc_has_branch ${1}.event; then
116 for grpev in `xbc_subkeys ${1}.event 2`; do
117 setup_event $prefix ${grpev%.*} ${grpev#*.} $2
122 size2kb() { # size[KB|MB]
127 expr ${1%MB} \* 1024;;
133 setup_instance() { # [instance]
135 instance="ftrace.instance.${1}"
136 instancedir=$TRACEFS/instances/$1
142 set_array_of ${instance}.options ${instancedir}/trace_options
143 set_value_of ${instance}.trace_clock ${instancedir}/trace_clock
144 set_value_of ${instance}.cpumask ${instancedir}/tracing_cpumask
145 set_value_of ${instance}.tracer ${instancedir}/current_tracer
146 set_array_of ${instance}.ftrace.filters \
147 ${instancedir}/set_ftrace_filter
148 set_array_of ${instance}.ftrace.notrace \
149 ${instancedir}/set_ftrace_notrace
151 if xbc_has_key ${instance}.alloc_snapshot; then
152 run_cmd "echo 1 > ${instancedir}/snapshot"
155 if xbc_has_key ${instance}.buffer_size; then
156 size=`xbc_get_val ${instance}.buffer_size 1`
157 size=`eval size2kb $size`
158 run_cmd "echo $size >> ${instancedir}/buffer_size_kb"
161 setup_events ${instance} $1
162 set_array_of ${instance}.events ${instancedir}/set_event
165 # ftrace global configs (kernel.*)
166 if xbc_has_key "kernel.dump_on_oops"; then
167 dump_mode=`xbc_get_val "kernel.dump_on_oops" 1`
168 [ "$dump_mode" ] && dump_mode=`eval echo $dump_mode` || dump_mode=1
169 run_cmd "echo \"$dump_mode\" > /proc/sys/kernel/ftrace_dump_on_oops"
172 set_value_of kernel.fgraph_max_depth $TRACEFS/max_graph_depth
173 set_array_of kernel.fgraph_filters $TRACEFS/set_graph_function
174 set_array_of kernel.fgraph_notraces $TRACEFS/set_graph_notrace
176 # Per-instance/per-event configs
177 if ! xbc_has_branch "ftrace" ; then
181 setup_instance # root instance
183 if xbc_has_branch "ftrace.instance"; then
184 for i in `xbc_subkeys "ftrace.instance" 1`; do
185 run_cmd "mkdir -p $TRACEFS/instances/$i"