看似CPU高实则内存高的ANR分析

看似CPU高实则内存高的ANR分析

2020-03-09 13:5:05发布 浏览数:6747
概述:看似CPU高实则内存高的ANR分析

有时候遇到一个ANR,可能单看ANR报错还有点无从下手,那么还需要更深入的分析一下日志,从logcat、traces.txt等,如果trace.txt没看出来啥,就多啃啃logcat信息,一定能有所发现。记一次看似CPU消耗,实则是内存不足引起的ANR:

  1. 遇到ANR,logcat报错点如下
E ActivityManager: ANR in com.xin.rx
E ActivityManager: PID: 22280
E ActivityManager: Reason: Broadcast of Intent { act=android.intent.action.TIME_TICK flg=0x50000014 (has extras) }
E ActivityManager: Load: 17.51 / 15.34 / 12.68
#这里能看到CPU消耗高太高
E ActivityManager: CPU usage from 0ms to 10918ms later (2019-05-16 20:24:11.724 to 2019-05-16 20:24:22.642) with 99% awake:
E ActivityManager:   135% 3802/businessxin: 98% user + 37% kernel / faults: 15878 minor 463 major
#打印内存交换
E ActivityManager:   83% 173/kswapd0: 0% user + 83% kernel
E ActivityManager:   26% 1619/system_server: 4.4% user + 21% kernel / faults: 27401 minor 1591 major
E ActivityManager:   21% 376/mmc-cmdqd/0: 0% user + 21% kernel
E ActivityManager:   16% 22280/com.xin.rx: 1.7% user + 14% kernel / faults: 23542 minor 2243 major
E ActivityManager:   10% 26976/com.android.deskclock: 0.4% user + 9.7% kernel / faults: 17079 minor 1641 major
E ActivityManager:   9.9% 833/mm-qcamera-daemon: 6% user + 3.9% kernel / faults: 7351 minor 10 major
E ActivityManager:   7.4% 26972/app_process: 1.8% user + 5.5% kernel / faults: 22889 minor 1612 major
E ActivityManager:   5.1% 2572/.dataservices: 0.4% user + 4.6% kernel / faults: 5551 minor 1004 major
E ActivityManager:   4.3% 821/netd: 1.1% user + 3.1% kernel / faults: 942 minor
E ActivityManager:   3.8% 3958/networkxin 2.5% kernel / faults: 6581 minor 150 major
E ActivityManager:   3.2% 2448/VosRXThread: 0% user + 3.2% kernel
E ActivityManager:   3% 2031/com.android.phone: 0% user + 3% kernel / faults: 10635 minor 514 major
E ActivityManager:   2.9% 1889/com.android.systemui: 0.3% user + 2.6% kernel / faults: 7938 minor 316 major
E ActivityManager:   2.8% 2447/VosTXThread: 0% user + 2.8% kernel
E ActivityManager:   2.7% 404/logd: 0.2% user + 2.4% kernel / faults: 1720 minor 9 major
E ActivityManager:   2.6% 9183/kworker/u16:1: 0% user + 2.6% kernel
E ActivityManager:   2.4% 30214/kworker/u16:2: 0% user + 2.4% kernel
E ActivityManager:   2.4% 21442/kworker/u16:7: 0% user + 2.4% kernel
E ActivityManager:   2.1% 4023/business2: 0.8% user + 1.3% kernel / faults: 5682 minor 88 major
E ActivityManager:   1.7% 22277/kworker/u16:3: 0% user + 1.7% kernel
E ActivityManager:   1.2% 387/kworker/5:1H: 0% user + 1.2% kernel
E ActivityManager:   1.1% 50/ksoftirqd/5: 0% user + 1.1% kernel
E ActivityManager:   1.1% 2612/com.qualcomm.qti.services.secureui:sui_service: 0.3% user + 0.8% kernel / faults: 2156 minor 200 major
E ActivityManager:   0% 2602/com.oma.drm.server: 0% user + 0% kernel / faults: 2467 minor 129 major
E ActivityManager:   0% 2580/com.qualcomm.qti.loadcarrier: 0% user + 0% kernel / faults: 2221 minor 129 major
E ActivityManager:   0.5% 6/kworker/u16:0: 0% user + 0.5% kernel
E ActivityManager:   0.5% 2559/com.android.nfc: 0.2% user + 0.2% kernel / faults: 2000 minor 97 major
E ActivityManager:   0.4% 822/rild: 0% user + 0.4% kernel / faults: 571 minor 51 major
E ActivityManager:   0.4% 1943/sdcard: 0% user + 0.4% kernel / faults: 714 minor 3 major
E ActivityManager:   0.4% 4005/streamaxfcgi: 0.2% user + 0.1% kernel / faults: 1959 minor 20 major
E ActivityManager:   0.3% 380/usb-storage: 0% user + 0.3% kernel
E ActivityManager:   0.2% 7/rcu_preempt: 0% user + 0.2% kernel
E ActivityManager:   0.2% 61/rcuop/6: 0% user + 0.2% kernel
E ActivityManager:   0.2% 66/ksoftirqd/7: 0% user + 0.2% kernel
E ActivityManager:   0.2% 706/jbd2/dm-0-8: 0% user + 0.2% kernel
E ActivityManager:   0.2% 26127/kworker/5:2: 0% user + 0.2% kernel
E ActivityManager:   0.1% 45/rcuop/4: 0% user + 0.1% kernel
E ActivityManager:   0.1% 69/rcuop/7: 0% user + 0.1% kernel
E ActivityManager:   0.1% 381/mmcqd/1: 0% user + 0.1% kernel
E ActivityManager:   0% 414/debuggerd: 0% user + 0% kernel / faults: 427 minor 41 major
E ActivityManager:   0.1% 415/debuggerd64: 0% user + 0.1% kernel / faults: 413 minor 16 major
E ActivityManager:   0.1% 546/surfaceflinger: 0% user + 0.1% kernel / faults: 426 minor 20 major
E ActivityManager:   0.1% 570/logcat: 0.1% user + 0% kernel / faults: 1055 minor 1 major
E ActivityManager:   0% 2444/VosWDThread: 0% user + 0% kernel
E ActivityManager:   0.1% 3742/logcat: 0% user + 0% kernel / faults: 1062 minor 1 major
E ActivityManager:   0.1% 22285/kworker/4:1: 0% user + 0.1% kernel
E ActivityManager:   0.1% 26585/kworker/0:0: 0% user + 0.1% kernel
E ActivityManager:   0% 3/ksoftirqd/0: 0% user + 0% kernel
E ActivityManager:   0% 10/rcuop/0: 0% user + 0% kernel
E ActivityManager:   0% 18/ksoftirqd/1: 0% user + 0% kernel
E ActivityManager:   0% 29/rcuop/2: 0% user + 0% kernel
E ActivityManager:   0% 34/ksoftirqd/3: 0% user + 0% kernel
E ActivityManager:   0% 37/rcuop/3: 0% user + 0% kernel
E ActivityManager:   0% 42/ksoftirqd/4: 0% user + 0% kernel
E ActivityManager:   0% 53/rcuop/5: 0% user + 0% kernel
E ActivityManager:   0% 337/irq/162-spdm_bw: 0% user + 0% kernel
E ActivityManager:   0% 405/kworker/0:1H: 0% user + 0% kernel
E ActivityManager:   0% 416/vold: 0% user + 0% kernel / faults: 418 minor 11 major
E ActivityManager:   0% 422/kworker/6:1H: 0% user + 0% kernel
E ActivityManager:   0% 545/servicemanager: 0% user + 0% kernel / faults: 778 minor 8 major
E ActivityManager:   0% 703/kworker/1:1H: 0% user + 0% kernel
E ActivityManager:   0% 722/ptt_socket_app: 0% user + 0% kernel / faults: 192 minor 8 major
E ActivityManager:   0% 724/cnss_diag: 0% user + 0%
I art     : Wrote stack traces to '/data/anr/traces.txt'
I art     : Wrote stack traces to '/data/anr/traces.txt'
E pttSocketApp:          aniAsfIpc.c:971 Error(105):Recv failed, ipcPtr [0xad631000], sd 4
E pttSocketApp:       pttSocketApp.c:759 IPC Recv failed

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576

