极力推荐文章:欢迎收藏
Android 干货分享
本篇文章主要介绍 Android
开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
1.MTK AEE Log分析工具
2.AEE Log分析流程
3.system_server 卡死案例分析及解决
本文主要针对 Exception Type: system_server_watchdog
, system_server
卡死找出的分析以及解决方案。
MTK AEE Log获取方式:
关注微信公众号: 程序员Android
回复 aee 即可获取解析重启 db log
的工具。
dbg
文件。
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_watchdog Current Executing Process: system_server Trigger time:[2019-03-14 14:00:03.711844] pid:1029 Backtrace: Process: system_server Subject: Blocked in handler on ActivityManager (ActivityManager) Build: ACE/AS0618/AS0618:8.1.0/O11019/1548123508:user/release-keys
exp_main 文件解析
从开头的 Log
总体信息概览,我们可以看到 发生 重启的时间
、 类型
, 触发重启的进程
以及 PID
、 系统Blocked 的地方
。
结合 exp_main
以及 trace
分析重启 Log Log
分析如下:
// 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 找到卡死原因后,解决此问题。
需要修改ActivityManagerService类。
代码路径如下: alps/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
解决思路:
避免 provider 长时间持锁触发 MTK
60s 的 SWT 重启机制,设置超时时间,超过时间就要释放资源锁,避免发生此问题。
--- 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.Stub static 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.Stub synchronized (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.Stub cleanupAppInLaunchingProvidersLocked(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.Stub if (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); } } }
至此,本篇已结束,如有不对的地方,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!