anr用户无响应问题的解决

时间:2022-09-16 18:02:27

1、这几天总是出现用户无响应的问题,查日志,有个报错信息:

01-01 00:46:05.679 782-782/? D/CrashAnrDetector: Process: com.***.instance
Flags: 0xd8be46
Package: com.***.instance v405 (4.0.5)
Subject: Executing service com.***.instance/io.rong.imlib.ReConnectService
Build: samsung/matissewifizc/matissewifi:4.4.2/KOT49H/T530ZCU1ANI1:user/release-keys

CPU usage from 50167ms to 0ms ago with 99% awake:
  14% 28041/com.***.instance: 14% user + 0.3% kernel / faults: 864 minor
  2.7% 782/system_server: 2% user + 0.7% kernel / faults: 7696 minor
  0.6% 245/surfaceflinger: 0.4% user + 0.2% kernel / faults: 26 minor
  0.6% 1122/com.android.systemui: 0.5% user + 0% kernel / faults: 28 minor
  0.3% 542/kworker/u:2H: 0% user + 0.3% kernel
  0.3% 1946/mpdecision: 0% user + 0.3% kernel
  0.2% 215/kworker/u:6: 0% user + 0.2% kernel
  0.2% 8149/adbd: 0% user + 0.2% kernel
  0.1% 10752/watchdogd: 0% user + 0.1% kernel
  0.1% 11442/watchdogd: 0% user + 0.1% kernel
  0.1% 28985/kworker/u:2: 0% user + 0.1% kernel
  0.1% 3/ksoftirqd/0: 0% user + 0.1% kernel
  0% 32467/logcat: 0% user + 0% kernel
  0% 1//init: 0% user + 0% kernel / faults: 99 minor
  0% 222/healthd: 0% user + 0% kernel
  0% 513/mdss_fb0: 0% user + 0% kernel
  0% 26309/kworker/0:0: 0% user + 0% kernel
  0% 7/kworker/u:0H: 0% user + 0% kernel
  0% 31951/kworker/0:0H: 0% user + 0% kernel
  0% 223/servicemanager: 0% user + 0% kernel
  0% 232/edmaudit: 0% user + 0% kernel
  0% 1715/com.sec.phone: 0% user + 0% kernel / faults: 3 minor
  0% 3311/MC_Thread: 0% user + 0% kernel
  0% 3323/wpa_supplicant: 0% user + 0% kernel
  0% 7114/kworker/0:3H: 0% user + 0% kernel
  0% 19576/arield: 0% user + 0% kernel / faults: 12 minor
  0% 21016/com.android.settings: 0% user + 0% kernel
  0% 147/mmcqd/0: 0% user + 0% kernel
  0% 236/smdexe: 0% user + 0% kernel
  0% 267/qrngd: 0% user + 0% kernel
  0% 1284/com.baidu.map.location: 0% user + 0% kernel
  0% 1314/com.android.phone: 0% user + 0% kernel
  0% 3313/RX_Thread: 0% user + 0% kernel
  0% 3678/com.sec.android.app.launcher: 0% user + 0% kernel / faults: 1 minor
  0% 9520/253: 0% user + 0% kernel
  0% 18917/kworker/u:1: 0% user + 0% kernel
  0% 19868/com.sec.android.widgetapp.at.hero.cmaweather: 0% user + 0% kernel / faults: 16 minor
  0% 19954/com.kingroot.kinguser:service: 0% user + 0% kernel / faults: 2 minor
  0% 24608/com.sec.android.nearby.mediaserver:server: 0% user + 0% kernel
  0% 27086/com.***.instance:xg_service_v2: 0% user + 0% kernel
  0% 28140/com.***.instance:ipc: 0% user + 0% kernel
18% TOTAL: 15% user + 3.3% kernel + 0% iowait + 0% softirq
01-01 00:46:05.679 782-782/? D/CrashAnrDetector: processName: com.***.instance
01-01 00:46:05.679 782-782/? D/CrashAnrDetector: broadcastEvent : com.***.instance data_app_anr
2、一看就是融云的reconnectService在后台给我整崩了,干他,屏蔽。

3、还报错,找报错信息:

