和你一起终身学习,这里是程序员Android
经典好文推荐,通过阅读本文,您将收获以下知识点:
一、MTK AEE Log分析工具
二、AEE Log分析流程
三、system_server 卡死案例分析及解决
本文主要针对 Exception Type: system_server_watchdog
, system_server
卡死找出的分析以及解决方案。
一、MTK AEE Log分析工具
MTK AEE Log 获取方式:
程序员Android
回复 aee 即可获取解析重启db log
的工具。
二、AEE Log分析流程
1. 使用AEE 工具解析 dbg
文件。
使用解析db.fatal.02.SWT.dbg
AEE Log 解析出来的文件
2.分析解析出来的exp_main
等文件
exp_main 文件会记录发生重启时候的 log 打印信息。
部分重启异常 Log
信息如下:
$** *** *** *** *** *** *** *** Fatal *** *** *** *** *** *** *** **$
Build Info: 'alps-mp-o1.mp7:alps-mp-o1.mp7:mt6765:S01,ACE/AS0618/AS0618:8.1.0/O11019/1548123508:user/release-keys'
Flavor Info: 'None'
Exception Log Time:[Thu Mar 14 14:00:03 CST 2019] [38684.729626]Exception Class: SWT
Exception Type: system_server_watchdogCurrent Executing Process:
system_serverTrigger time:[2019-03-14 14:00:03.711844] pid:1029Backtrace:
Process: system_server
Subject: Blocked in handler on ActivityManager (ActivityManager)
Build: ACE/AS0618/AS0618:8.1.0/O11019/1548123508:user/release-keys
3.exp_main 文件解析
从开头的Log
总体信息概览,我们可以看到 发生重启的时间
、类型
,触发重启的进程
以及PID
、系统Blocked 的地方
。
结合exp_main
以及 trace
分析重启 LogLog
分析如下:
// 1.重启触发时间,以及PID
Trigger time:[2019-03-14 14:00:03.711844] pid:1029
// 2.Blocked 的进程
Backtrace:
Process: system_server
Subject: Blocked in handler on ActivityManager (ActivityManager)
// 3.根据PID 查看Trace信息
----- pid 1029 at 2019-03-14 13:59:58 -----
Cmd line: system_server... ...
// 4.根据Backtrace 查看Blocked的信息
"ActivityManager" prio=5 tid=11 Blocked... ...
// 5.tid=11 等待 tid=106的线程释放资源锁- waiting to lock <0x090691f3> (a android.util.ArrayMap) held by thread 106
... ...// 6.查看tid = 106 持锁情况
"backup" prio=5 tid=106 Waiting
... ... at java.lang.Object.wait(Native method)- waiting on <0x06a44c62> (a com.android.server.am.ContentProviderRecord)
// 7.死锁卡住的地方at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:12127)- locked <0x06a44c62> (a com.android.server.am.ContentProviderRecord)... ..."Binder:1029_8" prio=5 tid=107 Blocked
// 8.log中 tid=107 被 106 Blocked 进一步问题的加重at com.android.server.notification.RankingHelper.getRecord(RankingHelper.java:258)- waiting to lock <0x090691f3> (a android.util.ArrayMap) held by thread 106$** *** *** *** *** *** *** *** Fatal *** *** *** *** *** *** *** **$
Log 分析大致过程截图
完整 log 请在公众号上获取
三、system_server 卡死案例分析及解决
通过 Log 找到卡死原因后,解决此问题。
需要修改ActivityManagerService类。
1.修改代码路径如下:alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
2.解决思路
避免 provider 长时间持锁触发MTK
60s 的SWT 重启机制,设置超时时间,超过时间就要释放资源锁,避免发生此问题。
3.diff 修改方案如下:
--- a/[alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c)+++ b/[alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444)@@ [-545,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c#l545) [+545,9](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444#l545) @@ public class ActivityManagerService extends IActivityManager.Stub// How long we wait for an attached process to publish its content providers// before we decide it must be hung.static final int CONTENT_PROVIDER_PUBLISH_TIMEOUT = 10*1000;-+ // How long we wait for provider to be notify before we decide it may be hung.+ static final int CONTENT_PROVIDER_WAIT_TIMEOUT = 20*1000;+ // How long we wait for a launched process to attach to the activity manager// before we decide it's never going to come up for real, when the process was// started with a wrapper for instrumentation (such as Valgrind) because it@@ [-1745,6](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c#l1745) [+1747,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444#l1747) @@ public class ActivityManagerService extends IActivityManager.Stubstatic final int PUSH_TEMP_WHITELIST_UI_MSG = 68;static final int SERVICE_FOREGROUND_CRASH_MSG = 69;static final int DISPATCH_OOM_ADJ_OBSERVER_MSG = 70;+ static final int CONTENT_PROVIDER_WAIT_TIMEOUT_MSG = 71;static final int START_USER_SWITCH_FG_MSG = 712;static final int NOTIFY_VR_KEYGUARD_MSG = 74;@@ [-2108,6](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c#l2108) [+2111,12](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444#l2111) @@ public class ActivityManagerService extends IActivityManager.Stubsynchronized (ActivityManagerService.this) {mActivityStarter.doPendingActivityLaunchesLocked(true);}+ } break;+ case CONTENT_PROVIDER_WAIT_TIMEOUT_MSG: {+ ContentProviderRecord cpr = (ContentProviderRecord)msg.obj;+ synchronized (ActivityManagerService.this) {+ processContentProviderWaitTimedOutLocked(cpr);+ }} break;case KILL_APPLICATION_MSG: {synchronized (ActivityManagerService.this) {@@ [-7029,7](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c#l7029) [+7038,31](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444#l7038) @@ public class ActivityManagerService extends IActivityManager.StubcleanupAppInLaunchingProvidersLocked(app, true);removeProcessLocked(app, false, true, "timeout publishing content providers");}+ + @GuardedBy("this")+ private final void processContentProviderWaitTimedOutLocked(ContentProviderRecord cpr) {+ try {+ if (mLaunchingProviders.contains(cpr)) {+ if (DEBUG_MU) Slog.v(TAG_MU,+ "Remove from mLaunchingProviders, " + cpr+ + " launchingApp=" + cpr.launchingApp);+ mLaunchingProviders.remove(cpr);+ }+ if (DEBUG_MU) Slog.v(TAG_MU,+ "RemoveMessages CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, " + cpr+ + " launchingApp=" + cpr.launchingApp);+ mHandler.removeMessages(CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, cpr);+ synchronized (cpr) {+ cpr.notifyAll();+ cpr.launchingApp = null;+ }+ } catch (Exception e) {+ if (DEBUG_MU) Slog.v(TAG_MU,+ "processContentProviderWaitTimedOutLocked exception, " + e);+ }+ }+ private final void processStartTimedOutLocked(ProcessRecord app) {final int pid = app.pid;boolean gone = false;@@ [-12124,11](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=d5e2e1411f3698a829e997d402c7482ec277fa8c;hb=d5e2e1411f3698a829e997d402c7482ec277fa8c#l12124) [+12157,33](http://192.168.11.104/gitweb/?p=alps-mp-o1.mp1-V1.git;a=blob;f=alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java;h=03208f78a2bf3167b4f0790019326e3939cc5444;hb=03208f78a2bf3167b4f0790019326e3939cc5444#l12157) @@ public class ActivityManagerService extends IActivityManager.Stubif (conn != null) {conn.waiting = true;}+ // add 20s wait timeout,avoid + if (!mHandler.hasMessages(CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, cpr)) {+ if (DEBUG_MU) Slog.v(TAG_MU,+ "SendMessageDelayed CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, " + cpr+ + " launchingApp=" + cpr.launchingApp);+ Message msg = mHandler.obtainMessage(CONTENT_PROVIDER_WAIT_TIMEOUT_MSG);+ msg.obj = cpr;+ mHandler.sendMessageDelayed(msg, CONTENT_PROVIDER_WAIT_TIMEOUT);+ } else {+ if (DEBUG_MU) Slog.v(TAG_MU,+ "There is another waiting to start provider " + cpr+ + " launchingApp=" + cpr.launchingApp+ + ", not send CONTENT_PROVIDER_WAIT_TIMEOUT_MSG again");+ }+ cpr.wait();} catch (InterruptedException ex) {} finally {if (conn != null) {conn.waiting = false;+ }+ // remove wait time out message+ if (mHandler.hasMessages(CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, cpr)) {+ if (DEBUG_MU) Slog.v(TAG_MU,+ "After wait removeMessages CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, "+ + cpr + " launchingApp=" + cpr.launchingApp);+ mHandler.removeMessages(CONTENT_PROVIDER_WAIT_TIMEOUT_MSG, cpr);}}}
参考文献:
【腾讯文档】Android Framework 知识库
https://docs.qq.com/doc/DSXBmSG9VbEROUXF5
友情推荐:
Android 开发干货集锦
至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!
点击阅读原文,为大佬点赞!