ftrace_lib.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/bin/sh
  2. ###########################################################################
  3. ## ##
  4. ## Copyright (c) 2010 FUJITSU LIMITED ##
  5. ## ##
  6. ## This program is free software: you can redistribute it and/or modify ##
  7. ## it under the terms of the GNU General Public License as published by ##
  8. ## the Free Software Foundation, either version 3 of the License, or ##
  9. ## (at your option) any later version. ##
  10. ## ##
  11. ## This program is distributed in the hope that it will be useful, ##
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
  14. ## GNU General Public License for more details. ##
  15. ## ##
  16. ## You should have received a copy of the GNU General Public License ##
  17. ## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
  18. ## ##
  19. ## Author: Li Zefan <lizf@cn.fujitsu.com> ##
  20. ## ##
  21. ###########################################################################
  22. . test.sh
  23. ftrace_test_init()
  24. {
  25. export TPATH="$PWD"
  26. export SPATH="$TPATH/ftrace_stress"
  27. if grep -q debugfs /proc/mounts; then
  28. export DEBUGFS_PATH=/sys/kernel/debug/
  29. export TRACING_PATH="$DEBUGFS_PATH/tracing"
  30. debugfs_def_mounted=1
  31. else
  32. tst_tmpdir
  33. export DEBUGFS_PATH="$PWD/debugfs"
  34. export TRACING_PATH="$PWD/debugfs/tracing"
  35. mkdir $DEBUGFS_PATH
  36. mount -t debugfs xxx $DEBUGFS_PATH
  37. fi
  38. TST_CLEANUP=clean_up
  39. trap clean_up_exit INT
  40. tst_require_root
  41. # Check to see tracing feature is supported or not
  42. if [ ! -d $TRACING_PATH ]; then
  43. tst_brkm TCONF "Tracing is not supported. Skip the test..."
  44. fi
  45. save_old_setting
  46. }
  47. test_interval=$1
  48. save_old_setting()
  49. {
  50. cd $TRACING_PATH
  51. old_trace_options=( `cat trace_options` )
  52. old_tracing_on=`cat tracing_on`
  53. old_buffer_size=`cat buffer_size_kb`
  54. old_tracing_cpumask=`cat tracing_cpumask`
  55. if [ -e tracing_cpumask ]; then
  56. old_tracing_cpumask=`cat tracing_cpumask`
  57. fi
  58. if [ -e tracing_enabled ]; then
  59. old_tracing_enabled=`cat tracing_enabled`
  60. fi
  61. if [ -e stack_max_size ]; then
  62. old_stack_tracer_enabled=`cat /proc/sys/kernel/stack_tracer_enabled`
  63. fi
  64. if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then
  65. old_ftrace_enabled=`cat /proc/sys/kernel/ftrace_enabled`
  66. fi
  67. if [ -e "function_profile_enabled" ]; then
  68. old_profile_enabled=`cat function_profile_enabled`
  69. fi
  70. setting_saved=1
  71. cd - > /dev/null
  72. }
  73. restore_old_setting()
  74. {
  75. if [ ! "$setting_saved" = 1 ]; then
  76. return
  77. fi
  78. cd $TRACING_PATH
  79. echo nop > current_tracer
  80. echo 0 > events/enable
  81. if [ -e tracing_max_latency ]; then
  82. echo 0 > tracing_max_latency
  83. fi
  84. if [ -e tracing_cpumask ]; then
  85. echo $old_tracing_cpumask > tracing_cpumask
  86. fi
  87. if [ -e trace_clock ]; then
  88. echo local > trace_clock
  89. fi
  90. if [ -e "function_pofile_enabled" ]; then
  91. echo $old_profile_enabled > function_profile_enabled
  92. fi
  93. if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then
  94. echo $old_ftrace_enabled > /proc/sys/kernel/ftrace_enabled
  95. fi
  96. if [ -e stack_max_size ]; then
  97. echo $old_stack_tracer_enabled > /proc/sys/kernel/stack_tracer_enabled
  98. echo 0 > stack_max_size
  99. fi
  100. echo $old_buffer_size > buffer_size_kb
  101. echo $old_tracing_on > tracing_on
  102. if [ -e tracing_enabled ];then
  103. echo $old_tracing_enabled > tracing_enabled
  104. fi
  105. for option in $old_trace_options
  106. do
  107. echo $option > trace_options 2> /dev/null
  108. done
  109. echo > trace
  110. if [ -f set_ftrace_filter ]; then
  111. echo > set_ftrace_filter
  112. fi
  113. cd - > /dev/null
  114. }
  115. clean_up_mount()
  116. {
  117. if [ ! "$debugfs_def_mounted" = "1" ]; then
  118. umount $DEBUGFS_PATH
  119. rmdir $DEBUGFS_PATH
  120. fi
  121. }
  122. clean_up()
  123. {
  124. restore_old_setting
  125. clean_up_mount
  126. }
  127. clean_up_exit()
  128. {
  129. restore_old_setting
  130. clean_up_mount
  131. exit 1
  132. }
  133. test_begin()
  134. {
  135. start_time=`date +%s`
  136. }
  137. test_wait()
  138. {
  139. # run the test for $test_interval secs
  140. tst_sleep ${test_interval}s
  141. }
  142. ftrace_test_init