ANR基础
转自:http://blog.sina.com.cn/s/blog_c0de2be70102wd1k.html
1、ANR
basic knowledge
ANR分类:
Key Dispatch Timeout
Service Timeout
Broadcast Timeout
关键词:
event log: “am_anr”
trace.txt -java
-native
CPU usage ago
CPU usage later
iowait
“Early ANR” = The first ANR
2、How
to read Event Log
一些信息没有在logcat
log中而是在event
log中,查看event
log对与解决ANR问题很有帮助。
1) event log定义:
event.logtags
( in code path
/system/core/logcat/event.logtags )
( in phone path /system/etc/event-log-tags
)
event.logtags:
30008 am_anr (pid|1|5),(Package
Name|3),(Flags|1|5),(reason|3)
Source Code ActivityManagerService.java:
EventLog.writeEvent(EventLogTags.AM_ANR,
app.pid, app.processName...))
2) Log Example:
I/am_anr ( 1776):
[3274,com.sonyericsson.home,572997,keyDispatchingTimedOut]
3) Event: am_anr
system/core/logcat/event.logtags
52004 binder_sample (descriptor|3),(method_num|1|5),(time|1|3),(blocking_package|3),(sample_percent|1|6)
# Application Not Responding
30008 am_anr (pid|1|5),(Package
Name|3),(Flags|1|5),(reason|3)
I/am_anr ( 1776):
[3274,com.sonyericsson.home,572997,keyDispatchingTimedOut]
4) 重要的event
log标志:
db_sample
content_query_sample
content_update_sample
binder sample
dvm_lock_sample
Activity Event Series:
am_proc_start
am_restart_activity
am_on_resume_called
am_finish_activity
am_pause_activity
am_on_paused_called
am_destroy_activity
5) Database related:
定义:
52000 db_sample
(db|3),(sql|3),(time|1|3),(blocking_package|3), (sample_percent|1|6)
# Database operation samples.
# db: 数据库文件名
# sql: the executed query (without query args)
# time: cpu time millis (not wall time),
including lock acquisition
# blocking_package: if this is on a main
thread, the package name, otherwise ""
# sample_percent: the percent likelihood this
query was logged (based on 500ms)
sample_percent? If time >= 500ms, then
sample_percent show 100.
例子1:
I/db_sample(27898):
[/data/data/com.facebook.katana/databases/fb.db,INSERT INTO
cache(value, timestamp, name) VALUES(?, ?,
?);,99,com.facebook.katana,20]
信息解析:
Database:
/data/data/com.facebook.katana/databases/fb.db
Sql: INSERT INTO cache(value, timestamp, name)
VALUES(?, ?, ?)
Time spent: 99ms
This database operation runs in
com.facebook.katana main thread.
例子2:
I/db_sample(26092):
[/data/data/com.google.android.gm/databases/XX@YY,COMMIT;DELETE FROM
messages WHERE conversation = ? AND synced = ,797,,100]
6) Events : binder_sample
定义:
52004 binder_sample (descriptor|3),(method_num|1|5),(time|1|3),(blocking_package|3),(sample_percent|1|6)
descriptor:接口描述符(任何一个binder都实现一个接口,IPC调用用的API,任何一个接口都有一个描述符,即一个字符串)
method_num:调用的方法的序列号
time:该方法调用耗用的时间
(从client端发起到server端完成并返回)
blocking_package:从哪个进程发起的调用
例子:
I/binder_sample( 520):
[com.android.internal.telephony.ITelephonyRegistry,7,12518,com.android.phone,100]
含义:从com.android.phone主线程发起了一个ITelephonyRegistry接口的第7个方法的binder调用,耗时12s。
(从后面的源代码可知,系统只记录从主线程发起的binder通讯)
查可知有ITelephonyRegistry.aidl,系统编译后会自动生成ITelephonyRegistry.java文件,里面定义了方法的序号。
out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/src/telephony/java/com/android/internal/telephony/ITelephonyRegistry.java
private static final java.lang.String DESCRIPTOR
= "com.android.internal.telephony.ITelephonyRegistry";
static final int TRANSACTION_listen =
(android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
static final int TRANSACTION_notifyCallState =
(android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
......
static final int
TRANSACTION_notifyDataConnection =
(android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
由此知第7个方法是notifyDataConnection()
7) Events : dvm_lock_sample
定义:
dvm_lock_sample
(process|3),(main|1|5),(thread|3),(time|1|3),(file|3),(line|1|5),(ownerfile|3),(ownerline|1|5),(sample_percent|1|6)
dvm_lock_sample会记录所有线程在java层(即dvm层)获取锁的记录。该log在获取到锁之后输出。
包括:所属进程,是否为主线程,线程名称,获取锁所用的时间,获取锁代码所在的源文件,行号,锁被占有的代码所在的源文件,行号,耗用时间所占比例。
如果ownerfile与file相同,用"-"表示。
Example:
11-25 14:14:24.140 I/dvm_lock_sample( 296):
[system_server,0,Binder Thread #10,12515,
PackageManagerService.java,1719,-,682,100]
含义:Binder
Thread #10 ,非主线程,属于system_server进程,获取锁耗用了12s,
PackageManagerService.java, line
1719获取锁,PackageManagerService.java,line
682占用了锁。
3、OOM
Memory leak will cause ANR. Because when
memory is low, normal operations will be blocked for lack of memory
or wait GC to collect memory, this will make normal operations taking
much more time than before. Low memory will cause system into very
bad performance, ANR occurrence rate will increase greatly in this
condition. You will see many out of memory issues are along with ANR
issues.
If you see frequent ANR occurs in short time
and system is in OOM condition. These ANRs often can be ignored. We
should put effert on fixing memory leak. When the memory leak is
fixed, these ANRs should disappear.
There are 2 kinds of OOM. One is OOM in one
dvm process. Another is system overall memory is not enough.
1) OOM in one dvm process
One process, one dvm, one GC.
Dvm heap limit in ICS: Change from
dalvik.vm.heapsize to dalvik.vm.heapgrowthlimit (64Mb now in ginger
fuji ICS)
D/dalvikvm( 216): GC_CONCURRENT freed 4443K,
54% free 28546K/61347K, paused 4ms+20ms
系统为进程216分配了61347K的dvm
heap,有54%
free,分母代表了历史上对Heap的最大需求。
D/dalvikvm( 3142): GC_BEFORE_OOM freed 10K, 2%
free 64421K/65571K, paused 258msE/dalvikvm-heap( 3142): Out of memory
on a 335888-byte allocation.
2) System overall OOM
Kernel oom killer – when there is no enough
memory for allocating.
内核kernel
log:
init invoked oom-killer: gfp_mask=0xd0, order=2,
oom_adj=-16, oom_score_adj=-941
[] (>] (pgd_alloc+0x14/0xe0)
...... unwind_backtrace+0x0/0x12c) from
[] (dump_header.clone.1+0xd8/0x22c)
]
(dump_header.clone.1+0xd8/0x22c) from []
(oom_kill_process.clone.0+0x40/0x33c)
[]
(oom_kill_process.clone.0+0x40/0x33c) from []
(out_of_memory+0x328/0x458)
[] (out_of_memory+0x328/0x458)
from [] (__alloc_pages_nodemask+0x4a0/0x608)
[]
(__alloc_pages_nodemask+0x4a0/0x608) from []
(__get_free_pages+0x10/0x24)
[] (__get_free_pages+0x10/0x24)
from [
[] (sys_fork+0x28/0x2c) from
[] (ret_fast_syscall+0x0/0x30)
……
Out of memory: Kill process 22591
(ckscreen.uxpnxt) score 754 or sacrifice child
Killed process 22591 (ckscreen.uxpnxt)
total-vm:466932kB, anon-rss:23168kB, file-rss:8396kB
Android Low memory killer – when memory
decrease to some value. So, it doesn’t mean memory is used up.
select 1381 (android.browser), adj 7, size
22194, to kill
select 18759 (ndroid.crashsms), adj 8, size
7129, to kill
ANR基础的更多相关文章
- 谈谈 ANR 之 Service 超时
1. 核心源码 关键类 路径(/frameworks/base/) ActiveServices.java services/core/java/com/android/server/am/Activ ...
- Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式
前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...
- Android源码剖析之Framework层基础版(窗口、linux、token、Binder)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于Framework,就是应用层底下的控制层,离应用层最近,总想找个机会,写写WindowMang ...
- Android基础总结(8)——服务
服务(Service)是Android中实现程序后台运行的解决方案,它非常适合用于去执行哪些不需要和用户交互而且还要长期运行的任务.服务的运行不依赖任何用户界面,即使当程序被切换到后台,或者用户打开了 ...
- Android UI基础教程 目录
从csdn下载了这本英文版的书之后,又去京东搞了一个中文目录下来.对照着看. 话说,这本书绝对超值.有money的童鞋看完英文版记得去买中文版的~~ Android UI基础教程完整英文版 pdf+源 ...
- Android 系统稳定性 - ANR(一)
文章都为原创,转载请注明出处,未经允许而盗用者追究法律责任.很久之前写的了,留着有点浪费,共享之.编写者:李文栋 如果你是一个Android应用程序开发人员,你的人生中不可避免的三件事情是:死亡.缴 ...
- BroadcastReceiver基础总结
BroadcastReceiver基础总结 BroadcastReceiver是Android四大组件之一,主要负责接收系统或其他程序发出的广播,在开发中,通常用做事件驱动的起源,比如开机就要开启一个 ...
- Android Service基础
Service Service 是一个组件,用来执行长时间的后台操作,不提供用户界面. 另一个应用组件可以启动一个Service,它将持续地在后台运行,即便是用户转移到另一个应用它也不会停止. 另外, ...
- Android基础知识(一)
前言 前言 从软件测试最终目的发现问题缺陷来看,Findyou比较认同一个观念,测试的能力大致可以划分成三个能力层次:发现问题.定位问题.预防问题.有机会探讨一下这个分类. 发现问题各种方式方法,比如 ...
随机推荐
- codevs 2639 约会计划
codevs 2639 约会计划 题目描述 Description cc是个超级帅哥,口才又好,rp极高(这句话似乎降rp),又非常的幽默,所以很多mm都跟他关系不错.然而,最关键的是,cc能够很好的 ...
- 【HNOI2015】落忆枫音
题面 题解 求一个有特殊性质的有向图的生成树的个数. 首先,有向图的生成树的个数可以用矩阵树定理,能够得到\(40\)分. 但是如果它是一个\(\mathrm{DAG}\)就很好做,枚举每一个点的父亲 ...
- Ceph学习之路(三)Ceph luminous版本部署
1.配置ceph.repo并安装批量管理工具ceph-deploy [root@ceph-node1 ~]# vim /etc/yum.repos.d/ceph.repo [ceph] name=Ce ...
- 更改VS Code界面为简体中文
.先看一下效果(请忽略我的颜色主题): 1. 点击侧边栏的“扩展”按钮,或者按下Ctrl+Shift+X,安装需要的语言包 2. 通过命令面板设置语言 点击“查看”——“命令面板”,或者快捷键Ctr ...
- [Java] Design Pattern:Code Shape - manage your code shape
[Java] Design Pattern:Code Shape - manage your code shape Code Shape Design Pattern Here I will intr ...
- Http protocal
https://tools.ietf.org/html/rfc2616 1. 状态码:status code 1xxx:信息--请求被接收,继续下一步处理 2xxx:成功--请求行为被 ...
- PHPCMS增加SEO字段调用
alter table v9_site add site_title_index varchar(255) not null;alter table v9_site add keywords_ind ...
- 学习笔记 | Github
Github教程 \(Github\)是个好东西QwQ 存代码不用U盘爸爸妈妈再也不用担心我的U盘弄丢没有备份啦! 创建github账号 创建仓库 输入命令 git clone https://git ...
- js传输txt文档内容
要求:实现修改text文档内容,即可将text修改内容传到页面显示: HTML: <!doctype html> <html lang="en"> < ...
- HDU 1556 Color the ball (一维树状数组,区间更新,单点查询)
中文题,题意就不说了 一开始接触树状数组时,只知道“单点更新,区间求和”的功能,没想到还有“区间更新,单点查询”的作用. 树状数组有两种用途(以一维树状数组举例): 1.单点更新,区间查询(即求和) ...