1 #!/bin/bash 2 3 TRACE_DIR=/data/misc/anrd 4 TRACE_FILE_PATTEN=dump_of_anrdaemon 5 6 if [ $# -eq 1 ]; then 7 DEVICE=$(echo "-s $1") 8 else 9 DEVICE="" 10 fi 11 12 PID=$(adb $DEVICE shell "ps | grep anrd") 13 14 if [ $? -ne 0 ]; then 15 echo "FAILED. ADB failed or Daemon is not running." 16 exit 1 17 fi 18 19 PID=$(echo "$PID" | awk '{ print $2 }') 20 adb $DEVICE shell "kill -s SIGUSR1 $PID" 21 22 TRACE_FILE=$(adb $DEVICE shell "ls $TRACE_DIR \ 23 grep $TRACE_FILE_PATTEN | tail -n1" | tr -d '\r') 24 25 # Wiat the trace file generation to complete 26 adb $DEVICE shell "lsof $PID" | grep $TRACE_FILE > /dev/null 27 while [ $? -eq 0 ]; 28 do 29 sleep 1 30 adb $DEVICE shell "lsof $PID" | grep "$TRACE_FILE" > /dev/null 31 done 32 33 if [ -z "$TRACE_FILE" ]; then 34 echo "FAILED. Trace file not created" 35 fi 36 37 adb $DEVICE pull "${TRACE_DIR}/${TRACE_FILE}" ${TRACE_FILE} 38 39 CURRENT_DIR=$(pwd) 40 echo SUCCEED! 41 echo Trace stored at ${CURRENT_DIR}/${TRACE_FILE} 42