ANR Log分析工具和关键字

一、常见的关键字

关键字解释源码备注
am_anr发生问题时间点am_anr (User|1|5),(pid|1|5),(Package Name|3),(Flags|1|5),(reason|3)
public static final int AM_ANR = 30008;

03-26 14:54:25.759 1871 13613 I am_anr : [0,5272,com.android.systemui,818462221,Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50200010 cmp=com.android.systemui/com.android.settingslib.bluetooth.BluetoothEventManagerBluetoothBroadcastReceiver }]<br/>**时间戳:**03-26 14:54:25.759<br/>**进程:**1871<br/>线程:13613<br/>**ANR类型:**am_anr<br/>**User:**0<br/>**pid:**5272<br/>**Package Name:**com.android.systemui<br/>**Flags:**818462221<br/>**reason:**Broadcast of Intent { act=android.intent.action.SCREEN_OFF flg=0x50200010 cmp=com.android.systemui/com.android.settingslib.bluetooth.BluetoothEventManagerBluetoothBroadcastReceiver }
最终得出原因是systemui发送SCREEN_OFF广播,卡住主线程
ANR in发生问题时间点
PerfMonitor longMsg
Long monitor contention with持锁
AnrScout
MIUIScout
get period history msg
dvm_lock_sample持锁
Slow Binderbinder耗时
PerfMonitor dispatchInputEvent
low_memory低内存
OpenGLRenderer
becaused of low mem低内存
kill at or below oom_adj低内存
thermal sensor board temp is温度

二、特殊的LOG

小米机器增加了特殊的打点处理,详细参考 baseFramework/base/core/java/android/os/statistics/EventLogSuperviser.java

private static class EventLogTags {
  /** 2728 power_screen_state (offOrOn|1|5),(becauseOfUser|1|5),(totalTouchDownTime|2|3),(touchCycles|1|1) */
  public static final int POWER_SCREEN_STATE = 2728;
 
  /** 30007 am_resume_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3) */
  public static final int AM_RESUME_ACTIVITY = 30007;
 
  /** 30008 am_anr (User|1|5),(pid|1|5),(Package Name|3),(Flags|1|5),(reason|3) */
  public static final int AM_ANR = 30008;
 
  /** 30009 am_activity_launch_time (User|1|5),(Token|1|5),(Component Name|3),(time|2|3) */
  public static final int AM_ACTIVITY_LAUNCH_TIME = 30009;
 
  /** 30014 am_proc_start (User|1|5),(PID|1|5),(UID|1|5),(Process Name|3),(Type|3),(Component|3) */
  public static final int AM_PROC_START = 30014;
 
  /** 30017 am_low_memory (Num Processes|1|1) */
  public static final int AM_LOW_MEMORY = 30017;
 
  /** 30019 am_relaunch_resume_activity (User|1|5),(Token|1|5),(Task ID|1|5),(Component Name|3) */
  public static final int AM_RELAUNCH_RESUME_ACTIVITY = 30019;
 
  /** 30030 am_create_service (User|1|5),(Service Record|1|5),(Name|3),(UID|1|5),(PID|1|5) */
  public static final int AM_CREATE_SERVICE = 30030;
 
  /** 30036 am_provider_lost_process (User|1|5),(Package Name|3),(UID|1|5),(Name|3) */
  public static final int AM_PROVIDER_LOST_PROCESS = 30036;
 
  /** 30037 am_process_start_timeout (User|1|5),(PID|1|5),(UID|1|5),(Process Name|3) */
  public static final int AM_PROCESS_START_TIMEOUT = 30037;
 
  /** 30039 am_crash (User|1|5),(PID|1|5),(Process Name|3),(Flags|1|5),(Exception|3),(Message|3),(File|3),(Line|1|5) */
  public static final int AM_CRASH = 30039;
 
  /** 30041 am_switch_user (id|1|5) */
  public static final int AM_SWITCH_USER = 30041;
 
  /** 30046 am_meminfo (Cached|2|2),(Free|2|2),(Zram|2|2),(Kernel|2|2),(Native|2|2) */
  public static final int AM_MEMINFO = 30046;
 
  /** 30050 am_mem_factor (Current|1|5),(Previous|1|5) */
  public static final int AM_MEM_FACTOR = 30050;
 
  /** 30070 am_start_service (CallerUID|1|5),(CallerProcessName|3),(ServiceUID|1|5),(ServiceProcessName|3),(ServiceName|3),(ServiceIntent|3) */
  public static final int AM_START_SERVICE = 30070;
 
  /**30071 am_bind_service (CallerUID|1|5),(CallerProcessName|3),(ServiceUID|1|5),(ServiceProcessName|3),(ServiceName|3),(ServiceIntent|3) */
  public static final int AM_BIND_SERVICE = 30071;
 
  /**MIUI defined activity launch time event with more info**/
  public static final int AM_ACTIVITY_LAUNCH_TIME_MIUI = 30088;
 
  /** 52002 content_query_sample (uri|3),(projection|3),(selection|3),(sortorder|3),(time|1|3),(blocking_package|3),(sample_percent|1|6) */
  public static final int CONTENT_QUERY_SAMPLE = 52002;
 
  /** 52003 content_update_sample (uri|3),(operation|3),(selection|3),(time|1|3),(blocking_package|3),(sample_percent|1|6) */
  public static final int CONTENT_UPDATE_SAMPLE = 52003;
}

不过遗憾的是,目前的打点只使用到了AM_ANR这个字段

三、ANR的类型

参考 baseFramework/base/core/java/miui/mqsas/sdk/event/AnrEvent.java

ANR 的类型主要包含如下几个

 
    public String getAnrType() {
        if (isInputAnr()) {
            if (!TextUtils.isEmpty(mReason)) {
                if (mReason.contains(REASON_NOT_RESPONDING)) {
                    return "input.app";
                } else if (mReason.contains(REASON_NO_FOCUSED_WINDOW)) {
                    return "input.window";
                }
            }
            return "input";
        } else if (isServiceAnr()) {
            return "service";
        } else if (isBroadcastAnr()) {
            return "broadcast";
        } else if (isProviderAnr()) {
            return "provider";
        } else {
            return "unknown";
        }
    }
 
 
 
 public boolean isInputAnr() {
        if (!TextUtils.isEmpty(mReason)) {
            if (mReason.contains("Input dispatching timed out")) {
                return true;
            }
        }
        return false;
    }
 
    public boolean isServiceAnr() {
        if (!TextUtils.isEmpty(mReason)) {
            if (mReason.contains("executing service") || mReason.contains("Context.startForegroundService()")) {
                return true;
            }
        }
        return false;
    }
 
    public boolean isBroadcastAnr() {
        if (!TextUtils.isEmpty(mReason)) {
            if (mReason.contains("Broadcast of")) {
                return true;
            }
        }
        return false;
    }
 
    public boolean isProviderAnr() {
        if (!TextUtils.isEmpty(mReason)) {
            if (mReason.contains("ContentProvider not responding")) {
                return true;
            }
        }
        return false;
    }
 
类型名称超时时间
应用输入事件处理超时input.app
窗口输入事件处理超时input.window
输入事件处理超时input
Service处理长超时service
广播处理超时broadcast
provider处理超时provider
unknown暂未匹配到unknown

四、Log分析工具

Log 分析 工具: https://wiki.n.miui.com/pages/viewpage.action?pageId=580249480

在右上角

然后添加关键字 add

点击对号键 就可以查看相关log

也可以使用快捷键 Ctrl + F 自己输入关键字查看