androidlog分析及异常关键字分析启动或退出APP执⾏过程与
过滤ActivityMa。。。
private static final boolean IS_DEBUG_BUILD = Build.TYPE.equals("eng") || Build.TYPE.equals("urdebug");
分析异常时往往需要关注的重要⽬录:
/data/
/data/tombstones/tombstone_X
/data/system/dropbox/
Log.i("LogTag","------------", new Exception()); ⼈为抛出异常 打印运⾏堆栈,此命令适⽤于源码编译中,但在APP中使⽤就会报错,APP 中可以这样使⽤:
Log.i("LogTag","------------",“ ---”+new Exception());
Thread.currentThread().dumpStack(); //⽅法1
Log.d(TAG,"Gityuan", new RuntimeException("Gityuan")); //⽅法2
new RuntimeException("Gityuan").printStackTrace(); //⽅法3
MTK的mtkloger:
进⼊应⽤暗码 : *#*#3646633#*#*
log的保存路径 /storage/emulated/0/mtklog
海王星的发现如部分平板系统预装拨号盘如何打开MTKlog
adb shell am start -klogger.MainActivity
mtklog 的分类:MDLog、Mobile Log、Network Log,可能出现的aee_exp log
MD log:medom 相关底层的log
Mobile Log:主要是Android log 和kernel log
Network log:⽹络相关log
aee_exp log :crash ANR 重启相关的log输出
对应log⽂件名称为:
crash_log :崩溃⽇志,主要输出 程序崩溃造成的crash log
events_log:事件⽇志,主要输出记录各个activity周期及事件
kernel_log:底层驱动,按键,低内存相关log
sys_log:系统⽇志,Exception定位点
radio_log:输出通话,⽹络状态变化
main_log:详尽输出每⼀步的log
参考原⽂ : blog.csdn/weixin_33473519/article/details/53434800?utm_source=blogxgwz
/blog/1955652 此⽂对android的anr问题有详细说明
ANR,是“Application Not Responding”的缩写,即“应⽤程序⽆响应”。在Android中,ActivityManager
Service(简称AMS)和WindowManagerService(简称WMS)会监测应⽤程序的响应时间,如果应⽤程序主线程(即UI线程)在超时时间内对输⼊事件没有处理完毕,或者对特定操作没有执⾏完毕,就会出现ANR。对于输⼊事件没有处理完毕产⽣的ANR,Android会显⽰⼀个对话框,提⽰⽤户当前应⽤程序没有响应,⽤户可以选择继续等待或者关闭这个应⽤程序(也就是杀掉这个应⽤程序的进程)。
1:关键字搜索:
FATAL,leaked, block,Pid id XXX,crash,DALVIK THREADS, OOM,unfinished died
查找应⽤包名--快速定位ANR
The application may be doing too much work on its main thread.
AndroidRuntime(xxxx): Shutting down VM
线程的状态是native则表⽰当前正在执⾏jni,
聪明的你肯定已经知道,之所以trace信息会输出到“/data/”⽂件中,就是系统属性“dalvik.vm.stack-trace-file”设置的。你可以通过在设备的shell中使⽤tprop和getprop对系统属性进⾏设置和读取:
getprop dalvik.vm.stack-trace-file
tprop dalvik.vm.stack-trace-file /
此 Dialog的java位置:
frameworks\ba\rvices\core\java\com\android\rver\am\AppNotRespondingDialog.java
alps\frameworks\ba\rvices\core\java\com\android\rver\am\AppErrors.java ::appNotResponding()
此处发送Handler message为 SHOW_NOT_RESPONDING_UI_MSG
// Set the app's notResponding state, and look up the errorReportReceiver
makeAppNotRespondingLocked(app,
activity != null ? activity.shortComponentName : null,
annotation != null ? "ANR " + annotation : "ANR",
// Bring up the infamous App Not Responding dialog
Message msg = Message.obtain();
msg.what = ActivityManagerService.SHOW_NOT_RESPONDING_UI_MSG;
msg.obj = new AppNotRespondingDialog.Data(app, activity, aboveSystem);
mService.mUiHandler.ndMessage(msg);
接着会在ActivityManagerService.java类中接收此Message并对应处理
alps\frameworks\ba\rvices\core\java\com\android\rver\am\ActivityManagerService.java
final class UiHandler extends Handler {
public UiHandler() {
super(com.android.().getLooper(), null, true);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
ca SHOW_ERROR_UI_MSG: {
mAppErrors.handleShowAppErrorUi(msg);
ensureBootCompleted();
} break;
ca SHOW_NOT_RESPONDING_UI_MSG: {
mAppErrors.handleShowAnrUi(msg);
ensureBootCompleted();
} break;
在AppError.java中的handleShowAppErrorUI()
if (mService.canShowErrorDialogs() || showBackground) {
dialogToShow = new AppNotRespondingDialog(mService, mContext, data);
proc.anrDialog = dialogToShow;名人读书故事
} el {
MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_APP_ANR,
AppNotRespondingDialog.CANT_SHOW);
/
/ Just kill the app if there is no dialog to be shown.
mService.killAppAtUrsRequest(proc, null);
}
}
// If we've created a crash dialog, show it without the lock held
if (dialogToShow != null) {
dialogToShow.show();
}
两个标签同时过滤adb 命令: adb shell "logcat |grep -e ActivityManager: -e WindowManager:"下⾯的打印为了log信息减少,所以分别打印⽅便查阅 ,
C:\Urs\Ur>adb logcat |findstr "ActivityManager" \\点击Launcher中图标 打开APP DeskClock
08-12 06:35:09.605 1043 8961 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=
[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.deskclock/.DeskClock bnds=[795,131][990
,423]} from uid 10015
08-12 06:35:09.703 1043 8961 V WindowManager: Changing focus from Window{cfe72a u0
绿色住宅
com.android.launcher3/com.android.launcher3.Launcher} to null Callers=com.android.rver.wm.WindowManagerService. tFocudApp:2739 com.android.rver.am.ActivityManagerService.tResumedActivityUncheckLocked:3325
com.android.rver.am.ActivityStack.tResumedActivityLocked:2312 com.android.rver.am.ActivityStack
.minimalResumeActivityLocked:1115
08-12 06:35:09.890 1043 1121 I ActivityManager: Displayed com.android.deskclock/.DeskClock: +201ms
繁衍生息的意思--------------------------------------------------------------------------------
C:\Urs\Ur>adb logcat -c|findstr "ActivityManager"
C:\Urs\Ur>adb logcat |findstr "ActivityManager" \\退出APP
08-12 06:35:29.715 1043 1078 V WindowManager: Changing focus from Window{4cebd29 u0
com.android.deskclock/com.android.deskclock.DeskClock} to null Callers=com.android.rver.wm.WindowManagerService. tFocudApp:2739 com.android.rver.am.ActivityManagerService.tResumedActivityUncheckLocked:3325
健康教案小班com.android.rver.am.ActivityStack.tResumedActivityLocked:2312 com.android.rver.am.ActivitySta
蕃茄炖牛腩
Ur>adb logcat -c |findstr "WindowManager:"
Ur>adb logcat |findstr "WindowManager:" //点击Launcher中图标 打开APP:DeskClock
21:06.149 1043 1315 V WindowManager: Set focud app to: AppWindowToken{24e89b8 token=T
oken{b72727a ActivityRecord{5decea5 u0 com.android.deskclock/.DeskClock t43}}} old focus=AppWindowToke
token=Token{64857d6 ActivityRecord{eb9b98 u0 com.android.launcher3/.Launcher t33}}} moveFocusNow=true
21:06.149 1043 1315 V WindowManager: findFocudWindow: No focusable windows.
21:06.149 1043 1315 V WindowManager: Changing focus from Window{cfe72a u0
com.android.launcher3/com.android.launcher3.Launcher} to null Callers=com.android.rver.wm.WindowManagerService. pp:2739 com.android.rver.am.ActivityManagerService.tResumedActivityUncheckLocked:3325
com.android.rver.am.ActivityStack.tResumedActivityLocked:2312 com.android.rver.am.ActivityStack esumeActivityLocked:1115
21:06.149 1043 1315 D WindowManager: Input focus has changed to null
21:06.152 **** **** V WindowManager: findFocudWindow: No focusable windows.
21:06.160 1043 6439 V WindowManager: findFocudWindow: No focusable windows.
21:06.481 1043 2119 I WindowManager: Relayout Window{c7e57f5 u0
com.android.deskclock/com.android.deskclock.DeskClock}: oldVis=4 newVis=0 focusMayChange = true
21:06.487 1043 2119 V WindowManager: Changing focus from null to Window{c7e57f5 u0
com.android.deskclock/com.android.deskclock.DeskClock} Callers=com.android.rver.wm.WindowManagerService.
夏至一
indow:2179 com.android.rver.layout:235 android.view.Transact:286
com.android.rver.Transact:162
21:06.487 1043 2119 D WindowManager: Input focus has changed to Window{c7e57f5 u0
com.android.deskclock/com.android.deskclock.DeskClock}
泰州引江河-
------------------------------------------------------------------------------------
Ur>adb logcat -c|findstr "WindowManager:"
Ur>adb logcat |findstr "WindowManager:" //退出APP:DeskClock 到Launcher
21:27.964 1043 1226 D WindowManager: interceptKeyTi keyCode=4 down=fal repeatCount=0 keyguardOn=fal mHomePresd=fal canceled=fal metaState:0
21:27.984 1043 6439 V WindowManager: Set focud app to: AppWindowToken{fb1c0e3 token=Token{64857d6 ActivityRecord{eb9b98 u0 com.android.launcher3/.Launcher t33}}} old focus=AppWindowToken{
oken=Token{b72727a ActivityRecord{5decea5 u0 com.android.deskclock/.DeskClock t43}}} moveFocusNow=true
21:27.984 1043 6439 V WindowManager: findFocudWindow: No focusable windows.
21:27.985 1043 6439 V WindowManager: Changing focus from Window{c7e57f5 u0
com.android.deskclock/com.android.deskclock.DeskClock} to null Callers=com.android.rver.wm.WindowManagerService. dApp:2739 com.android.rver.am.ActivityManagerService.tResumedActivityUncheckLocked:3325
com.android.rver.am.ActivityStack.tResumedActivityLocked:2312 com.android.rver.am.ActivitySta TopActivityInnerLocked:2694
21:27.985 1043 6439 D WindowManager: Input focus has changed to null
21:28.002 1043 1315 V WindowManager: findFocudWindow: No focusable windows.
21:28.044 1043 6439 I WindowManager: Relayout Window{cfe72a u0
com.android.launcher3/com.android.launcher3.Launcher}: oldVis=4 newVis=0 focusMayChange = true
21:28.048 1043 6439 V WindowManager: Changing focus from null to Window{cfe72a u0
com.android.launcher3/com.android.launcher3.Launcher} Callers=com.android.rver. dow:2179 com.android.rver.layout:235 android.view.Transact:286
com.android.rver.Transact:162
21:28.048 1043 6439 D WindowManager: Input focus has changed to Window{cfe72a u0
com.android.launcher3/com.android.launcher3.Launcher}