01-03 20:57:48.164 1085-1085/? D/CrashAnrDetector: Process: com.***.hxmonline:xg_service_v2
  Flags: 0xd8be46
  Package: com.***.hxmonline v405 (4.0.5)
  Subject: Executing service com.***.hxmonline/com.tencent.android.tpush.service.XGPushService
  Build: samsung/matissewifizc/matissewifi:4.4.2/KOT49H/T530ZCU1ANI1:user/release-keys
  
  CPU usage from 4952ms to -5112ms ago with 99% awake:
    91% 8077/com.***.hxmonline: 85% user + 6.1% kernel / faults: 21754 minor 2 major
    18% 275/mm-qcamera-daemon: 17% user + 1.1% kernel
    14% 1085/system_server: 11% user + 3.4% kernel / faults: 539 minor
    9.3% 249/surfaceflinger: 3.9% user + 5.3% kernel
    7.5% 252/mediaserver: 7.1% user + 0.3% kernel / faults: 8 minor
    0.2% 1044/debuggerd_real: 0.1% user + 0.1% kernel / faults: 5368 minor
    3.8% 321/adbd: 0.4% user + 3.3% kernel
    2.2% 11801/logcat: 0.8% user + 1.3% kernel
    1.4% 1974/com.android.systemui: 1% user + 0.3% kernel / faults: 4 minor
    1.2% 629/mdss_fb0: 0% user + 1.2% kernel
    0.2% 7403/com.kingroot.kinguser:service: 0.1% user + 0% kernel / faults: 141 minor
    0.1% 2218/com.baidu.map.location: 0.1% user + 0% kernel / faults: 234 minor 1 major
    0.4% 2322/com.android.phone: 0.2% user + 0.1% kernel
    0.4% 4210/mpdecision: 0% user + 0.4% kernel
    0.4% 11635/com.***.hxmonline:xg_service_v2: 0.3% user + 0% kernel / faults: 147 minor
    0.4% 19800/kworker/u:3: 0% user + 0.4% kernel
    0.4% 29597/kworker/u:1: 0% user + 0.4% kernel
    0.3% 12211/kworker/u:5: 0% user + 0.3% kernel
    0.2% 3/ksoftirqd/0: 0% user + 0.2% kernel
    0% 3864/com.sec.knox.seandroid: 0% user + 0% kernel
    0.1% 27/kworker/0:1H: 0% user + 0.1% kernel
    0.1% 1148/kworker/0:2H: 0% user + 0.1% kernel
    0% 2262/com.sec.knox.eventsmanager: 0% user + 0% kernel
    0% 2897/com.sec.android.provider.logsprovider: 0% user + 0% kernel
    0.1% 4207/watchdogd: 0.1% user + 0% kernel
    0.1% 12243/ksoftirqd/1: 0% user + 0.1% kernel
    0.1% 12244/kworker/1:1: 0% user + 0.1% kernel
    0% 1//init: 0% user + 0% kernel / faults: 47 minor
    0% 7/kworker/u:0H: 0% user + 0% kernel
    0% 33/kworker/u:1H: 0% user + 0% kernel
    0% 147/mmcqd/0: 0% user + 0% kernel
    0% 774/watchdogd: 0% user + 0% kernel
    0% 1430/kworker/0:1: 0% user + 0% kernel
    0% 7333/MC_Thread: 0% user + 0% kernel
    0% 7334/TX_Thread: 0% user + 0% kernel
    0% 7335/RX_Thread: 0% user + 0% kernel
    0% 29217/kworker/0:0: 0% user + 0% kernel
   +0% 12324/kworker/1:2: 0% user + 0% kernel
   +0% 12361/migration/2: 0% user + 0% kernel
   +0% 12362/kworker/2:0: 0% user + 0% kernel
   +0% 12363/kworker/2:0H: 0% user + 0% kernel
   +0% 12364/ksoftirqd/2: 0% user + 0% kernel
   +0% 12365/kworker/2:1: 0% user + 0% kernel
  60% TOTAL: 49% user + 10% kernel + 0.1% softirq
4、信鸽的后台service咋也有问题,暂时都先屏蔽掉。

5、还(zhen)有(shi)问(fu)题(le)

6、这回后台不报错了,只能去/data/log下面看日志了,有个dumpstate_app_anr.txt的文件,上里面瞅瞅,还看到了另外一个出错信息:

