brintos

brintos / linux-shallow public Read only

0
0
Text · 5.8 KiB · 1603801 Raw
261 lines · bash
1#!/bin/sh2# SPDX-License-Identifier: GPL-2.0-only3 4usage() {5	echo "Dump boot-time tracing bootconfig from ftrace"6	echo "Usage: $0 [--debug] [ > BOOTCONFIG-FILE]"7	exit 18}9 10DEBUG=11while [ x"$1" != x ]; do12	case "$1" in13	"--debug")14		DEBUG=$1;;15	-*)16		usage17		;;18	esac19	shift 120done21 22if [ x"$DEBUG" != x ]; then23	set -x24fi25 26TRACEFS=`grep -m 1 -w tracefs /proc/mounts | cut -f 2 -d " "`27if [ -z "$TRACEFS" ]; then28	if ! grep -wq debugfs /proc/mounts; then29		echo "Error: No tracefs/debugfs was mounted."30		exit 131	fi32	TRACEFS=`grep -m 1 -w debugfs /proc/mounts | cut -f 2 -d " "`/tracing33	if [ ! -d $TRACEFS ]; then34		echo "Error: ftrace is not enabled on this kernel." 1>&235		exit 136	fi37fi38 39######## main #########40 41set -e42 43emit_kv() { # key =|+= value44	echo "$@"45}46 47global_options() {48	val=`cat $TRACEFS/max_graph_depth`49	[ $val != 0 ] && emit_kv kernel.fgraph_max_depth = $val50	if grep -qv "^#" $TRACEFS/set_graph_function $TRACEFS/set_graph_notrace ; then51		cat 1>&2 << EOF52# WARN: kernel.fgraph_filters and kernel.fgraph_notrace are not supported, since the wild card expression was expanded and lost from memory.53EOF54	fi55}56 57kprobe_event_options() {58	cat $TRACEFS/kprobe_events | while read p args; do59		case $p in60		r*)61		cat 1>&2 << EOF62# WARN: A return probe found but it is not supported by bootconfig. Skip it.63EOF64		continue;;65		esac66		p=${p#*:}67		event=${p#*/}68		group=${p%/*}69		if [ $group != "kprobes" ]; then70			cat 1>&2 << EOF71# WARN: kprobes group name $group is changed to "kprobes" for bootconfig.72EOF73		fi74		emit_kv $PREFIX.event.kprobes.$event.probes += $args75	done76}77 78synth_event_options() {79	cat $TRACEFS/synthetic_events | while read event fields; do80		emit_kv $PREFIX.event.synthetic.$event.fields = `echo $fields | sed "s/;/,/g"`81	done82}83 84# Variables resolver85DEFINED_VARS=86UNRESOLVED_EVENTS=87 88defined_vars() { # event-dir89	grep "^hist" $1/trigger | grep -o ':[a-zA-Z0-9]*='90}91referred_vars() {92	grep "^hist" $1/trigger | grep -o '$[a-zA-Z0-9]*'93}94 95event_is_enabled() { # enable-file96	test -f $1 && grep -q "1" $197}98 99per_event_options() { # event-dir100	evdir=$1101	# Check the special event which has no filter and no trigger102	[ ! -f $evdir/filter ] && return103 104	if grep -q "^hist:" $evdir/trigger; then105		# hist action can refer the undefined variables106		__vars=`defined_vars $evdir`107		for v in `referred_vars $evdir`; do108			if echo $DEFINED_VARS $__vars | grep -vqw ${v#$}; then109				# $v is not defined yet, defer it110				UNRESOLVED_EVENTS="$UNRESOLVED_EVENTS $evdir"111				return;112			fi113		done114		DEFINED_VARS="$DEFINED_VARS "`defined_vars $evdir`115	fi116	grep -v "^#" $evdir/trigger | while read action active; do117		emit_kv $PREFIX.event.$group.$event.actions += \'$action\'118	done119 120	if [ $GROUP_ENABLED -eq 0 ] && event_is_enabled $evdir/enable; then121		emit_kv $PREFIX.event.$group.$event.enable122	fi123	val=`cat $evdir/filter`124	if [ "$val" != "none" ]; then125		emit_kv $PREFIX.event.$group.$event.filter = "$val"126	fi127}128 129retry_unresolved() {130	unresolved=$UNRESOLVED_EVENTS131	UNRESOLVED_EVENTS=132	for evdir in $unresolved; do133		event=${evdir##*/}134		group=${evdir%/*}; group=${group##*/}135		per_event_options $evdir136	done137}138 139event_options() {140	# PREFIX and INSTANCE must be set141	if [ $PREFIX = "ftrace" ]; then142		# define the dynamic events143		kprobe_event_options144		synth_event_options145	fi146	ALL_ENABLED=0147	if event_is_enabled $INSTANCE/events/enable; then148		emit_kv $PREFIX.event.enable149		ALL_ENABLED=1150	fi151	for group in `ls $INSTANCE/events/` ; do152		[ ! -d $INSTANCE/events/$group ] && continue153		GROUP_ENABLED=$ALL_ENABLED154		if [ $ALL_ENABLED -eq 0 ] && \155		   event_is_enabled $INSTANCE/events/$group/enable ;then156			emit_kv $PREFIX.event.$group.enable157			GROUP_ENABLED=1158		fi159		for event in `ls $INSTANCE/events/$group/` ;do160			[ ! -d $INSTANCE/events/$group/$event ] && continue161			per_event_options $INSTANCE/events/$group/$event162		done163	done164	retry=0165	while [ $retry -lt 3 ]; do166		retry_unresolved167		retry=$((retry + 1))168	done169	if [ "$UNRESOLVED_EVENTS" ]; then170		cat 1>&2 << EOF171! ERROR: hist triggers in $UNRESOLVED_EVENTS use some undefined variables.172EOF173	fi174}175 176is_default_trace_option() { # option177grep -qw $1 << EOF178print-parent179nosym-offset180nosym-addr181noverbose182noraw183nohex184nobin185noblock186trace_printk187annotate188nouserstacktrace189nosym-userobj190noprintk-msg-only191context-info192nolatency-format193record-cmd194norecord-tgid195overwrite196nodisable_on_free197irq-info198markers199noevent-fork200nopause-on-trace201function-trace202nofunction-fork203nodisplay-graph204nostacktrace205notest_nop_accept206notest_nop_refuse207EOF208}209 210instance_options() { # [instance-name]211	if [ $# -eq 0 ]; then212		PREFIX="ftrace"213		INSTANCE=$TRACEFS214	else215		PREFIX="ftrace.instance.$1"216		INSTANCE=$TRACEFS/instances/$1217	fi218	val=219	for i in `cat $INSTANCE/trace_options`; do220		is_default_trace_option $i && continue221		val="$val, $i"222	done223	[ "$val" ] && emit_kv $PREFIX.options = "${val#,}"224	val="local"225	for i in `cat $INSTANCE/trace_clock` ; do226		[ "${i#*]}" ] && continue227		i=${i%]}; val=${i#[}228	done229	[ $val != "local" ] && emit_kv $PREFIX.trace_clock = $val230	val=`cat $INSTANCE/buffer_size_kb`231	if echo $val | grep -vq "expanded" ; then232		emit_kv $PREFIX.buffer_size = $val"KB"233	fi234	if grep -q "is allocated" $INSTANCE/snapshot ; then235		emit_kv $PREFIX.alloc_snapshot236	fi237	val=`cat $INSTANCE/tracing_cpumask`238	if [ `echo $val | sed -e s/f//g`x != x ]; then239		emit_kv $PREFIX.cpumask = $val240	fi241	val=`cat $INSTANCE/tracing_on`242	if [ "$val" = "0" ]; then243		emit_kv $PREFIX.tracing_on = 0244	fi245 246	val=`cat $INSTANCE/current_tracer`247	[ $val != nop ] && emit_kv $PREFIX.tracer = $val248	if grep -qv "^#" $INSTANCE/set_ftrace_filter $INSTANCE/set_ftrace_notrace; then249		cat 1>&2 << EOF250# WARN: kernel.ftrace.filters and kernel.ftrace.notrace are not supported, since the wild card expression was expanded and lost from memory.251EOF252	fi253	event_options254}255 256global_options257instance_options258for i in `ls $TRACEFS/instances` ; do259	instance_options $i260done261