110 lines · bash
1# SPDX-License-Identifier: GPL-2.0-only2 3clear_trace() { # reset trace output4 echo > trace5}6 7disable_tracing() { # stop trace recording8 echo 0 > tracing_on9}10 11enable_tracing() { # start trace recording12 echo 1 > tracing_on13}14 15reset_tracer() { # reset the current tracer16 echo nop > current_tracer17}18 19reset_trigger_file() {20 # remove action triggers first21 grep -H ':on[^:]*(' $@ |22 while read line; do23 cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`24 file=`echo $line | cut -f1 -d:`25 echo "!$cmd" >> $file26 done27 grep -Hv ^# $@ |28 while read line; do29 cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`30 file=`echo $line | cut -f1 -d:`31 echo "!$cmd" > $file32 done33}34 35reset_trigger() { # reset all current setting triggers36 if [ -d events/synthetic ]; then37 reset_trigger_file events/synthetic/*/trigger38 fi39 reset_trigger_file events/*/*/trigger40}41 42reset_events_filter() { # reset all current setting filters43 grep -v ^none events/*/*/filter |44 while read line; do45 echo 0 > `echo $line | cut -f1 -d:`46 done47}48 49reset_ftrace_filter() { # reset all triggers in set_ftrace_filter50 if [ ! -f set_ftrace_filter ]; then51 return 052 fi53 echo > set_ftrace_filter54 grep -v '^#' set_ftrace_filter | while read t; do55 tr=`echo $t | cut -d: -f2`56 if [ "$tr" = "" ]; then57 continue58 fi59 if ! grep -q "$t" set_ftrace_filter; then60 continue;61 fi62 name=`echo $t | cut -d: -f1 | cut -d' ' -f1`63 if [ $tr = "enable_event" -o $tr = "disable_event" ]; then64 tr=`echo $t | cut -d: -f2-4`65 limit=`echo $t | cut -d: -f5`66 else67 tr=`echo $t | cut -d: -f2`68 limit=`echo $t | cut -d: -f3`69 fi70 if [ "$limit" != "unlimited" ]; then71 tr="$tr:$limit"72 fi73 echo "!$name:$tr" > set_ftrace_filter74 done75}76 77disable_events() {78 echo 0 > events/enable79}80 81clear_synthetic_events() { # reset all current synthetic events82 grep -v ^# synthetic_events |83 while read line; do84 echo "!$line" >> synthetic_events85 done86}87 88initialize_ftrace() { # Reset ftrace to initial-state89# As the initial state, ftrace will be set to nop tracer,90# no events, no triggers, no filters, no function filters,91# no probes, and tracing on.92 disable_tracing93 reset_tracer94 reset_trigger95 reset_events_filter96 reset_ftrace_filter97 disable_events98 [ -f set_event_pid ] && echo > set_event_pid99 [ -f set_ftrace_pid ] && echo > set_ftrace_pid100 [ -f set_ftrace_notrace ] && echo > set_ftrace_notrace101 [ -f set_graph_function ] && echo | tee set_graph_*102 [ -f stack_trace_filter ] && echo > stack_trace_filter103 [ -f kprobe_events ] && echo > kprobe_events104 [ -f uprobe_events ] && echo > uprobe_events105 [ -f synthetic_events ] && echo > synthetic_events106 [ -f snapshot ] && echo 0 > snapshot107 clear_trace108 enable_tracing109}110