1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 # 4 # Here's how to use this: 5 # 6 # This script is used to help find functions t 7 # tracer or function graph tracing that causes 8 # crash. Here's the steps to take. 9 # 10 # First, determine if function tracing is work 11 # 12 # (note, if this is a problem with function_ 13 # replace "function" with "function_graph" 14 # 15 # # cd /sys/kernel/tracing 16 # # echo schedule > set_ftrace_filter 17 # # echo function > current_tracer 18 # 19 # If this works, then we know that something i 20 # 21 # # echo nop > current_tracer 22 # 23 # Starting with v5.1 this can be done with num 24 # 25 # The old (slow) way, for kernels before v5.1. 26 # 27 # [old-way] # cat available_filter_functions > 28 # 29 # [old-way] *** Note *** this process will ta 30 # [old-way] filters. Setting multiple function 31 # [old-way] are dealing with thousands of func 32 # [old-way] with your coworkers, read facebook 33 # [old-way] will end. 34 # 35 # The new way (using numbers) is an O(n) opera 36 # 37 # seq `wc -l available_filter_functions | cut 38 # 39 # This will create a sequence of numbers that 40 # available_filter_functions, and when echoing 41 # set_ftrace_filter file, it will enable the c 42 # O(1) time. Making enabling all functions O(n 43 # functions to enable. 44 # 45 # For either the new or old way, the rest of t 46 # 47 # # ftrace-bisect ~/full-file ~/test-file ~/n 48 # # cat ~/test-file > set_ftrace_filter 49 # 50 # # echo function > current_tracer 51 # 52 # If it crashes, we know that ~/test-file has 53 # 54 # Reboot back to test kernel. 55 # 56 # # cd /sys/kernel/tracing 57 # # mv ~/test-file ~/full-file 58 # 59 # If it didn't crash. 60 # 61 # # echo nop > current_tracer 62 # # mv ~/non-test-file ~/full-file 63 # 64 # Get rid of the other test file from previous 65 # # rm -f ~/test-file ~/non-test-file 66 # 67 # And start again: 68 # 69 # # ftrace-bisect ~/full-file ~/test-file ~/n 70 # 71 # The good thing is, because this cuts the num 72 # by half, the cat of it into set_ftrace_filte 73 # iteration, so don't talk so much at the wate 74 # 75 # Eventually, if you did this correctly, you w 76 # function, and all we need to do is to notrac 77 # 78 # The way to figure out if the problem functio 79 # 80 # # echo <problem-function> > set_ftrace_notr 81 # # echo > set_ftrace_filter 82 # # echo function > current_tracer 83 # 84 # And if it doesn't crash, we are done. 85 # 86 # If it does crash, do this again (there's mor 87 # but you need to echo the problem function(s) 88 # enabling function tracing in the above steps 89 # kernel, annotate the problem functions with 90 # 91 92 93 if [ $# -ne 3 ]; then 94 echo 'usage: ftrace-bisect full-file test-fi 95 exit 96 fi 97 98 full=$1 99 test=$2 100 nontest=$3 101 102 x=`cat $full | wc -l` 103 if [ $x -eq 1 ]; then 104 echo "There's only one function left, 105 cat $full 106 exit 0 107 fi 108 109 let x=$x/2 110 let y=$x+1 111 112 if [ ! -f $full ]; then 113 echo "$full does not exist" 114 exit 1 115 fi 116 117 if [ -f $test ]; then 118 echo -n "$test exists, delete it? [y/N 119 read a 120 if [ "$a" != "y" -a "$a" != "Y" ]; the 121 exit 1 122 fi 123 fi 124 125 if [ -f $nontest ]; then 126 echo -n "$nontest exists, delete it? [ 127 read a 128 if [ "$a" != "y" -a "$a" != "Y" ]; the 129 exit 1 130 fi 131 fi 132 133 sed -ne "1,${x}p" $full > $test 134 sed -ne "$y,\$p" $full > $nontest
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.