android如何分析进程被杀问题

查看进程被杀的3个步骤

确定被杀进程的包名

  • 有人给出直接用
  • 百度搜索app对应的包名

确定进程被杀的精确时间点

  • 有进程被杀时间点及原因包名,则直接用
  • log中搜索正则表达式(gedit支持正则)am_proc_died: [0,[0-9]*,xxxx,,xxxx代表包名 ,拿到这行log的时间点以及进程pid

eg: 08-19 10:06:55.302 1000 1699 12137 I am_proc_died: [0,9307,com.quark.browser,905,11]
如上栗子:时间点为08-19 10:06:55.302 (搜索时可自行减几毫秒,否则可能搜索不到同时间点的其他log),进程pid为9307

查看进程被杀原因

  • 在system log(logcat -v 下面)或event log(logcat -b events下面)搜索2中时间点附近对应pid的log
    12-16 15:46:10.814 root 756 756 I Zygote : Process 9187 exited due to signal 11 (Segmentation fault)
    12-16 15:46:10.830 1000 1747 2367 I ActivityManager: Process com.tencent.mm (pid 9187) has died: fg TOP
  • 或者搜索对应包名的ApplicationExitInfo
    ApplicationExitInfo #14:
    timestamp=2020-12-16 15:45:08.647
    pid=6175
    realUid=10249
    packageUid=10249
    definingUid=10249
    user=0
    process=com.tencent.mm
    reason=2 (SIGNALED)
    status=11

    importance=100
    pss=204MB
    rss=311MB
    description=null
    state=empty
    trace=null

常见的查杀类型

LowMemoryKiller(低内存查杀)

原因查找:

  1. 直接搜索lowmemorykiller: Kill ‘com.xxx.xxx’ (pid)
    08-19 10:06:55.207 lmkd 954 954 E lowmemorykiller: Kill ‘com.quark.browser’ (9307), uid 10248, oom_adj 905 to free 69048kB
    08-19 10:06:55.207 lmkd 954 954 I lowmemorykiller: Reclaimed 69048kB, cache(718372kB) and free(314436kB)-reserved(43892kB) below min(765000kB) for oom_adj 900

代表:手机cache 内存为718372kb,低于oom_adj 900这个级别的最低值765000kB,所以lmkd会查杀pid为9307的com.quark.browser进程,该进程当前的adj为905(高于900),释放了69048kb

  1. 未有lowmemorykiller打印,但是am_low_memory递减同时,am_proc_died同时打印,且system log中有has died 打印
    07-30 22:18:26.746 1000 1718 5108 I ActivityManager: Process com.xiaomi.channel (pid 21963) has died: hvy HVY
    07-30 22:18:26.746 1000 1718 5127 I am_low_memory: 68
    07-30 22:18:26.746 1000 1718 5108 I am_proc_died: [0,21963,com.xiaomi.channel,400,14]
    07-30 22:18:26.803 1000 1718 5127 I am_low_memory: 66

代表:am_low_memory 后面的数字代表当前系统中lru 中进程的数量,数字递减代表有进程被杀,has died 代表非AMS查杀(lmk查杀或信号查杀),hvy HVY代表进程的优先级(进程自查一览表)

看下手机内存状态以及占内存较高的应用

log中搜索 dumpsys meminfo,赋值粘贴如下信息到jira上

  1. 内存状态信息
    Total RAM: 5,510,720K (status normal)
    Free RAM: 1,092,011K ( 31,027K cached pss + 938,028K cached kernel + 864K cached ion + 122,092K free)
    Used RAM: 5,982,010K (5,483,142K used pss + 498,868K kernel)
    Lost RAM: 266,644K
    ZRAM: 462,104K physical used for 1,590,008K in swap (3,014,028K total swap)
    Tuning: 256 (large 512), oom 967,680K, restore limit 322,560K (high-end-gfx)
    --------- 9.460s was the duration of dumpsys meminfo, ending at: 2020-08-15 12:33:59

代表如下:
手机总可用内存为5,510,720K
Free的cache 内存为31,027K cached pss
主要使用的是 5,483,142K
丢失内存:266,644K 这个值过大不正常

  1. 高优先级应用(占用达6位数的):
    Total PSS by process:
    509,265K: com.tencent.mm (pid 8448 / activities) ( 148,217K in swap)
    315,084K: com.miui.miwallpaper.earth:earthSuperWallpaper (pid 4223) ( 42,026K in swap)
    304,568K: system (pid 1699) ( 33,679K in swap)
    295,422K: com.miui.home (pid 4283 / activities) ( 107,864K in swap)
    258,716K: com.tencent.mm (pid 10718 / activities) ( 119,475K in swap)
    195,761K: [email protected]_64 (pid 847) ( 194,356K in swap)
    170,929K: com.tencent.mm:tools (pid 25205) ( 136K in swap)
    170,385K: surfaceflinger (pid 956) ( 7,976K in swap)
    163,051K: com.android.systemui (pid 4066) ( 61,983K in swap)
    140,609K: com.xiaomi.smarthome (pid 10748) ( 75,044K in swap)
    104,044K: com.tencent.mobileqq (pid 17557) ( 589K in swap)

正常查杀empty进程

  • 08-10 13:32:13.057 1000 1700 1812 I am_kill : [0,2409,com.miui.screenrecorder,955,empty for 1800s]
    empty进程数量达到阈值了,会查杀30min内没活跃的进程
  • 08-10 16:00:54.244 1000 1700 1795 I ActivityManager: Killing 20081:com.android.providers.calendar/u0a72 (adj 985): empty #26
    系统内empty进程数量达到阈值26(不同手机略有不同)会按时间顺序查杀进程

客户端调用startInstrumentation,会先forceStopPackage再拉起,可能会查杀到相关的其他进程

08-03 15:10:02.933 1000 1303 12534 I ActivityManager: Force stopping com.eg.android.AlipayGphone appid=10198 user=0: start instr
08-03 15:10:02.933 1000 1303 12534 I ActivityManager: Killing 1441:com.kugou.android/u0a219 (adj 0): stop com.eg.android.AlipayGphone: start instr

进程自己退出

08-13 10:17:04.053 root 689 689 I Zygote : Process 29263 exited cleanly (0)
08-13 10:17:04.056 1000 1692 1805 I libprocessgroup: Successfully killed process cgroup uid 10252 pid 29263 in 122ms
08-13 10:17:03.933 1000 1692 5189 I ActivityManager: Process com.tencent.tmgp.pubgmhd (pid 29263) has died: hvy HVY

idle maint查杀

设备处于两次idle之间低内存状态持续时间超1/3,会查杀内存增长较高的进程,原生策略。
08-14 09:43:55.617 1000 1477 1779 I am_wtf : [0,1477,system_server,-1,ActivityManager,Killcom.tencent.mm in idle maint: pss=365677, swapPss=174343, initialPss=173858, period=+1h17m4s218ms, lowRamPeriod=+1h8m19s250ms]
08-14 09:43:55.625 1000 1477 1477 I am_kill : [0,17579,com.byai.crm,100,idle maint (pss 165820 from 95133)]
08-14 09:43:55.772 1041 664 31875 I [30200] : 17579&10168&0&-1
08-14 09:43:55.724 1000 1477 1514 I am_proc_died: [0,17579,com.byai.crm,100,4]

installPackageLI/ deletePackageX等

只要是forceStopPackage接口查杀就有可能查杀到关联的进程,如下拨号就是因为与gms关联被杀

08-10 15:59:30.827 1000 1700 1812 I ActivityManager: Force stopping com.google.android.gms appid=10190 user=-1: installPackageLI
08-10 15:59:30.984 1000 1700 1812 I ActivityManager: Killing 3876:com.google.android.dialer/u0a180 (adj -700): stop com.google.android.gms: installPackageLI

过渡使用CPU

09-06 18:07:44.445 1000 1651 1798 I am_kill : [0,22157,com.ximalaya.ting.android,900,excessive cpu 16720 during 300044 dur=2221553 limit=2]
09-06 18:07:44.445 1000 1651 1798 I ActivityManager: Killing 22157:com.ximalaya.ting.android/u0a239 (adj 900): excessive cpu 16720 during 300044 dur=2221553 limit=2
09-06 18:07:44.566 root 681 681 I Zygote : Process 22157 exited due to signal 9 (Killed)

上次adj降为Service以下到现在经历2221553 ms,cpu POWER_CHECK_MAX_CPU_4 = 2, 两次检测时间间隔为300044 ms,使用cpu时间为16720ms,超过2%

进程的某个线程发生异常,自己发Signal 9信号给Zygote 杀掉自己

09-07 16:53:03.027 1000 2566 2582 I Process : Sending signal. PID: 2566 SIG: 9
09-07 16:53:03.154 root 681 681 I Zygote : Process 2566 exited due to signal 9 (Killed)
09-07 16:53:03.167 1000 1734 4006 I ActivityManager: Process com.android.systemui (pid 2566) has died: pers PER

进程发生未捕获异常自杀

06-21 18:06:55.108 10261 12675 12675 I Process : Process is going to kill itself!
06-21 18:06:55.108 10261 12675 12675 I Process : java.lang.Exception
06-21 18:06:55.108 10261 12675 12675 I Process : at android.os.Process.killProcess(Process.java:1350)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:183)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.dragon.read.app.y$1.uncaughtException(SourceFile:33816621)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.crash.i.a.d(SourceFile:33751057)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.crash.i.a.b(SourceFile:34079314)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.crash.i.a.uncaughtException(SourceFile:33619968)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.platform.godzilla.common.d.a(SourceFile:33685510)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.platform.godzilla.common.d.uncaughtException(SourceFile:33882169)
06-21 18:06:55.108 10261 12675 12675 I Process : at org.chromium.base.JavaExceptionReporter.uncaughtException(chromium-TrichromeWebViewGoogle6432.apk-stable-567252434:17)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.n.n.el.n.u(Unknown Source:166)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.n.n.el.n.uncaughtException(Unknown Source:115)
06-21 18:06:55.108 10261 12675 12675 I Process : at com.bytedance.sdk.openadsdk.core.e.y.uncaughtException(Unknown Source:103)
06-21 18:06:55.108 10261 12675 12675 I Process : at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1071)
06-21 18:06:55.108 10261 12675 12675 I Process : at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1066)
06-21 18:06:55.108 10261 12675 12675 I Process : at java.lang.Thread.dispatchUncaughtException(Thread.java:2306)
06-21 18:06:55.108 10261 12675 12675 I Process : Sending signal. PID: 12675 SIG: 9

06-21 18:06:55.241 1000 1965 3017 I ActivityManager: Process com.dragon.read (pid 12675) has died: fg TOP
06-21 18:06:55.242 1000 1965 3017 I am_proc_died: [0,12675,com.dragon.read,0,2]

某个app调用forceStopPackage 接口

03-25 19:34:10.498 26589 29585 I ActivityManager: Killing 14459:com.xiaomi.misubscreenui/1000 (adj 0): stop com.xiaomi.misubscreenui due to from process:com.miui.voiceassist

你可能感兴趣的:(AMS,android,java)