05-27 11:01:19.684  1079  1500 I am_anr  : [0,15000,com.***.hxm,16301638,Executing service com.***.hxm/com.***.B_ApplicationClass.HXMMobileStudyService]
7、这里有什么阻碍线程的操作么,费解

8、又找到个报错service:

01-03 20:57:48.494 1085-1085/? D/CrashAnrDetector: Process: com.***.hxmonline
Flags: 0xd8be46
Package: com.***.hxmonline v405 (4.0.5)
Subject: Executing service com.***.hxmonline/com.***.B_ApplicationClass.TCPSendRetryService
Build: samsung/matissewifizc/matissewifi:4.4.2/KOT49H/T530ZCU1ANI1:user/release-keys
CPU usage from 41ms to -5198ms ago:
  76% 8077/com.***.hxmonline: 71% user + 4.3% kernel / faults: 8219 minor
  33% 1085/system_server: 25% user + 7.4% kernel / faults: 1546 minor 1 major
  17% 275/mm-qcamera-daemon: 17% user + 0.3% kernel
  9.3% 1044/debuggerd_real: 5.1% user + 4.1% kernel / faults: 5366 minor
  7.8% 249/surfaceflinger: 3.4% user + 4.3% kernel
  5.9% 252/mediaserver: 5.9% user + 0% kernel / faults: 3 minor
  3.4% 321/adbd: 0.7% user + 2.6% kernel
  2% 11801/logcat: 0.5% user + 1.5% kernel
  1.9% 1974/com.android.systemui: 1.5% user + 0.3% kernel / faults: 2 minor
  1.1% 4210/mpdecision: 0% user + 1.1% kernel
  0.9% 629/mdss_fb0: 0% user + 0.9% kernel
  0.7% 2322/com.android.phone: 0.1% user + 0.5% kernel
  0.1% 3531/arield: 0% user + 0% kernel / faults: 11 minor
  0.3% 33/kworker/u:1H: 0% user + 0.3% kernel
  0.3% 2262/com.sec.knox.eventsmanager: 0.1% user + 0.1% kernel
  0.3% 2897/com.sec.android.provider.logsprovider: 0.1% user + 0.1% kernel
  0.3% 3864/com.sec.knox.seandroid: 0.1% user + 0.1% kernel
  0.3% 12211/kworker/u:5: 0% user + 0.3% kernel
  0.3% 19800/kworker/u:3: 0% user + 0.3% kernel
  0.1% 3/ksoftirqd/0: 0% user + 0.1% kernel
  0% 238/netd: 0% user + 0% kernel / faults: 8 minor
  0.1% 774/watchdogd: 0% user + 0.1% kernel
  0.1% 1148/kworker/0:2H: 0% user + 0.1% kernel
  0.1% 1430/kworker/0:1: 0% user + 0.1% kernel
  0% 1542/com.samsung.android.MtpApplication: 0% user + 0% kernel
  0% 6962/kworker/u:4: 0% user + 0% kernel
  0.1% 29597/kworker/u:1: 0% user + 0.1% kernel
 +0% 12389/migration/1: 0% user + 0% kernel
 +0% 12390/kworker/1:0: 0% user + 0% kernel
 +0% 12391/kworker/1:0H: 0% user + 0% kernel
 +0% 12392/ksoftirqd/1: 0% user + 0% kernel
 +0% 12409/kworker/1:1: 0% user + 0% kernel
 +0% 12411/migration/2: 0% user + 0% kernel
 +0% 12412/kworker/2:0: 0% user + 0% kernel
 +0% 12413/kworker/2:0H: 0% user + 0% kernel
 +0% 12414/ksoftirqd/2: 0% user + 0% kernel
 +0% 12415/kworker/2:1: 0% user + 0% kernel
61% TOTAL: 48% user + 12% kernel + 0.4% iowait + 0.2% softirq
9、这是个定时发送tcp消息的service,顿时灵感来了,是不是发送tcp消息的时候堵住了,导致了service无响应,而且

HXMMobileStudyService中有链接tcp逻辑的代码,所以anr错误提示中也会有这个service的报错信息

10、service中处理逻辑也是在主线程中,所以service堵了也相当于主线程堵了。

11、把所有链接tcp代码和发送tcp代码,都放到线程池中加载

12、问题解决!!!融云和信鸽不知道什么鬼,service里怎么各种anr