Analyze ANR with trace file

ANR (Application Not Responding): application does not respond, which is the performance of AMS and WMS monitoring application response timeout in Android;

The common ANR S in our application development are as follows:

  • Press the key to touch the event dispatch timeout ANR, and the general threshold is 5s (in the setting, the ANR pop-up window is opened, and the event dispatch will trigger the pop-up ANR by default);
  • Broadcast blocking ANR, the general threshold is 10s (in the setting, the ANR pop-up window is opened, no pop-up by default, only log prompt);
  • Service timeout ANR, the general threshold is 20s (in the setting, the ANR pop-up window is opened, no pop-up by default, only log prompt);

Location and analysis of ANR

When ANR occurs, in addition to the logs visible in logcat, we can also find traces in the directory specified by the system for analysis. After ANR occurs, we can get the ANR trace file through the following command:
1."`adb pull /data/anr/traces.txt ./

//Display process id, ANR occurrence time point, ANR occurrence process package name
----- pid 19073 at 2015-10-08 17:24:38 -----
Cmd line: com.example.yanbo.myapplication
//Some object information such as GC can be ignored
......
//ANR method stack print information! A key!
DALVIK THREADS (18):
"main" prio=5 tid=1 Sleeping
  | group="main" sCount=1 dsCount=0 obj=0x7497dfb8 self=0x7f9d09a000
  | sysTid=19073 nice=0 cgrp=default sched=0/0 handle=0x7fa106c0a8
  | state=S schedstat=( 125271779 68162762 280 ) utm=11 stm=1 core=0 HZ=100
  | stack=0x7fe90d3000-0x7fe90d5000 stackSize=8MB
  | held mutexes=
  at java.lang.Thread.sleep!(Native method)
  - sleeping on <0x0a2ae345> (a java.lang.Object)
  at java.lang.Thread.sleep(Thread.java:1031)
  - locked <0x0a2ae345> (a java.lang.Object)
//The real problem points that lead to ANR can be found in onClicksleepCause. We can do analogy analysis at ordinary times, which is not detailed here.
  at java.lang.Thread.sleep(Thread.java:985)
  at com.example.yanbo.myapplication.MainActivity$1.onClick(MainActivity.java:21)
  at android.view.View.performClick(View.java:4908)
  at android.view.View$PerformClick.run(View.java:20389)
  at android.os.Handler.handleCallback(Handler.java:815)
  at android.os.Handler.dispatchMessage(Handler.java:104)
  at android.os.Looper.loop(Looper.java:194)
  at android.app.ActivityThread.main(ActivityThread.java:5743)
  at java.lang.reflect.Method.invoke!(Native method)
  at java.lang.reflect.Method.invoke(Method.java:372)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:988)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
......
//Omit some infrequent attention to stack printing
......
``

OK, end of ANR analysis.

Reprint: http://blog.csdn.net/jiangguangchao/article/details/54908477

Tags: Java Android

Posted on Tue, 31 Mar 2020 16:41:36 -0700 by malcome_thompson