ANR简介与常见问题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

SpreadSoft Confidential
page.
Байду номын сангаас
2
触发ANR的三种情况
SpreadSof
主线程对输入事件在 5 秒内没有处理完毕 主线程在执行 BroadcastReceiver 的 onReceive 函数 时 10 秒内没有执行完毕
主线程在执行 Service 的各个生命周期函数时 20 秒 内没有执行完毕
SpreadSoft Confidential
page. 18
坏的ANR分析
缺乏有效分析
“应用看不出来了,请FW / Kernel 帮忙分析”
“log内有很多ANR,请FW整体把握”
SpreadSof
“GC垃圾回收的线程被杀死导致内存泄漏输入法(ActivityManager)被杀死,5秒后输 入法应用调度超时,最终导致com.android.gallery3d 发生ANR” “sigkill杀死了收音机,所以指南针发生了ANR”
SpreadSof
进程信息
是否启动了太多线程?
发生ANR时各个应用的内存使用量
SpreadSoft Confidential
page. 12
screenshot中的信息
发生问题的时间? 手机是否完全黑屏? 手机显示是否处于混乱状态? 手机是否部分黑屏?
SpreadSof
一些特殊状态
是否有不常见的错误信息,特别是在发生ANR的应用 启动后打出的信息
stack corruption detected: aborted Looper : Error modifying epoll events for fd 162, errno=2
SpreadSoft Confidential
SpreadSof
[ 17.716015] c2 [<c0258d88>] (tty_read+0x0/0xdc) from [<c01027b0>] (vfs_read+0xc0/0x13c) [ 17.724050] c2 [<c01026f0>] (vfs_read+0x0/0x13c) from [<c0102878>] (sys_read+0x4c/0x78)
“Kernel.log有5个,平时只有一个”
SpreadSoft Confidential
page. 20
好的ANR分析
找到异常与ANR可能的联系
SpreadSof
“Camera Handler被sigkill杀死,而Camera需要用它与HAL通信,故Gallery3D发生 ANR。” “消息泵Looper出现异常,导致应用无法接到InputDispacher分发的消息,于是 ANR。” “Camera的HAL层代码在上层应用退出后没有关闭,占用大量CPU负载,导致活动应 用排队时间过长,导致ANR。” “系统频繁杀进程,主线程Suspend等待GC,导致ANR,建议优化。” “Kernel信息显示写SD卡命令超时,Trace文件中看到应用主线程停在写文件上,请检 查SD卡相关模块。”
SpreadSoft Confidential
page. 16
Kernel.log中的信息
大量异常信息
10-16 06:04:03.301 <4>[59035.520019] c0 DCAM: 1 wait 10-16 06:04:03.371 <4>[59035.580514] c0 DCAM: 1 wait 10-16 06:04:03.431 <4>[59035.641031] c0 DCAM: 1 wait 10-16 06:04:03.491 <4>[59035.701556] c0 DCAM: 1 wait 10-16 06:04:03.551 <4>[59035.762070] c0 DCAM: 1 wait 10-16 06:04:03.611 <4>[59035.822593] c0 DCAM: 1 wait 10-16 06:04:03.671 <4>[59035.883109] c0 DCAM: 1 wait 10-16 06:04:03.731 <4>[59035.943633] c0 DCAM: 1 wait 10-16 06:04:03.791 <4>[59036.004154] c0 DCAM: 1 wait
SpreadSoft Confidential
page. 14
Kernel.log中的信息
例3内存不足
<4>[ 706.806995] c1 send sigkill to 1038 (mobile.cmccwifi), adj 705, size 4733 <4>[ 706.821424] c1 send sigkill to 1399 (rd.fileexplorer), adj 705, size 4438 <4>[ 706.829372] c1 send sigkill to 1142 (viders.calendar), adj 647, size 4688
ANR发生的时间点
Input event dispatching timed out sending to
SpreadSof
应用启动后多久发生ANR?
应用启动是否顺利?
Launch timeout has expired, giving up wake lock
It has been 5042.3ms since event, 5005.0ms since wait started. Reason: Waiting because no window has focus but there is a focused application that may eventually add a window when it finishes starting up.
SpreadSof
SpreadSoft Confidential
page. 17
Kernel.log中的信息
大量异常信息
<3>[ <3>[ <3>[ <3>[ <6>[ <3>[ <3>[ <3>[
SpreadSof
12.420045] c1 Error: sblock_receive dst 2, channel 17 result is -19 12.432095] c1 saudio_wait_monitor_cmd error -19 12.432135] c1 sblock-2-13 not ready! 12.432153] c1 Error: sblock_receive dst 2, channel 13 result is -19 12.458086] c3 pgprot_noncached flags 0x0 12.520700] c1 saudio_wait_monitor_cmd error -19 12.520735] c1 sblock-2-17 not ready! 12.520751] c1 Error: sblock_receive dst 2, channel 17 result is -19
SpreadSoft Confidential
page. 21
如果确实分析不出来
SpreadSof
请把log文件留下来用信使发给FW,一天从FTP下10 个文件太痛苦了。
SpreadSoft Confidential
page. 22
page.
7
Trace.log中的信息
线程状态
SpreadSof
SpreadSoft Confidential
page.
8
Trace.log中的信息
线程状态
SpreadSof
SpreadSoft Confidential
page.
9
Trace.log中的信息
死锁 Native方法未返回 主线程Suspend 线程暂停,正在GC或者Debug
SpreadSof
SpreadSoft Confidential
page. 15
Kernel.log中的信息
例4 Backtrace
[ 17.705114] c2 Backtrace: [ 17.707799] c2 [<c025d968>] (n_tty_read+0x0/0x648) from [<c0258e1c>] (tty_read+0x94/0xdc)
SpreadSoft Confidential
page.
3
ANR的相关log
SpreadSof
SpreadSoft Confidential
page.
4
Syetem.log中的信息
ANR信息
SpreadSof
SpreadSoft Confidential
page.
5
System.log中的信息
SpreadSof
SpreadSoft Confidential
page. 10
Trace.log中的信息
nativePollOnce
SpreadSof
SpreadSoft Confidential
page. 11
snapshot.log中的信息
Meminfo
MemTotal: 403784 kB MemFree: Buffers: Cached: Kernel总共能识别的内存 3068 kB 完全空闲的内存 3140 kB 可以腾出的缓存 43772 kB 可以腾出的缓存
SpreadSoft Confidential
page. 19
好的ANR分析
查找异常现象
“CPU负载超过9,main.log中一秒打出500行log” “主线程被Suspend,之前有大量低内存log”
SpreadSof
“ANR发生前发现信息stack corruption detected: aborted ,请调查是否异常。”
是否存在相关进程或服务被杀死?
SpreadSoft Confidential
page.
6
Main.log中的信息
是否多出了一些log?
Camera已经退出,但HAL层仍在打出信息 AppBackup长时间循环输出log
SpreadSof
Main.log中的信息比较杂乱,需要仔细分析
是否缺少了一些log?
page.
1
ANR产生的三个条件
SpreadSof
主线程:只有应用程序进程的主线程响应超时才会产 生 ANR
超时时间:ANR 的类型不同,超时时间也不同,但只要 在这个时间上限内没有响应就会ANR
输入事件/特定操作:输入事件是指按键、触屏等设备 输入事件,特定操作是指BroadcastReceiver 和 Service 的生命周期中的各个函数,产生 ANR 的上下 文不同,导致 ANR 的原因也会不同。
SpreadSof
<4>[ 1304.483544] c2 Normal: 737*4kB 232*8kB 0*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB= 4804kB
例2内存耗尽
<4>[ 720.147025] c1 thumbs thread invoked oom-killer: gfp_mask=0x10200da, order=0, oom_adj=2, oom_score_adj=117
SpreadSoft Confidential
page. 13
Kernel.log中的信息
例1内存碎片
<4>[ 1304.482941] c2 sh invoked oom-killer: gfp_mask=0xd0, order=2, oom_adj=-16, oom_score_adj=-941
ANR简介
SpreadSof
ANR,是“Application Not Responding”的缩写,即 “应用程序无响应”。
如果应用程序主线程(即 UI 线程)在超时时间内对输入 事件没有处理完毕,或者对特定操作没有执行完毕,就 会出现 ANR。
SpreadSoft Confidential
相关文档
最新文档