diff options
author | Zhengyin Qian <qianzy@google.com> | 2016-05-27 17:58:00 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-05-27 17:58:00 +0000 |
commit | 27879586fff26d5ac1864f57bf441a39f8ab9315 (patch) | |
tree | 06bca426c19114e6a999d99579d5ca80cc418df4 | |
parent | 90ce7ac45f183aad12151d691f82a4a9c9a78f2f (diff) | |
parent | 4b7f0b27a267e5e10894bbf438dec15e534e4cc4 (diff) | |
download | extras-27879586fff26d5ac1864f57bf441a39f8ab9315.tar.gz |
ANRdaemon: add README and a bash script to easily get trace. am: 9e90477a67
am: 4b7f0b27a2
* commit '4b7f0b27a267e5e10894bbf438dec15e534e4cc4':
ANRdaemon: add README and a bash script to easily get trace.
Change-Id: I0ea20dd173cfaef70df4d07672810ca233fcb5f2
-rwxr-xr-x | ANRdaemon/ANRdaemon_get_trace.sh | 39 | ||||
-rw-r--r-- | ANRdaemon/README | 30 |
2 files changed, 69 insertions, 0 deletions
diff --git a/ANRdaemon/ANRdaemon_get_trace.sh b/ANRdaemon/ANRdaemon_get_trace.sh new file mode 100755 index 00000000..be4062c7 --- /dev/null +++ b/ANRdaemon/ANRdaemon_get_trace.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +TRACE_DIR=/sdcard/ANRdaemon + +if [ $# -eq 1 ]; then + DEVICE=$(echo "-s $1") +else + DEVICE="" +fi + +PID=$(adb $DEVICE shell "ps | grep anrd") + +if [ $? -ne 0 ]; then + echo "FAILED. ADB failed or Daemon is not running." + exit 1 +fi + +PID=$(echo "$PID" | awk '{ print $2 }') +adb $DEVICE shell "kill -s SIGUSR1 $PID" + +TRACE_FILE=$(adb $DEVICE shell "ls $TRACE_DIR | tail -n1" | tr -d '\r') + +# Wiat the trace file generation to complete +adb $DEVICE shell "lsof $PID" | grep $TRACE_FILE > /dev/null +while [ $? -eq 0 ]; +do + sleep 1 + adb $DEVICE shell "lsof $PID" | grep "$TRACE_FILE" > /dev/null +done + +if [ -z "$TRACE_FILE" ]; then + echo "FAILED. Trace file not created" +fi + +adb $DEVICE pull "${TRACE_DIR}/${TRACE_FILE}" ${TRACE_FILE} + +CURRENT_DIR=$(pwd) +echo SUCCEED! +echo Trace stored at ${CURRENT_DIR}/${TRACE_FILE} diff --git a/ANRdaemon/README b/ANRdaemon/README new file mode 100644 index 00000000..57ed594a --- /dev/null +++ b/ANRdaemon/README @@ -0,0 +1,30 @@ +ANRdaemon is a daemon to help analyze ANR due to CPU starvation by logging system +activity when CPU usage is very high. The daemon uses debugfs underlying for +logging. Trace are configured ahead by setting different modules in /d/tracing. +Depending on the CPU usage level, the trace is turn on/off by writting to the +global control /d/trace/trace_on. The raw trace file is stored at +/d/tracing/trace. + +The daemon will be started at boot time and will be running with the following +settings: +$ ANRdaemon -t 9990 sched gfx am +This means tracing will be enabled above 99.90% CPU utilization and will trace +sched, gfx and am modules (See -h for more info). + +Use ANRdaemon_get_trace.sh [device serial] to dump and fetch the compressed trace file. + +The compressed trace file can be parsed using systrace: +$ systrace.py --from-file=<path to compressed trace file> + +Known issue: in the systrace output, anrdaemon will show up when the trace is +not running. This is because the daemon process turns off tracing when CPU usage +drops, the last entry it leaves in the raw trace file is the scheduler switched +from some other process to the daemon. Then sometime later (say 20 secs later), +when the CPU usage becomes high and the daemon process turn on tracing again, +the first entry in /d/tracing/trace logged by sched is switching away from the +daemon process to some other process. Due to this artifact, when the raw trace +file is parsed by systrace.py, the daemon process is shown as running for the +whole 20secs (because from systrace's view, the two 20 sec apart sched trace +entries regarding the daemon process indicates the daemon process ran continuously +for all 20sec). However, this will not affect the actual captured trace during +high CPU usage case. |