Path: blob/master/tools/bootconfig/scripts/bconf2ftrace.sh
26288 views
#!/bin/sh1# SPDX-License-Identifier: GPL-2.0-only23usage() {4echo "Ftrace boottime trace test tool"5echo "Usage: $0 [--apply|--init] [--debug] BOOTCONFIG-FILE"6echo " --apply: Test actual apply to tracefs (need sudo)"7echo " --init: Initialize ftrace before applying (imply --apply)"8exit 19}1011[ $# -eq 0 ] && usage1213BCONF=14DEBUG=15APPLY=16INIT=17while [ x"$1" != x ]; do18case "$1" in19"--debug")20DEBUG=$1;;21"--apply")22APPLY=$1;;23"--init")24APPLY=$125INIT=$1;;26*)27[ ! -f $1 ] && usage28BCONF=$1;;29esac30shift 131done3233if [ x"$APPLY" != x ]; then34if [ `id -u` -ne 0 ]; then35echo "This must be run by root user. Try sudo." 1>&236exec sudo $0 $DEBUG $APPLY $BCONF37fi38fi3940run_cmd() { # command41echo "$*"42if [ x"$APPLY" != x ]; then # apply command43eval $*44fi45}4647if [ x"$DEBUG" != x ]; then48set -x49fi5051TRACEFS=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "`52if [ -z "$TRACEFS" ]; then53if ! grep -wq debugfs /proc/mounts; then54echo "Error: No tracefs/debugfs was mounted." 1>&255exit 156fi57TRACEFS=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing58if [ ! -d $TRACEFS ]; then59echo "Error: ftrace is not enabled on this kernel." 1>&260exit 161fi62fi6364if [ x"$INIT" != x ]; then65. `dirname $0`/ftrace.sh66(cd $TRACEFS; initialize_ftrace)67fi6869. `dirname $0`/xbc.sh7071######## main #########72set -e7374xbc_init $BCONF7576set_value_of() { # key file77if xbc_has_key $1; then78val=`xbc_get_val $1 1`79run_cmd "echo '$val' >> $2"80fi81}8283set_array_of() { # key file84if xbc_has_key $1; then85xbc_get_val $1 | while read line; do86run_cmd "echo '$line' >> $2"87done88fi89}9091compose_synth() { # event_name branch92echo -n "$1 "93xbc_get_val $2 | while read field; do echo -n "$field; "; done94}9596print_hist_array() { # prefix key97__sep="="98if xbc_has_key ${1}.${2}; then99echo -n ":$2"100xbc_get_val ${1}.${2} | while read field; do101echo -n "$__sep$field"; __sep=","102done103fi104}105106print_hist_action_array() { # prefix key107__sep="("108echo -n ".$2"109xbc_get_val ${1}.${2} | while read field; do110echo -n "$__sep$field"; __sep=","111done112echo -n ")"113}114115print_hist_one_action() { # prefix handler param116echo -n ":${2}("`xbc_get_val ${1}.${3}`")"117if xbc_has_key "${1}.trace"; then118print_hist_action_array ${1} "trace"119elif xbc_has_key "${1}.save"; then120print_hist_action_array ${1} "save"121elif xbc_has_key "${1}.snapshot"; then122echo -n ".snapshot()"123fi124}125126print_hist_actions() { # prefix handler param127for __hdr in `xbc_subkeys ${1}.${2} 1 ".[0-9]"`; do128print_hist_one_action ${1}.${2}.$__hdr ${2} ${3}129done130if xbc_has_key ${1}.${2}.${3} ; then131print_hist_one_action ${1}.${2} ${2} ${3}132fi133}134135print_hist_var() { # prefix varname136echo -n ":${2}="`xbc_get_val ${1}.var.${2} | tr -d [:space:]`137}138139print_one_histogram() { # prefix140echo -n "hist"141print_hist_array $1 "keys"142print_hist_array $1 "values"143print_hist_array $1 "sort"144if xbc_has_key "${1}.size"; then145echo -n ":size="`xbc_get_val ${1}.size`146fi147if xbc_has_key "${1}.name"; then148echo -n ":name="`xbc_get_val ${1}.name`149fi150for __var in `xbc_subkeys "${1}.var" 1`; do151print_hist_var ${1} ${__var}152done153if xbc_has_key "${1}.pause"; then154echo -n ":pause"155elif xbc_has_key "${1}.continue"; then156echo -n ":continue"157elif xbc_has_key "${1}.clear"; then158echo -n ":clear"159fi160print_hist_actions ${1} "onmax" "var"161print_hist_actions ${1} "onchange" "var"162print_hist_actions ${1} "onmatch" "event"163164if xbc_has_key "${1}.filter"; then165echo -n " if "`xbc_get_val ${1}.filter`166fi167}168169setup_one_histogram() { # prefix trigger-file170run_cmd "echo '`print_one_histogram ${1}`' >> ${2}"171}172173setup_histograms() { # prefix trigger-file174for __hist in `xbc_subkeys ${1} 1 ".[0-9]"`; do175setup_one_histogram ${1}.$__hist ${2}176done177if xbc_has_key ${1}.keys; then178setup_one_histogram ${1} ${2}179fi180}181182setup_event() { # prefix group event [instance]183branch=$1.$2.$3184if [ "$4" ]; then185eventdir="$TRACEFS/instances/$4/events/$2/$3"186else187eventdir="$TRACEFS/events/$2/$3"188fi189# group enable190if [ "$3" = "enable" ]; then191run_cmd "echo 1 > ${eventdir}"192return193fi194195case $2 in196kprobes)197xbc_get_val ${branch}.probes | while read line; do198run_cmd "echo 'p:kprobes/$3 $line' >> $TRACEFS/kprobe_events"199done200;;201synthetic)202run_cmd "echo '`compose_synth $3 ${branch}.fields`' >> $TRACEFS/synthetic_events"203;;204esac205206set_value_of ${branch}.filter ${eventdir}/filter207set_array_of ${branch}.actions ${eventdir}/trigger208209setup_histograms ${branch}.hist ${eventdir}/trigger210211if xbc_has_key ${branch}.enable; then212run_cmd "echo 1 > ${eventdir}/enable"213fi214}215216setup_events() { # prefix("ftrace" or "ftrace.instance.INSTANCE") [instance]217prefix="${1}.event"218if xbc_has_branch ${1}.event; then219for grpev in `xbc_subkeys ${1}.event 2`; do220setup_event $prefix ${grpev%.*} ${grpev#*.} $2221done222fi223if xbc_has_branch ${1}.event.enable; then224if [ "$2" ]; then225run_cmd "echo 1 > $TRACEFS/instances/$2/events/enable"226else227run_cmd "echo 1 > $TRACEFS/events/enable"228fi229fi230}231232size2kb() { # size[KB|MB]233case $1 in234*KB)235echo ${1%KB};;236*MB)237expr ${1%MB} \* 1024;;238*)239expr $1 / 1024 ;;240esac241}242243setup_instance() { # [instance]244if [ "$1" ]; then245instance="ftrace.instance.${1}"246instancedir=$TRACEFS/instances/$1247else248instance="ftrace"249instancedir=$TRACEFS250fi251252set_array_of ${instance}.options ${instancedir}/trace_options253set_value_of ${instance}.trace_clock ${instancedir}/trace_clock254set_value_of ${instance}.cpumask ${instancedir}/tracing_cpumask255set_value_of ${instance}.tracing_on ${instancedir}/tracing_on256set_value_of ${instance}.tracer ${instancedir}/current_tracer257set_array_of ${instance}.ftrace.filters \258${instancedir}/set_ftrace_filter259set_array_of ${instance}.ftrace.notrace \260${instancedir}/set_ftrace_notrace261262if xbc_has_key ${instance}.alloc_snapshot; then263run_cmd "echo 1 > ${instancedir}/snapshot"264fi265266if xbc_has_key ${instance}.buffer_size; then267size=`xbc_get_val ${instance}.buffer_size 1`268size=`eval size2kb $size`269run_cmd "echo $size >> ${instancedir}/buffer_size_kb"270fi271272setup_events ${instance} $1273set_array_of ${instance}.events ${instancedir}/set_event274}275276# ftrace global configs (kernel.*)277if xbc_has_key "kernel.dump_on_oops"; then278dump_mode=`xbc_get_val "kernel.dump_on_oops" 1`279[ "$dump_mode" ] && dump_mode=`eval echo $dump_mode` || dump_mode=1280run_cmd "echo \"$dump_mode\" > /proc/sys/kernel/ftrace_dump_on_oops"281fi282283set_value_of kernel.fgraph_max_depth $TRACEFS/max_graph_depth284set_array_of kernel.fgraph_filters $TRACEFS/set_graph_function285set_array_of kernel.fgraph_notraces $TRACEFS/set_graph_notrace286287# Per-instance/per-event configs288if ! xbc_has_branch "ftrace" ; then289exit 0290fi291292setup_instance # root instance293294if xbc_has_branch "ftrace.instance"; then295for i in `xbc_subkeys "ftrace.instance" 1`; do296run_cmd "mkdir -p $TRACEFS/instances/$i"297setup_instance $i298done299fi300301302303