看到该日志的ANR,是从Android应用里爆出来的,但怎么看都不像是这个应用的问题

  1. 查看ANR信息:


发现有cpu相关信息,CPU usage,说明是当时cpu负载太高,应用分的时间片太少,执行不及时造成的假象ANR 再看kswapd0: 0% user + 83% kernel:swap分区有一个作用,在内存不足的时候,硬盘上一部分当做虚拟内存来使用,而kswapd0进程,一般是内存不足了,使用swap分区与内存换页操作交换数据,十分耗CPU,就导致了CPU的高负荷

知道了CPU为什么高负荷,是因为内存不足,但是没有其他信息了啊,还得继续分析

  1. 从ANR日志时间点往前看
ActivityManager: Low on memory:
ActivityManager:   ntv   N   763042: networkxin (pid 3958) native
ActivityManager:   ntv   N    61606: businessxin (pid 3802) native
ActivityManager:   ntv   N    42253: mm-qcamera-daemon (    3,724K memtrack) (pid 833) native
ActivityManager:   ntv   N    29819: surfaceflinger (   17,808K memtrack) (pid 546) native
ActivityManager:   ntv   N    10412: media.codec (      504K memtrack) (pid 817) native
ActivityManager:   ntv   N     7871: app_process (pid 27764) native
ActivityManager:   ntv   N     7434: netmgrd (pid 908) native
ActivityManager:   ntv   N     7269: audioserver (pid 808) native
ActivityManager:   ntv   N     6645: rild (pid 822) native
ActivityManager:   ntv   N     6068: <pre-initialized> (pid 27772) native
ActivityManager:   ntv   N     5793: logd (pid 404) native
ActivityManager:   ntv   N     4913: business2 (pid 4023) native
ActivityManager:   ntv   N     4770: cnd (pid 720) native
ActivityManager:   ntv   N     4691: zygote (pid 807) native
ActivityManager:   ntv   N     4275: com.android.calendar (pid 27786) native
ActivityManager:   ntv   N     4131: mm-pp-dpps (pid 575) native
ActivityManager:   ntv   N     4095: zygote64 (pid 743) native
ActivityManager:   ntv   N     4026: qseeproxydaemon (pid 831) native
ActivityManager:   ntv   N     3758: streamaxfcgi (pid 4005) native
ActivityManager:   ntv   N     3387: xtwifi-client (pid 1534) native
ActivityManager:   ntv   N     3333: cameraserver (pid 811) native
ActivityManager:   ntv   N     2933: daemon (pid 1151) native
ActivityManager:   ntv   N     2735: media.extractor (pid 819) native
ActivityManager:   ntv   N     2525: vold (pid 416) native
ActivityManager:   ntv   N     2124: mediaserver (pid 820) native
ActivityManager:   ntv   N     2033: slim_daemon (pid 1535) native
ActivityManager:   ntv   N     2021: thermal-engine (pid 731) native
ActivityManager:   ntv   N     1998: audiod (pid 837) native
ActivityManager:   ntv   N     1569: dpmd (pid 846) native
ActivityManager:   ntv   N     1563: wpa_supplicant (pid 2470) native
ActivityManager:   ntv   N     1556: /init (pid 1) native
ActivityManager:   ntv   N     1554: imsdatadaemon (pid 878) native
ActivityManager:   ntv   N     1420: drmserver (pid 814) native
ActivityManager:   ntv   N     1392: netd (pid 821) native
ActivityManager:   ntv   N     1382: sdcard (pid 1943) native
ActivityManager:   ntv   N     1351: mediadrmserver (pid 818) native
ActivityManager:   ntv   N     1309: lowi-server (pid 1532) native
ActivityManager:   ntv   N     1222: mdtpd (pid 838) native
ActivityManager:   ntv   N     1150: ipacm (pid 871) native
ActivityManager:   ntv   N     1122: time_daemon (pid 1764) native
ActivityManager:   ntv   N     1084: cnss_diag (pid 724) native
ActivityManager:   ntv   N     1047: cnss-daemon (pid 26777) native
ActivityManager:   ntv   N     1038: qti (pid 894) native
ActivityManager:   ntv   N      978: wcnss_service (pid 733) native
ActivityManager:   ntv   N      958: adsprpcd (pid 738) native
ActivityManager:   ntv   N      956: commonfs (pid 4273) native
ActivityManager:   ntv   N      942: qcom-system-daemon (pid 717) native
ActivityManager:   ntv   N      941: nginx: worker process (pid 3973) native
ActivityManager:   ntv   N      939: sensors.qcom (pid 631) native
ActivityManager:   ntv   N      918: loc_launcher (pid 827) native
ActivityManager:   ntv   N      879: pm-service (pid 542) native
ActivityManager:   ntv   N      874: ATFWD-daemon (pid 829) native
ActivityManager:   ntv   N      866: keystore (pid 816) native
ActivityManager:   ntv   N      854: xtwifi-inet-agent (pid 1533) native
ActivityManager:   ntv   N      766: gatekeeperd (pid 839) native
ActivityManager:   ntv   N      758: perfd (pid 427) native
ActivityManager:   ntv   N      746: commonfs (pid 4041) native
ActivityManager:   ntv   N      738: installd (pid 815) native
ActivityManager:   ntv   N      736: lmkd (pid 544) native
ActivityManager:   ntv   N      726: qseecomd (pid 606) native
ActivityManager:   ntv   N      726: imsqmidaemon (pid 734) native
ActivityManager:   ntv   N      706: pm-proxy (pid 576) native
ActivityManager:   ntv   N      690: servicemanager (pid 545) native
ActivityManager:   ntv   N      679: esepmdaemon (pid 538) native
ActivityManager:   ntv   N      672: ueventd (pid 382) native
ActivityManager:   ntv   N      665: ptt_socket_app (pid 722) native
ActivityManager:   ntv   N      610: logcat (pid 570) native
ActivityManager:   ntv   N      610: ipacm-diag (pid 848) native
ActivityManager:   ntv   N      601: rmt_storage (pid 533) native
ActivityManager:   ntv   N      595: tftp_server (pid 534) native
ActivityManager:   ntv   N      592: dpmd (pid 825) native
ActivityManager:   ntv   N      585: logcat (pid 3742) native
ActivityManager:   ntv   N      567: msm_irqbalance (pid 898) native
ActivityManager:   ntv   N      513: sh (pid 428) native
ActivityManager:   ntv   N     7453: (Other native)
ActivityManager:   sys   P    56781: system (pid 1619) fixed
ActivityManager:   pers  P    31196: com.android.systemui (    3,068K memtrack) (pid 1889) fixed
ActivityManager:   pers  P    19700: com.android.phone (pid 2031) fixed
ActivityManager:   pers  P     9098: .dataservices (pid 2572) fixed
ActivityManager:   pers  P     7617: com.android.nfc (pid 2559) fixed
ActivityManager:   pers  P     6229: com.qualcomm.qti.services.secureui:sui_service (pid 2612) fixed
ActivityManager:   pers  P     6186: com.oma.drm.server (pid 2602) fixed
ActivityManager:   pers  P     5795: com.qualcomm.qti.loadcarrier (pid 2580) fixed
ActivityManager:            1199160: TOTAL (   25,104K memtrack)
ActivityManager:   MemInfo:   124,172K slab,    45,092K shmem,    20,048K vm alloc,    16,092K page tables    22,640K kernel stack
ActivityManager:                1,096K buffers,   115,140K cached,    45,388K mapped,     7,772K free
ActivityManager:   ZRAM:   320,124K RAM,   524,284K swap total,         0K swap free
ActivityManager:   Free RAM:    78,620K
ActivityManager:   Used RAM: 1,427,204K
ActivityManager:   Lost RAM:    29,608K
ActivityManager: Process com.xin.rx (pid 27772) has died
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192

看到AMS有打印 Low on memory信息,看到了是哪个进程内存那么高了,就像这里的networkxin,接下来就要根据当时的场景分析,去找那个进程内存高的原因了

ps:一般不止一次报这个Low on memory,多往前搜几次,一般能找到哪个进程可能发生了内存泄漏,内存一直在增长

请先
登录
后评论
0 条评论
暂时没有评论
最新文章
更多