ftrace-bisect.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. #
  3. # Here's how to use this:
  4. #
  5. # This script is used to help find functions that are being traced by function
  6. # tracer or function graph tracing that causes the machine to reboot, hang, or
  7. # crash. Here's the steps to take.
  8. #
  9. # First, determine if function tracing is working with a single function:
  10. #
  11. # (note, if this is a problem with function_graph tracing, then simply
  12. # replace "function" with "function_graph" in the following steps).
  13. #
  14. # # cd /sys/kernel/debug/tracing
  15. # # echo schedule > set_ftrace_filter
  16. # # echo function > current_tracer
  17. #
  18. # If this works, then we know that something is being traced that shouldn't be.
  19. #
  20. # # echo nop > current_tracer
  21. #
  22. # # cat available_filter_functions > ~/full-file
  23. # # ftrace-bisect ~/full-file ~/test-file ~/non-test-file
  24. # # cat ~/test-file > set_ftrace_filter
  25. #
  26. # *** Note *** this will take several minutes. Setting multiple functions is
  27. # an O(n^2) operation, and we are dealing with thousands of functions. So go
  28. # have coffee, talk with your coworkers, read facebook. And eventually, this
  29. # operation will end.
  30. #
  31. # # echo function > current_tracer
  32. #
  33. # If it crashes, we know that ~/test-file has a bad function.
  34. #
  35. # Reboot back to test kernel.
  36. #
  37. # # cd /sys/kernel/debug/tracing
  38. # # mv ~/test-file ~/full-file
  39. #
  40. # If it didn't crash.
  41. #
  42. # # echo nop > current_tracer
  43. # # mv ~/non-test-file ~/full-file
  44. #
  45. # Get rid of the other test file from previous run (or save them off somewhere).
  46. # # rm -f ~/test-file ~/non-test-file
  47. #
  48. # And start again:
  49. #
  50. # # ftrace-bisect ~/full-file ~/test-file ~/non-test-file
  51. #
  52. # The good thing is, because this cuts the number of functions in ~/test-file
  53. # by half, the cat of it into set_ftrace_filter takes half as long each
  54. # iteration, so don't talk so much at the water cooler the second time.
  55. #
  56. # Eventually, if you did this correctly, you will get down to the problem
  57. # function, and all we need to do is to notrace it.
  58. #
  59. # The way to figure out if the problem function is bad, just do:
  60. #
  61. # # echo <problem-function> > set_ftrace_notrace
  62. # # echo > set_ftrace_filter
  63. # # echo function > current_tracer
  64. #
  65. # And if it doesn't crash, we are done.
  66. #
  67. # If it does crash, do this again (there's more than one problem function)
  68. # but you need to echo the problem function(s) into set_ftrace_notrace before
  69. # enabling function tracing in the above steps. Or if you can compile the
  70. # kernel, annotate the problem functions with "notrace" and start again.
  71. #
  72. if [ $# -ne 3 ]; then
  73. echo 'usage: ftrace-bisect full-file test-file non-test-file'
  74. exit
  75. fi
  76. full=$1
  77. test=$2
  78. nontest=$3
  79. x=`cat $full | wc -l`
  80. if [ $x -eq 1 ]; then
  81. echo "There's only one function left, must be the bad one"
  82. cat $full
  83. exit 0
  84. fi
  85. let x=$x/2
  86. let y=$x+1
  87. if [ ! -f $full ]; then
  88. echo "$full does not exist"
  89. exit 1
  90. fi
  91. if [ -f $test ]; then
  92. echo -n "$test exists, delete it? [y/N]"
  93. read a
  94. if [ "$a" != "y" -a "$a" != "Y" ]; then
  95. exit 1
  96. fi
  97. fi
  98. if [ -f $nontest ]; then
  99. echo -n "$nontest exists, delete it? [y/N]"
  100. read a
  101. if [ "$a" != "y" -a "$a" != "Y" ]; then
  102. exit 1
  103. fi
  104. fi
  105. sed -ne "1,${x}p" $full > $test
  106. sed -ne "$y,\$p" $full > $nontest