Path: blob/master/tools/bootconfig/scripts/ftrace2bconf.sh
26288 views
#!/bin/sh1# SPDX-License-Identifier: GPL-2.0-only23usage() {4echo "Dump boot-time tracing bootconfig from ftrace"5echo "Usage: $0 [--debug] [ > BOOTCONFIG-FILE]"6exit 17}89DEBUG=10while [ x"$1" != x ]; do11case "$1" in12"--debug")13DEBUG=$1;;14-*)15usage16;;17esac18shift 119done2021if [ x"$DEBUG" != x ]; then22set -x23fi2425TRACEFS=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "`26if [ -z "$TRACEFS" ]; then27if ! grep -wq debugfs /proc/mounts; then28echo "Error: No tracefs/debugfs was mounted."29exit 130fi31TRACEFS=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing32if [ ! -d $TRACEFS ]; then33echo "Error: ftrace is not enabled on this kernel." 1>&234exit 135fi36fi3738######## main #########3940set -e4142emit_kv() { # key =|+= value43echo "$@"44}4546global_options() {47val=`cat $TRACEFS/max_graph_depth`48[ $val != 0 ] && emit_kv kernel.fgraph_max_depth = $val49if grep -qv "^#" $TRACEFS/set_graph_function $TRACEFS/set_graph_notrace ; then50cat 1>&2 << EOF51# WARN: kernel.fgraph_filters and kernel.fgraph_notrace are not supported, since the wild card expression was expanded and lost from memory.52EOF53fi54}5556kprobe_event_options() {57cat $TRACEFS/kprobe_events | while read p args; do58case $p in59r*)60cat 1>&2 << EOF61# WARN: A return probe found but it is not supported by bootconfig. Skip it.62EOF63continue;;64esac65p=${p#*:}66event=${p#*/}67group=${p%/*}68if [ $group != "kprobes" ]; then69cat 1>&2 << EOF70# WARN: kprobes group name $group is changed to "kprobes" for bootconfig.71EOF72fi73emit_kv $PREFIX.event.kprobes.$event.probes += $args74done75}7677synth_event_options() {78cat $TRACEFS/synthetic_events | while read event fields; do79emit_kv $PREFIX.event.synthetic.$event.fields = `echo $fields | sed "s/;/,/g"`80done81}8283# Variables resolver84DEFINED_VARS=85UNRESOLVED_EVENTS=8687defined_vars() { # event-dir88grep "^hist" $1/trigger | grep -o ':[a-zA-Z0-9]*='89}90referred_vars() {91grep "^hist" $1/trigger | grep -o '$[a-zA-Z0-9]*'92}9394event_is_enabled() { # enable-file95test -f $1 && grep -q "1" $196}9798per_event_options() { # event-dir99evdir=$1100# Check the special event which has no filter and no trigger101[ ! -f $evdir/filter ] && return102103if grep -q "^hist:" $evdir/trigger; then104# hist action can refer the undefined variables105__vars=`defined_vars $evdir`106for v in `referred_vars $evdir`; do107if echo $DEFINED_VARS $__vars | grep -vqw ${v#$}; then108# $v is not defined yet, defer it109UNRESOLVED_EVENTS="$UNRESOLVED_EVENTS $evdir"110return;111fi112done113DEFINED_VARS="$DEFINED_VARS "`defined_vars $evdir`114fi115grep -v "^#" $evdir/trigger | while read action active; do116emit_kv $PREFIX.event.$group.$event.actions += \'$action\'117done118119if [ $GROUP_ENABLED -eq 0 ] && event_is_enabled $evdir/enable; then120emit_kv $PREFIX.event.$group.$event.enable121fi122val=`cat $evdir/filter`123if [ "$val" != "none" ]; then124emit_kv $PREFIX.event.$group.$event.filter = "$val"125fi126}127128retry_unresolved() {129unresolved=$UNRESOLVED_EVENTS130UNRESOLVED_EVENTS=131for evdir in $unresolved; do132event=${evdir##*/}133group=${evdir%/*}; group=${group##*/}134per_event_options $evdir135done136}137138event_options() {139# PREFIX and INSTANCE must be set140if [ $PREFIX = "ftrace" ]; then141# define the dynamic events142kprobe_event_options143synth_event_options144fi145ALL_ENABLED=0146if event_is_enabled $INSTANCE/events/enable; then147emit_kv $PREFIX.event.enable148ALL_ENABLED=1149fi150for group in `ls $INSTANCE/events/` ; do151[ ! -d $INSTANCE/events/$group ] && continue152GROUP_ENABLED=$ALL_ENABLED153if [ $ALL_ENABLED -eq 0 ] && \154event_is_enabled $INSTANCE/events/$group/enable ;then155emit_kv $PREFIX.event.$group.enable156GROUP_ENABLED=1157fi158for event in `ls $INSTANCE/events/$group/` ;do159[ ! -d $INSTANCE/events/$group/$event ] && continue160per_event_options $INSTANCE/events/$group/$event161done162done163retry=0164while [ $retry -lt 3 ]; do165retry_unresolved166retry=$((retry + 1))167done168if [ "$UNRESOLVED_EVENTS" ]; then169cat 1>&2 << EOF170! ERROR: hist triggers in $UNRESOLVED_EVENTS use some undefined variables.171EOF172fi173}174175is_default_trace_option() { # option176grep -qw $1 << EOF177print-parent178nosym-offset179nosym-addr180noverbose181noraw182nohex183nobin184noblock185trace_printk186annotate187nouserstacktrace188nosym-userobj189noprintk-msg-only190context-info191nolatency-format192record-cmd193norecord-tgid194overwrite195nodisable_on_free196irq-info197markers198noevent-fork199nopause-on-trace200function-trace201nofunction-fork202nodisplay-graph203nostacktrace204notest_nop_accept205notest_nop_refuse206EOF207}208209instance_options() { # [instance-name]210if [ $# -eq 0 ]; then211PREFIX="ftrace"212INSTANCE=$TRACEFS213else214PREFIX="ftrace.instance.$1"215INSTANCE=$TRACEFS/instances/$1216fi217val=218for i in `cat $INSTANCE/trace_options`; do219is_default_trace_option $i && continue220val="$val, $i"221done222[ "$val" ] && emit_kv $PREFIX.options = "${val#,}"223val="local"224for i in `cat $INSTANCE/trace_clock` ; do225[ "${i#*]}" ] && continue226i=${i%]}; val=${i#[}227done228[ $val != "local" ] && emit_kv $PREFIX.trace_clock = $val229val=`cat $INSTANCE/buffer_size_kb`230if echo $val | grep -vq "expanded" ; then231emit_kv $PREFIX.buffer_size = $val"KB"232fi233if grep -q "is allocated" $INSTANCE/snapshot ; then234emit_kv $PREFIX.alloc_snapshot235fi236val=`cat $INSTANCE/tracing_cpumask`237if [ `echo $val | sed -e s/f//g`x != x ]; then238emit_kv $PREFIX.cpumask = $val239fi240val=`cat $INSTANCE/tracing_on`241if [ "$val" = "0" ]; then242emit_kv $PREFIX.tracing_on = 0243fi244245val=`cat $INSTANCE/current_tracer`246[ $val != nop ] && emit_kv $PREFIX.tracer = $val247if grep -qv "^#" $INSTANCE/set_ftrace_filter $INSTANCE/set_ftrace_notrace; then248cat 1>&2 << EOF249# WARN: kernel.ftrace.filters and kernel.ftrace.notrace are not supported, since the wild card expression was expanded and lost from memory.250EOF251fi252event_options253}254255global_options256instance_options257for i in `ls $TRACEFS/instances` ; do258instance_options $i259done260261262