android核心技术之ANR分析(MTK)

What is ANR

ANR = Application Not Responding

ANR type:

  • Key Dispatch Timeout

Not response to an input event(eg: key press,screen touch) within (15 seconds or 8 seconds,default 5 seconds)

  • Broadcast Timeout

a broadcastReceiver hasn’t finished within 10 seconds

  • Service Timeout

Request service failed within 20 seconds

Reminder

  • if you choose “force to close ”,AMS will kill the process.
  • Keep the scene for get important info is very import.

ANR Essential:

Java process has main thread and main message queue(main thread = activity thread)
The Main Thread ,that is responsible for handling the ui events like Draw,Listen and receive the UI events.
Main thread will pick up message from main message queue and dispatch it as soon as possible.
Before main thread finish processing current message ,it can not pick up next one.
If main thread stuck with one message and fail to dispatch is in time, ANR will occur.

ANR key info

We need to know why main thread can not process the message in time?

  • Can not get CPU time to run
  • wait for some event but it donot happen in time?
  • Message handle flow is too complicated?

So need the follow files for analyze.

  • MTKLog saved in T card,include:

Aee_exp->db files(data/aee_exp)
MoblieLog->APLog_xxx_xxx->APLog
MdLog->MDLog_xxx_xxx->Modem Log
Netlog-> MDLog_xxx_xxx->Network Log

  • data/anr saved on the phone,include:

Trace.txt

Mobile Log:
you can get more info about anr from event log and main log:

  • The ANR time stamp
  • which process happens anr
  • which type of anr
  • more inof about the process before anr

LOG中搜索关键字:
anr
application is not responding
system_app_anr

Trace.txt
you can get callstack from the Trace.txt

Analyze ANR

在APLOG中搜索关键字:
anr
application is not responding

这里写图片描述

这里写图片描述

Example

  • Description:

IDLE界面进入图库,打开大量的图片,选择条目,点击几张图片,按HOME键,再从IDLE界面进入图库,点击图片,弹出图库没有响应。

  • Analyze:

(1)find anr time,process ID,ANT type
在APLOG中搜索关键字:
anr
application is not responding
system_app_anr

(2)Check CPU usage
(3)check Trace.txt,mapping process id and time stamp.
最后发现是在主线程中执行了耗时操作query数据库,导致ANR
(4)find more info from main and event log to check main thread.
最后确认是:
main thread are busy query db database all the time.

Need MTK help

提供有效的LOG:
-MTKLog saved in T card,include:
Aee_exp->db files
MoblieLog->APLog_xxx_xxx->APLog
MdLog->MDLog_xxx_xxx->Modem Log
Netlog-> MDLog_xxx_xxx->Network Log
-data/anr saved on the phone,include:
Trace.txt
最好是提供ENG的LOG,ENG会提供了更多的信息。

常见导致ANR的原因:

  1. 数据库操作I/O被阻塞
    iowait、ContentResolver.query、onPostExecute
  2. 在UI线程进行网络数据的读写
  3. 内存不足导致block在创建bitmap上
    atdalvik.system.VMRuntime.trackExternalAllocation(NativeMethod)
    atandroid.graphics.Bitmap.createBitmap(Bitmap.java:468)
  4. 程序异常退出,uncausedexception (Fatal)
  5. 程序强制关闭,ForceClosed (简称FC) (Fatal)
  6. 通过搜索ANR定位问题

解决ANR的方法:

  • 不要让主线程干耗时的工作
  • 不要让其他线程阻塞主线程的执行

参考资料

1.如何分析解决Android ANR
http://blog.csdn.net/dadoneo/article/details/8270107

2.Android ANR分析与总结
http://blog.csdn.net/androiddevelop/article/details/49515903

3.Android ANR分析
http://blog.csdn.net/yxz329130952/article/details/50087731

4.Application Not Responding(ANR) Analyze
MediaTek On-Line > eCourse Home > SW > ALPS > Common Framework

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hfreeman2008

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值