最近客户反馈一个问题,设备偶现死机。最后解决,在此记录。
目录
[三 死机问题分析](#三 死机问题分析)
[1 死机现象的梳理](#1 死机现象的梳理)
[2 死机日志](#2 死机日志)
[2 日志分析二(正确方案)](#2 日志分析二(正确方案))
一死机的现象
设备死机,或者黑屏任何操作无响应,无法点亮屏幕;或亮屏任何操作无响应。只能断电重启。
二死机的类型
-
逻辑卡顿(block)
-
死循环 (Deadloop)
-
死锁 (Deadlock)
这次根据结果先说结论是 死锁导致死机。
三 死机问题分析
1 死机现象的梳理
客户反馈死机问题,暂无提供可复现的逻辑步骤,属于随机发生。这部使用monkey压测,出现死机行为,分析日志,每次都有不同,无法定位原因。
2 死机日志
1)日志分析一
1 开启了ylog开关后复现,都能捕获日志,有些日志就是普通的日志,有日志捕获死机日常。日志结构如下:
2 左侧文件夹traces就是死机log。分析log如下:
html
0-android.log日志文件中 看到进程全部挂掉,系统死亡。日志如下
M0164CC 11-21 11:50:59.424 366 366 I SPRDHWComposer: HWCDisplay::present_display <785>: No job to commit, return ERR_NO_JOB
M0164CD 11-21 11:50:59.417 249 249 I ServiceManager: service 'netstats' died
M0164CE 11-21 11:50:59.427 480 5944 D BufferPoolAccessor: bufferpool2 0xa7070110 : 0(0 size) total buffers - 0(0 size) used buffers - 7/10 (recycle/alloc) - 3/9 (fetch/transfer)
M0164CF 11-21 11:50:59.427 480 5939 D BufferPoolAccessor: bufferpool2 0xa706fe10 : 0(0 size) total buffers - 0(0 size) used buffers - 8/10 (recycle/alloc) - 2/9 (fetch/transfer)
M0164D0 11-21 11:50:59.427 480 5908 D BufferPoolAccessor: bufferpool2 0xa7070310 : 0(0 size) total buffers - 0(0 size) used buffers - 13/15 (recycle/alloc) - 2/14 (fetch/transfer)
M0164D1 11-21 11:50:59.427 249 249 I ServiceManager: service 'persistent_data_block' died
M0164D2 11-21 11:50:59.428 249 249 I ServiceManager: service 'netpolicy' died
M0164D3 11-21 11:50:59.428 249 249 I ServiceManager: service 'wifi' died
M0164D4 11-21 11:50:59.428 249 249 I ServiceManager: service 'wifiscanner' died
M0164D5 11-21 11:50:59.428 249 249 I ServiceManager: service 'wifip2p' died
M0164D6 11-21 11:50:59.428 249 249 I ServiceManager: service 'notification' died
M0164D7 11-21 11:50:59.428 249 249 I ServiceManager: service 'devicestoragemonitor' died
M0164D8 11-21 11:50:59.428 249 249 I ServiceManager: service 'location' died
M0164D9 11-21 11:50:59.428 249 249 I ServiceManager: service 'country_detector' died
M0164DA 11-21 11:50:59.428 249 249 I ServiceManager: service 'time_detector' died
M0164DB 11-21 11:50:59.428 249 249 I ServiceManager: service 'search' died
M0164DC 11-21 11:50:59.428 249 249 I ServiceManager: service 'wallpaper' died
M0164DD 11-21 11:50:59.428 249 249 I ServiceManager: service 'audio' died
M0164DE 11-21 11:50:59.429 249 249 I ServiceManager: service 'broadcastradio' died
M0164DF 11-21 11:50:59.429 249 249 I ServiceManager: service 'DockObserver' died
M0164E0 11-21 11:50:59.429 249 249 I ServiceManager: service 'midi' died
M0164E1 11-21 11:50:59.429 249 249 I ServiceManager: service 'adb' died
M0164E2 11-21 11:50:59.429 249 249 I ServiceManager: service 'usb' died
M0164E3 11-21 11:50:59.429 249 249 I ServiceManager: service 'serial' died
M0164E4 11-21 11:50:59.429 249 249 I ServiceManager: service 'hardware_properties' died
M0164E5 11-21 11:50:59.429 480 480 D BufferPoolAccessor: bufferpool2 0xa706fd10 : 0(0 size) total buffers - 0(0 size) used buffers - 5/7 (recycle/alloc) - 2/6 (fetch/transfer)
M0164E6 11-21 11:50:59.429 249 249 I ServiceManager: service 'color_display' died
M0164E7 11-21 11:50:59.429 5930 8561 I AudioTrack: pause
M0164E8 11-21 11:50:59.429 480 480 D BufferPoolAccessor: Destruction - bufferpool2 0xa706fd10 cached: 0/0M, 0/0% in use; allocs: 7, 71% recycled; transfers: 6, 67% unfetced
M0164E9 11-21 11:50:59.429 249 249 I ServiceManager: service 'jobscheduler' died
M0164EA 11-21 11:50:59.429 249 249 I ServiceManager: service 'soundtrigger' died
M0164EB 11-21 11:50:59.429 249 249 I ServiceManager: service 'trust' died
M0164EC 11-21 11:50:59.429 249 249 I ServiceManager: service 'backup' died
M0164ED 11-21 11:50:59.429 249 249 I ServiceManager: service 'appwidget' died
M0164EE 11-21 11:50:59.429 249 249 I ServiceManager: service 'role' died
M0164EF 11-21 11:50:59.429 249 249 I ServiceManager: service 'voiceinteraction' died
M0164F0 11-21 11:50:59.429 249 249 I ServiceManager: service 'diskstats' died
M0164F1 11-21 11:50:59.429 249 249 I ServiceManager: service 'runtime' died
M0164F2 11-21 11:50:59.429 480 5944 D BufferPoolAccessor: bufferpool2 0xa7070210 : 0(0 size) total buffers - 0(0 size) used buffers - 11/15 (recycle/alloc) - 4/14 (fetch/transfer)
M0164F3 11-21 11:50:59.429 249 249 I ServiceManager: service 'network_time_update_service' died
M0164F4 11-21 11:50:59.429 480 5944 D BufferPoolAccessor: Destruction - bufferpool2 0xa7070210 cached: 0/0M, 0/0% in use; allocs: 15, 73% recycled; transfers: 14, 71% unfetced
M0164F5 11-21 11:50:59.429 249 249 I ServiceManager: service 'dreams' died
M0164F6 11-21 11:50:59.429 249 249 I ServiceManager: service 'graphicsstats' died
M0164F7 11-21 11:50:59.429 249 249 I ServiceManager: service 'print' died
M0164F8 11-21 11:50:59.429 249 249 I ServiceManager: service 'companiondevice' died
M0164F9 11-21 11:50:59.429 249 249 I ServiceManager: service 'restrictions' died
M0164FA 11-21 11:50:59.429 249 249 I ServiceManager: service 'media_session' died
M0164FB 11-21 11:50:59.429 249 249 I ServiceManager: service 'media_resource_monitor' died
M0164FC 11-21 11:50:59.429 249 249 I ServiceManager: service 'media_router' died
M0164FD 11-21 11:50:59.429 249 249 I ServiceManager: service 'ledsrv' died
M0164FE 11-21 11:50:59.429 249 249 I ServiceManager: service 'shortcut' died
M0164FF 11-21 11:50:59.429 249 249 I ServiceManager: service 'launcherapps' died
M016500 11-21 11:50:59.429 249 249 I ServiceManager: service 'crossprofileapps' died
M016501 11-21 11:50:59.429 249 249 I ServiceManager: service 'media_projection' died
M016502 11-21 11:50:59.430 249 249 I ServiceManager: service 'slice' died
M016503 11-21 11:50:59.430 249 249 I ServiceManager: service 'media.camera.proxy' died
M016504 11-21 11:50:59.430 249 249 I ServiceManager: service 'statscompanion' died
M016505 11-21 11:50:59.430 249 249 I ServiceManager: service 'incidentcompanion' died
M016506 11-21 11:50:59.430 249 249 I ServiceManager: service 'imms' died
M016507 11-21 11:50:59.430 249 249 I ServiceManager: service 'autofill' died
M016508 11-21 11:50:59.430 249 249 I ServiceManager: service 'clipboard' died
M016509 11-21 11:50:59.430 480 5939 D BufferPoolAccessor: bufferpool2 0xa7070010 : 0(0 size) total buffers - 0(0 size) used buffers - 6/11 (recycle/alloc) - 5/10 (fetch/transfer)
M01650A 11-21 11:50:59.430 249 249 I ServiceManager: service 'app_binding' died
M01650B 11-21 11:50:59.430 249 249 I ServiceManager: service 'sprd_power' died
M01650C 11-21 11:50:59.430 480 5939 D BufferPoolAccessor: Destruction - bufferpool2 0xa7070010 cached: 0/0M, 0/0% in use; allocs: 11, 55% recycled; transfers: 10, 50% unfetced
M01650D 11-21 11:50:59.430 249 249 I ServiceManager: service 'sprdssense' died
M01650E 11-21 11:50:59.430 249 249 I ServiceManager: service 'bluetooth_manager' died
M01650F 11-21 11:50:59.430 249 249 I ServiceManager: service 'connmetrics' died
M016510 11-21 11:50:59.430 249 249 I ServiceManager: service 'netd_listener' died
M016511 11-21 11:50:59.430 249 249 I ServiceManager: service 'contexthub' died
M016512 11-21 11:50:59.430 249 249 I ServiceManager: service 'power_ex' died
M016513 11-21 11:50:59.430 249 249 I ServiceManager: service 'otadexopt' died
M016514 11-21 11:50:59.430 249 249 I ServiceManager: service 'user' died
M016515 11-21 11:50:59.430 249 249 I ServiceManager: service 'activity' died
M016516 11-21 11:50:59.430 5927 5927 I Zygote : Process 6082 exited due to signal 9 (Killed)
M016517 11-21 11:50:59.431 5927 5927 E Zygote : Exit zygote because system server (pid 6082) has terminated
M016518 11-21 11:50:59.432 5927 5927 D Zygote : SprdDebug set prop ret = 0
M016519 11-21 11:50:59.432 480 5939 D BufferPoolAccessor: Destruction - bufferpool2 0xa7070110 cached: 0/0M, 0/0% in use; allocs: 10, 70% recycled; transfers: 9, 67% unfetced
M01651A 11-21 11:50:59.433 480 5944 D BufferPoolAccessor: Destruction - bufferpool2 0xa7070310 cached: 0/0M, 0/0% in use; allocs: 15, 87% recycled; transfers: 14, 86% unfetced
M01651B 11-21 11:50:59.433 480 480 D BufferPoolAccessor: Destruction - bufferpool2 0xa706fe10 cached: 0/0M, 0/0% in use; allocs: 10, 80% recycled; transfers: 9, 78% unfetced
M01651C 11-21 11:50:59.435 366 366 D SPRDHWComposer: SprdPrimaryDisplayDevice::commit <784>: No Job to commit, totalLayerCount = 0
M01651D 11-21 11:50:59.435 366 366 I SPRDHWComposer: HWCDisplay::present_display <785>: No job to commit, return ERR_NO_JOB
M01651E 11-21 11:50:59.437 6281 6281 D AndroidRuntime: Shutting down VM
C01651F 11-21 11:50:59.437 6281 6281 E AndroidRuntime: FATAL EXCEPTION: main
C01651F 11-21 11:50:59.437 6281 6281 E AndroidRuntime: Process: com.android.phone, PID: 6281
C01651F 11-21 11:50:59.437 6281 6281 E AndroidRuntime: DeadSystemException: The system died; earlier logs will point to the root cause
M016520 11-21 11:50:59.439 249 249 I ServiceManager: service 'procstats' died
M016521 11-21 11:50:59.439 249 249 I ServiceManager: service 'meminfo' died
M016522 11-21 11:50:59.439 249 249 I ServiceManager: service 'gfxinfo' died
M016523 11-21 11:50:59.439 249 249 I ServiceManager: service 'dbinfo' died
M016524 11-21 11:50:59.439 249 249 I ServiceManager: service 'cpuinfo' died
M016525 11-21 11:50:59.439 249 249 I ServiceManager: service 'permission' died
M016526 11-21 11:50:59.439 249 249 I ServiceManager: service 'processinfo' died
M016527 11-21 11:50:59.439 249 249 I ServiceManager: service 'overlay' died
M016528 11-21 11:50:59.439 249 249 I ServiceManager: service 'sensor_privacy' died
M016529 11-21 11:50:59.439 249 249 I ServiceManager: service 'sensorservice' died
M01652A 11-21 11:50:59.439 5931 6023 E IPCThreadState: attemptIncStrongHandle(4): Not supported
M01652B 11-21 11:50:59.439 249 249 I ServiceManager: service 'ethernet' died
M01652C 11-21 11:50:59.439 249 249 I ServiceManager: service 'battery' died
M01652D 11-21 11:50:59.439 249 249 I ServiceManager: service 'batteryproperties' died
M01652E 11-21 11:50:59.439 249 249 I ServiceManager: service 'device_identifiers' died
M01652F 11-21 11:50:59.439 249 249 I ServiceManager: service 'uri_grants' died
M016530 11-21 11:50:59.440 6281 6281 D HprofFactory: Create HprofDebugEx
M016531 11-21 11:50:59.439 249 249 I ServiceManager: service 'activity_task' died
M016532 11-21 11:50:59.444 249 249 I ServiceManager: service 'appops' died
M016533 11-21 11:50:59.444 249 249 I ServiceManager: service 'batterystats' died
M016534 11-21 11:50:59.444 249 249 I ServiceManager: service 'power' died
M016535 11-21 11:50:59.444 249 249 I ServiceManager: service 'thermalservice' died
M016536 11-21 11:50:59.444 249 249 I ServiceManager: service 'recovery' died
M016537 11-21 11:50:59.444 249 249 I ServiceManager: service 'display' died
M016538 11-21 11:50:59.444 249 249 I ServiceManager: service 'package' died
M016539 11-21 11:50:59.444 249 249 I ServiceManager: service 'package_native' died
M01653A 11-21 11:50:59.444 249 249 I ServiceManager: service 'usagestats' died
M01653B 11-21 11:50:59.444 249 249 I ServiceManager: service 'webviewupdate' died
M01653C 11-21 11:50:59.444 249 249 I ServiceManager: service 'binder_calls_stats' died
M01653D 11-21 11:50:59.444 249 249 I ServiceManager: service 'looper_stats' died
M01653E 11-21 11:50:59.444 6281 6281 I Process : Sending signal. PID: 6281 SIG: 9
。。。。。(略)
3 看以上日志,系统服务全部挂掉,接下来我们继续分析log
看android0.log日志,我们分析如下。
bash
发生SWT:
"android.fg"线程在等锁<0x0b167f2f>,该锁是被"android.display"持有;
"android.display"又在等锁<0x046172a2>,该锁是被"main"线程持有;
"main"线程又在等锁<0x0d005081>,该锁是被"HwBinder:745_5"持有;
"HwBinder:745_5"线程又在等锁<0x0b167f2f>,导致发生死锁了。
[下一步计划]
待AMS看下死锁原因,谢谢!
[分析过程]
[1119anrlog\ap\000-1119_153646_poweron\0-android.log]:
E00CBFE 11-19 15:42:02.313 745 770 I watchdog: Blocked in handler on foreground thread (android.fg), Blocked in handler on main thread (main), Blocked in handler on ui thread (android.ui), Blocked in handler on display thread (android.display), Blocked in handler on ActivityManager (ActivityManager), Blocked in handler on PowerManagerService (PowerManagerService)
S00CCF3 11-19 15:42:15.914 745 770 W Watchdog: *** WATCHDOG KILLING SYSTEM PROCESS: Blocked in handler on foreground thread (android.fg), Blocked in handler on main thread (main), Blocked in handler on ui thread (android.ui), Blocked in handler on display thread (android.display), Blocked in handler on ActivityManager (ActivityManager), Blocked in handler on PowerManagerService (PowerManagerService)
----- pid 745 at 2024-11-19 15:41:21 -----
Cmd line: system_server
"android.fg" prio=5 tid=14 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x13141228 self=0x9a7fda00
| sysTid=764 nice=0 cgrp=default sched=0/0 handle=0x8454c230
| state=S schedstat=( 1707629333 1820559435 5437 ) utm=148 stm=22 core=1 HZ=100
| stack=0x84449000-0x8444b000 stackSize=1040KB
| held mutexes=
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:15827)
- waiting to lock <0x0b167f2f> (a com.android.server.am.ActivityManagerServiceEx) held by thread 17
at android.app.ContextImpl.sendOrderedBroadcastAsUser(ContextImpl.java:1314)
at android.app.ContextImpl.sendOrderedBroadcastAsUser(ContextImpl.java:1276)
at com.android.server.ConnectivityService.sendDataActivityBroadcast(ConnectivityService.java:2086)
at com.android.server.ConnectivityService.access$400(ConnectivityService.java:235)
at com.android.server.ConnectivityService$3.interfaceClassDataActivityChanged(ConnectivityService.java:1664)
at com.android.server.NetworkManagementService.lambda$notifyInterfaceClassActivity$5(NetworkManagementService.java:438)
at com.android.server.-$$Lambda$NetworkManagementService$D43p3Tqq7B3qaMs9AGb_3j0KZd0.sendCallback(lambda:-1)
at com.android.server.NetworkManagementService.invokeForAllObservers(NetworkManagementService.java:340)
at com.android.server.NetworkManagementService.notifyInterfaceClassActivity(NetworkManagementService.java:438)
at com.android.server.NetworkManagementService.access$1200(NetworkManagementService.java:117)
at com.android.server.NetworkManagementService$NetdUnsolicitedEventListener.lambda$onInterfaceClassActivityChanged$0$NetworkManagementService$NetdUnsolicitedEventListener(NetworkManagementService.java:666)
at com.android.server.-$$Lambda$NetworkManagementService$NetdUnsolicitedEventListener$0xWa9DGxTnoGVHppsM-nng2PygE.run(lambda:-1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
"android.display" prio=5 tid=17 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x13141568 self=0x9a800400
| sysTid=767 nice=-3 cgrp=default sched=0/0 handle=0x84231230
| state=S schedstat=( 875860938 1723520664 3899 ) utm=62 stm=25 core=2 HZ=100
| stack=0x8412e000-0x84130000 stackSize=1040KB
| held mutexes=
at com.android.server.power.PowerManagerService.updateUidProcStateInternal(PowerManagerService.java:3148)
- waiting to lock <0x046172a2> (a java.lang.Object) held by thread 1
at com.android.server.power.PowerManagerService$LocalService.updateUidProcState(PowerManagerService.java:5200)
at com.android.server.am.ActivityManagerService.enqueueUidChangeLocked(ActivityManagerService.java:16904)
at com.android.server.am.OomAdjuster.updateOomAdjLocked(OomAdjuster.java:621)
at com.android.server.am.ActivityManagerService.updateOomAdjLocked(ActivityManagerService.java:17226)
at com.android.server.am.ActivityManagerService$LocalService.updateOomAdj(ActivityManagerService.java:18350)
- locked <0x0b167f2f> (a com.android.server.am.ActivityManagerServiceEx)
at com.android.server.wm.-$$Lambda$yIIsPVyXvnU3Rv8mcliit-gIpSs.run(lambda:-1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
at com.android.server.ServiceThread.run(ServiceThread.java:44)
"main" prio=5 tid=1 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x757ab450 self=0xb053de00
| sysTid=745 nice=-2 cgrp=default sched=0/0 handle=0xb0b20dc0
| state=S schedstat=( 6436213292 2293829926 7935 ) utm=480 stm=163 core=1 HZ=100
| stack=0xbe5e9000-0xbe5eb000 stackSize=8192KB
| held mutexes=
at com.android.server.BatteryService$LocalService.getBatteryChargeCounter(BatteryService.java:1337)
- waiting to lock <0x0d005081> (a java.lang.Object) held by thread 130
at com.android.server.power.batterysaver.BatterySavingStats.injectBatteryLevel(BatterySavingStats.java:248)
at com.android.server.power.batterysaver.BatterySavingStats.transitionStateLocked(BatterySavingStats.java:287)
at com.android.server.power.batterysaver.BatterySavingStats.transitionState(BatterySavingStats.java:268)
- locked <0x046172a2> (a java.lang.Object)
at com.android.server.power.batterysaver.BatterySaverController.updateBatterySavingStats(BatterySaverController.java:519)
- locked <0x046172a2> (a java.lang.Object)
at com.android.server.power.batterysaver.BatterySaverController.access$100(BatterySaverController.java:59)
at com.android.server.power.batterysaver.BatterySaverController$1.onReceive(BatterySaverController.java:187)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1583)
at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(lambda:-1)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at com.android.server.SystemServer.run(SystemServer.java:562)
at com.android.server.SystemServer.main(SystemServer.java:370)
at java.lang.reflect.Method.invoke(Native method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:914)
"HwBinder:745_5" prio=5 tid=130 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x147408b0 self=0x7de38e00
| sysTid=2169 nice=0 cgrp=default sched=0/0 handle=0x7ba8c230
| state=S schedstat=( 35393468 114781610 106 ) utm=3 stm=0 core=2 HZ=100
| stack=0x7b991000-0x7b993000 stackSize=1008KB
| held mutexes=
at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:15827)
- waiting to lock <0x0b167f2f> (a com.android.server.am.ActivityManagerServiceEx) held by thread 17
at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1049)
at com.android.server.BatteryService$Led.sendLightActionBroadcast(BatteryService.java:1128)
at com.android.server.BatteryService$Led.updateLightsLocked(BatteryService.java:1179)
at com.android.server.BatteryService.processValuesLocked(BatteryService.java:680)
at com.android.server.BatteryService.update(BatteryService.java:453)
- locked <0x0d005081> (a java.lang.Object)
at com.android.server.BatteryService.access$1100(BatteryService.java:116)
at com.android.server.BatteryService$HealthHalCallback.healthInfoChanged(BatteryService.java:1187)
at android.hardware.health.V2_0.IHealthInfoCallback$Stub.onTransact(IHealthInfoCallback.java:440)
"android.ui" prio=5 tid=15 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x13141398 self=0x9a7fe800
| sysTid=765 nice=-2 cgrp=default sched=0/0 handle=0x84443230
| state=S schedstat=( 2231931697 1799238491 11891 ) utm=148 stm=74 core=0 HZ=100
| stack=0x84340000-0x84342000 stackSize=1040KB
| held mutexes=
at com.android.server.am.ActivityManagerService.dispatchUidsChanged(ActivityManagerService.java:3345)
- waiting to lock <0x0b167f2f> (a com.android.server.am.ActivityManagerServiceEx) held by thread 17
"ActivityManager" prio=5 tid=23 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x13141c58 self=0x9a83d800
| sysTid=773 nice=-2 cgrp=default sched=0/0 handle=0x83bfb230
| state=S schedstat=( 769154699 733906338 2390 ) utm=56 stm=20 core=1 HZ=100
| stack=0x83af8000-0x83afa000 stackSize=1040KB
| held mutexes=
at com.android.server.am.ActivityManagerService.idleUids(ActivityManagerService.java:17290)
- waiting to lock <0x0b167f2f> (a com.android.server.am.ActivityManagerServiceEx) held by thread 17
"PowerManagerService" prio=5 tid=33 Blocked
| group="main" sCount=1 dsCount=0 flags=1 obj=0x13145a78 self=0x9a846400
| sysTid=783 nice=-4 cgrp=default sched=0/0 handle=0x830ab230
| state=S schedstat=( 369337669 465048778 2947 ) utm=20 stm=16 core=2 HZ=100
| stack=0x82fa8000-0x82faa000 stackSize=1040KB
| held mutexes=
at com.android.server.power.PowerManagerService$BatteryReceiver.onReceive(PowerManagerService.java:4070)
- waiting to lock <0x046172a2> (a java.lang.Object) held by thread 1
4 以上日志结论是发生死锁导致死机。我们继续分析
文件夹中有crash.log.看日志如下
bash
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: FATAL EXCEPTION: main
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: Process: com.android.calendar, PID: 17985
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.calendar/com.android.calendar.AllInOneActivity}: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.calendar.DayFragment: could not find Fragment constructor
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3322)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3475)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2039)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7626)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.android.calendar.DayFragment: could not find Fragment constructor
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Fragment.instantiate(Fragment.java:562)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.FragmentContainer.instantiate(FragmentContainer.java:53)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.FragmentState.instantiate(FragmentState.java:77)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:2900)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.FragmentController.restoreAllState(FragmentController.java:142)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Activity.onCreate(Activity.java:1504)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at com.android.calendar.AllInOneActivity.onCreate(AllInOneActivity.java:274)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7879)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7867)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3294)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: ... 11 more
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: Caused by: java.lang.NoSuchMethodException: com.android.calendar.DayFragment.<init> []
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at java.lang.Class.getConstructor0(Class.java:2332)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at java.lang.Class.getConstructor(Class.java:1728)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: at android.app.Fragment.instantiate(Fragment.java:543)
C046623 11-20 11:14:51.848 17985 17985 E AndroidRuntime: ... 21 more
刚开始一直以为是这两个造成的,但是此处未做过定制,所以问题不是这里。继续寻找问题(后续发现我被这个crash误导了,这是monkey压测捕获的log,正式的log日志是这里的日志内容不一样的)
2 日志分析二(正确方案)
因为无复现逻辑还是想法触发死机的行为,无意间使用数据线插拔设备,导致设备卡顿,赶紧导出日志
- 日志结构如下:
看以上日志结构,最外层的文件夹结尾都是fwkreboot,说明fw是重启的。日志都有traces文件夹,里面都有anr的log日志,说明发生了卡顿,现象也是如此。 - 查看0-android_crash.log 日志如下(其他crash日志也是同样的内容)
看日志说明,系统发生死机,fwkreboot是重启行为。可以看时间点以前的log确定问题点 - 接下来继续看traces下的anr 日志。寻找相同的日志log,截图如下
- 可以看到以上截图,有sendLightActionBroadcast方法 发生blocked,在BatteryService类里。接下来我们去阅读BatteryService修改的逻辑。
- BatteryService中开发逻辑
- 看代码,我们在指示灯亮起时发送广播。说明发送广播时发生了卡顿。看该类中有发送广播的逻辑如下截图
截图中所有发送的广播都是放在队列里面发送。这样我们的广播方式和他们保持一致就可有了。 - 修改方案:将广播放在Handler里面发送。
- 打包测试验证。未复现卡顿或死机现象。问题解决
总结:第一次遇到死机现象还是有点蒙逼的,因为没有复现逻辑,不确定造成死机的原因,前期clash的日志误导了判断。后续可复现时日志重复,根据前期日志的分析,定位就非常容易了。写次日志更多的是梳理从问题到日志分析,到问题定位解决,从宏观到具体的一个思路和日志结构的直观浏览。
OVER~
参考文章