WIP FPC-III support
[linux/fpc-iii.git] / tools / bootconfig / scripts / bconf2ftrace.sh
blob595e164dc352f08d97125f04e49efd89e9281811
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0-only
4 usage() {
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)"
9 exit 1
12 [ $# -eq 0 ] && usage
14 BCONF=
15 DEBUG=
16 APPLY=
17 INIT=
18 while [ x"$1" != x ]; do
19 case "$1" in
20 "--debug")
21 DEBUG=$1;;
22 "--apply")
23 APPLY=$1;;
24 "--init")
25 APPLY=$1
26 INIT=$1;;
28 [ ! -f $1 ] && usage
29 BCONF=$1;;
30 esac
31 shift 1
32 done
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
41 run_cmd() { # command
42 echo "$*"
43 if [ x"$APPLY" != x ]; then # apply command
44 eval $*
48 if [ x"$DEBUG" != x ]; then
49 set -x
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
56 exit 1
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
61 exit 1
65 if [ x"$INIT" != x ]; then
66 . `dirname $0`/ftrace.sh
67 (cd $TRACEFS; initialize_ftrace)
70 . `dirname $0`/xbc.sh
72 ######## main #########
73 set -e
75 xbc_init $BCONF
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"
88 done
92 compose_synth() { # event_name branch
93 echo -n "$1 "
94 xbc_get_val $2 | while read field; do echo -n "$field; "; done
97 setup_event() { # prefix group event [instance]
98 branch=$1.$2.$3
99 if [ "$4" ]; then
100 eventdir="$TRACEFS/instances/$4/events/$2/$3"
101 else
102 eventdir="$TRACEFS/events/$2/$3"
104 case $2 in
105 kprobes)
106 xbc_get_val ${branch}.probes | while read line; do
107 run_cmd "echo 'p:kprobes/$3 $line' >> $TRACEFS/kprobe_events"
108 done
110 synthetic)
111 run_cmd "echo '`compose_synth $3 ${branch}.fields`' >> $TRACEFS/synthetic_events"
113 esac
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]
124 prefix="${1}.event"
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
128 done
132 size2kb() { # size[KB|MB]
133 case $1 in
134 *KB)
135 echo ${1%KB};;
136 *MB)
137 expr ${1%MB} \* 1024;;
139 expr $1 / 1024 ;;
140 esac
143 setup_instance() { # [instance]
144 if [ "$1" ]; then
145 instance="ftrace.instance.${1}"
146 instancedir=$TRACEFS/instances/$1
147 else
148 instance="ftrace"
149 instancedir=$TRACEFS
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
188 exit 0
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"
196 setup_instance $i
197 done