Skip to content

Commit 2787958

Browse files
Zhengyin Qianandroid-build-merger
authored andcommitted
ANRdaemon: add README and a bash script to easily get trace. am: 9e90477
am: 4b7f0b2 * commit '4b7f0b27a267e5e10894bbf438dec15e534e4cc4': ANRdaemon: add README and a bash script to easily get trace. Change-Id: I0ea20dd173cfaef70df4d07672810ca233fcb5f2
2 parents 90ce7ac + 4b7f0b2 commit 2787958

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

ANRdaemon/ANRdaemon_get_trace.sh

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

ANRdaemon/README

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ANRdaemon is a daemon to help analyze ANR due to CPU starvation by logging system
2+
activity when CPU usage is very high. The daemon uses debugfs underlying for
3+
logging. Trace are configured ahead by setting different modules in /d/tracing.
4+
Depending on the CPU usage level, the trace is turn on/off by writting to the
5+
global control /d/trace/trace_on. The raw trace file is stored at
6+
/d/tracing/trace.
7+
8+
The daemon will be started at boot time and will be running with the following
9+
settings:
10+
$ ANRdaemon -t 9990 sched gfx am
11+
This means tracing will be enabled above 99.90% CPU utilization and will trace
12+
sched, gfx and am modules (See -h for more info).
13+
14+
Use ANRdaemon_get_trace.sh [device serial] to dump and fetch the compressed trace file.
15+
16+
The compressed trace file can be parsed using systrace:
17+
$ systrace.py --from-file=<path to compressed trace file>
18+
19+
Known issue: in the systrace output, anrdaemon will show up when the trace is
20+
not running. This is because the daemon process turns off tracing when CPU usage
21+
drops, the last entry it leaves in the raw trace file is the scheduler switched
22+
from some other process to the daemon. Then sometime later (say 20 secs later),
23+
when the CPU usage becomes high and the daemon process turn on tracing again,
24+
the first entry in /d/tracing/trace logged by sched is switching away from the
25+
daemon process to some other process. Due to this artifact, when the raw trace
26+
file is parsed by systrace.py, the daemon process is shown as running for the
27+
whole 20secs (because from systrace's view, the two 20 sec apart sched trace
28+
entries regarding the daemon process indicates the daemon process ran continuously
29+
for all 20sec). However, this will not affect the actual captured trace during
30+
high CPU usage case.

0 commit comments

Comments
 (0)