pvrhtbd 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. ###############################################################################
  2. # @File pvrhtbd
  3. # @Title HTB Log dump tool
  4. # @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
  5. # @Description Script to execute a set of tests and collate the benchmark
  6. # performance into a single report.
  7. # @License Strictly Confidential.
  8. ###############################################################################
  9. usage() {
  10. echo ""
  11. echo "Usage: ./pvrhtbd [pvrdebug hostlog options and arguments]"
  12. echo "Dump the processed output of the Host Trace Buffer to a file."
  13. echo ""
  14. echo "This tool starts a reader daemon, then applies any hostlog"
  15. echo "configuration options."
  16. echo "Data logging continues until <enter> is pressed to stop log capture"
  17. echo ""
  18. echo "There are two main use-cases supported by this tool:"
  19. echo "Crash Logging:"
  20. echo " Where the Host Trace Buffer has been configured via powervr.ini"
  21. echo " to drop the oldest logs, this tool can be used without arguments"
  22. echo " after the driver has crashed to capture the logs leading up to"
  23. echo " the crash point."
  24. echo "Continuous Logging:"
  25. echo " The tool may be stated, applying any Host Trace configuration"
  26. echo " options required and left running until the data required has"
  27. echo " been captured."
  28. echo " If the Host Trace Buffer size specified in powervr.ini is large"
  29. echo " enough, and this tool started early enough putting the Host Trace"
  30. echo " in blocking mode, it should be possible to capture all Host Trace"
  31. echo " events"
  32. echo ""
  33. echo " -h, --help prints this message"
  34. echo ""
  35. }
  36. # write_cfg_file(tld_output_folder, cfg_file)
  37. write_cfg_file() {
  38. echo "
  39. [pvrtld]
  40. output_folder_name=$1
  41. output_type=file
  42. omit_header=yes
  43. output_file_save_previous=yes
  44. [PVRHTBuffer]
  45. enabled=yes
  46. output_file_name=$2
  47. wait_for_stream=yes
  48. " > $3
  49. }
  50. PVRINI_FILE="/etc/powervr.ini"
  51. TLD_CFG_FILE="htbtld.conf"
  52. FIFO_FILE="tldctrl.fifo"
  53. HT_BASENAME="hosttrace"
  54. HT_OUTFILE="${HT_BASENAME}.bin"
  55. HOSTTRACE_FILE="${HT_BASENAME}.log"
  56. PVRDBG_DROPLATEST="-hostlogtype droplatest"
  57. BLOCK_STR="block"
  58. APPHINT_EN_STR="EnableHTBLogGroup"
  59. PVRDEBUG_EN_STR="hostloggroups"
  60. PVRDEBUG_ARGS=""
  61. GRAB_LOG=0
  62. init() {
  63. # detect os
  64. if [ -x "/system/bin/logcat" ]; then
  65. OS="Android"
  66. elif [ -c "/dev/slog" ]; then
  67. OS="QNX"
  68. else
  69. OS="Linux"
  70. fi
  71. echo "Detected OS: $OS"
  72. # set OS dependent variables here
  73. if [ $OS = 'Android' ]; then
  74. TMP_DIR="/data/local/tmp"
  75. BIN_DIR="/system/vendor/bin"
  76. TLD_BIN="$BIN_DIR/pvrtld"
  77. PVRDEBUG_BIN="$BIN_DIR/pvrdebug"
  78. HTB_BIN="$BIN_DIR/pvrhtb2txt"
  79. elif [ $OS = 'QNX' ]; then
  80. TMP_DIR="/tmp"
  81. TLD_BIN="`command -v pvrtld`"
  82. PVRDEBUG_BIN="`command -v pvrdebug`"
  83. HTB_BIN="`command -v pvrhtb2txt`"
  84. # QNX does not have /etc/powervr.ini by default. Check current directory first.
  85. if [ -e "`pwd`/powervr.ini" ]; then
  86. PVRINI_FILE="`pwd`/powervr.ini"
  87. fi
  88. else
  89. TMP_DIR="/tmp"
  90. TLD_BIN="`command -v \"pvrtld\"`"
  91. PVRDEBUG_BIN="`command -v \"pvrdebug\"`"
  92. HTB_BIN="`command -v \"pvrhtb2txt\"`"
  93. fi
  94. if [ ! -x "$TLD_BIN" ]; then
  95. echo "[Error] pvrtld not found"
  96. exit 1
  97. fi
  98. if [ ! -x "$PVRDEBUG_BIN" ]; then
  99. echo "[Error] pvrdebug not found"
  100. exit 1
  101. fi
  102. if [ ! -x "$HTB_BIN" ]; then
  103. echo "[Error] pvrhtb2txt not found"
  104. exit 1
  105. fi
  106. if [ $OS = 'QNX' ]; then
  107. # QNX not support creating folder in /tmp. User must cd to a mount point (NFS or external disk)
  108. WORK_DIR="`pwd`/`date +pvrhtbd_%y%m%d%H%M`"
  109. else
  110. WORK_DIR="$TMP_DIR/`date +pvrhtbd_%y%m%d%H%M`"
  111. fi
  112. mkdir -p $WORK_DIR
  113. if [ $? -ne 0 ]; then
  114. echo "Failed to create folder $WORK_DIR"
  115. if [ $OS = 'QNX' ]; then
  116. # Worst case that user do not have NFS mount or external disk.
  117. echo
  118. echo "Using $TMP_DIR as output directory"
  119. echo -n "Old data files will be deleted. Press <Enter> to continue..."
  120. dd bs=1 count=1 2> /dev/null
  121. WORK_DIR=$TMP_DIR
  122. # Remove existing files
  123. rm -f $WORK_DIR/$TLD_CFG_FILE
  124. rm -f $WORK_DIR/$HT_OUTFILE
  125. rm -f $WORK_DIR/$HOSTTRACE_FILE
  126. else
  127. exit 1
  128. fi
  129. fi
  130. # Should print out working variables
  131. echo "TMP_DIR=$TMP_DIR"
  132. echo "TLD_BIN=$TLD_BIN"
  133. echo "PVRDEBUG_BIN=$PVRDEBUG_BIN"
  134. echo "HTB_BIN=$HTB_BIN"
  135. echo "WORK_DIR=$WORK_DIR"
  136. }
  137. arg_parse() {
  138. arg_add=0
  139. for argument in "$@"
  140. do
  141. case "$argument" in
  142. -hostloggroups|-hostlogmode|-hostlogtype|-hostloglevel)
  143. PVRDEBUG_ARGS="$PVRDEBUG_ARGS $argument"
  144. arg_add=1
  145. ;;
  146. -h|--help)
  147. usage
  148. exit 0
  149. ;;
  150. -g|--grab)
  151. GRAB_LOG=1
  152. ;;
  153. *)
  154. if [ "$arg_add" -eq "1" ]; then
  155. PVRDEBUG_ARGS="$PVRDEBUG_ARGS $argument"
  156. arg_add=0
  157. else
  158. echo "[Error] Argument '$argument' not recognized."
  159. echo " Run '$0 -h' for more information."; exit 1
  160. fi
  161. ;;
  162. esac
  163. done
  164. }
  165. capture_hosttrace() {
  166. # fifo to send keypress to backgrounded app
  167. # mknod $WORK_DIR/$FIFO_FILE p
  168. # run pvrtld in background
  169. # (redirecting stdout causes pvrtld to fail to write output)
  170. #$TLD_BIN -f=$WORK_DIR/$TLD_CFG_FILE < $WORK_DIR/$FIFO_FILE &
  171. $TLD_BIN -f=$WORK_DIR/$TLD_CFG_FILE &
  172. proc_num=$!
  173. sleep 3
  174. # set the logging parameters as requested
  175. # this has to be done after starting capture to support blocking logs
  176. if [ ! -z "$PVRDEBUG_ARGS" ]; then
  177. echo "Using pvrdebug to set logging parameters:"
  178. echo " $PVRDEBUG_ARGS"
  179. $PVRDEBUG_BIN $PVRDEBUG_ARGS
  180. fi
  181. if [ "0" -eq "$GRAB_LOG" ]; then
  182. # wait for a keypress (Android does not give a lot of options for this)
  183. echo "Please press <Enter> to stop log capture"
  184. dd bs=1 count=1 2> /dev/null
  185. else
  186. sleep 3
  187. fi
  188. # safely stop if reading a blocking log
  189. echo $PVRDEBUG_ARGS | grep -q "$BLOCK_STR"
  190. if [ "0" -eq "$?" ]; then
  191. echo "Using pvrdebug to reset logging parameters:"
  192. echo " $PVRDBG_DROPLATEST"
  193. $PVRDEBUG_BIN $PVRDBG_DROPLATEST
  194. fi
  195. # stop pvrtld
  196. #echo -n "x" > $WORK_DIR/$FIFO_FILE
  197. #rm $WORK_DIR/$FIFO_FILE
  198. echo "Stopping..."
  199. kill -s QUIT $proc_num
  200. # wait some because pvrtld is slow to stop
  201. sleep 3
  202. if [ ! $OS = 'QNX' ]; then
  203. # flush to disk
  204. sync
  205. fi
  206. }
  207. process_binfile() {
  208. $HTB_BIN -bin $WORK_DIR/$HT_OUTFILE > $WORK_DIR/$HOSTTRACE_FILE
  209. echo "Host Trace Data written to: $WORK_DIR/$HOSTTRACE_FILE"
  210. }
  211. perform_check() {
  212. if [ -e $PVRINI_FILE ]; then
  213. grep -q "$APPHINT_EN_STR" $PVRINI_FILE
  214. app_en=$?
  215. else
  216. app_en=1
  217. fi
  218. echo $PVRDEBUG_ARGS > $WORK_DIR/args.tmp
  219. grep -q "$PVRDEBUG_EN_STR" $WORK_DIR/args.tmp
  220. arg_en=$?
  221. if [ "0" -ne "$app_en" -a "0" -ne "$arg_en" ]; then
  222. echo "Host Trace Logging is not enabled in either:"
  223. echo " $PVRINI_FILE"
  224. echo " or cmdline args"
  225. echo "Nothing will be captured"
  226. exit 1
  227. fi
  228. }
  229. archive() {
  230. if [ $OS = "Android" ]; then
  231. if [ ! -x /system/bin/gzip ]; then
  232. return
  233. fi
  234. else
  235. if ! command gzip -h >/dev/null 2>&1; then
  236. return
  237. fi
  238. fi
  239. echo -n "Archiving data ...................... "
  240. gzip -f $OUT
  241. echo "done"
  242. echo ""
  243. echo "File $OUT.gz was created."
  244. }
  245. run_main() {
  246. echo ""
  247. echo "========================== HTB Log Dump ============================"
  248. init
  249. arg_parse $@
  250. perform_check
  251. write_cfg_file $WORK_DIR $HT_BASENAME $WORK_DIR/$TLD_CFG_FILE
  252. echo ""
  253. echo "======================== Capturing HTB Log ========================="
  254. capture_hosttrace
  255. echo ""
  256. echo "======================== Write out HTB Log ========================="
  257. process_binfile
  258. echo ""
  259. echo ""
  260. }
  261. # main function
  262. run_main $@