AMS之dumpsys篇

转载:http://gityuan.com/2017/07/04/ams_dumpsys/ 

基于Android 7.0的源码分析

一.概述

前面介绍过AMS相关的一些数据结构,每个数据结构有大量的成员变量,为了查询当前手机运行时状态的 变化值,可以通过dumpsys activity命令来完成,该方法最终是调用AMS.dump()方法。

dumpsys命令用法简要介绍过dumpsys命令 的基本用法,以及系统服务列表信息,那么本文重点介绍AMS。 根据dumpsys activity传递不同的参数, 对于AMS.dump便会输出相应的对象信息。 具体可以跟哪些参数.

1.1 命令格式

dumpsys activity [options] [WHAT]

其中options为可选项,以-开头, 主要有以下几类:

options含义
-a包括所有可用Server状态
-c包括Client状态,即App端情况
-p PACKAGE限定输出指定包名

1.2 WHAT参数

列举常见的WHAT参数:

序号WHAT解释对应源码
1a[ctivities]activity状态dumpActivitiesLocked()
2b[roadcasts] [PACKAGE_NAME]broadcast状态dumpBroadcastsLocked()
3s[ervices] [COMP_SPEC …]service状态newServiceDumperLocked().dumpLocked
4prov[iders] [COMP_SPEC …]content provider状态dumpProvidersLocked()
5p[rocesses] [PACKAGE_NAME]进程状态dumpProcessesLocked()
6o[om]内存管理dumpOomLocked()
7i[ntents] [PACKAGE_NAME]pending intent状态dumpPendingIntentsLocked()
8r[ecents]最近activitydumpRecentsLocked()
9perm[issions]URI授权情况dumpPermissionsLocked()
10all所有activities信息dumpActivity()
11top顶部activity信息dumpActivity()
12packagepackage相关信息dump()

其中PACKAGE_NAME是指可跟包名,COMP_SPEC是指可跟具体组件信息,中括号是指缩写字母;

二. dumpsys activity

前面介绍dumpsys activity根据后面跟着的不同参数则输出相应的内容,当不跟任何参数, dumpsys activity等价于依次输出下面8条命令:

dumpsys activity intents
dumpsys activity broadcasts //广播
dumpsys activity providers  //provider
dumpsys activity permissions
dumpsys activity services  //服务
dumpsys activity recents
dumpsys activity activities //activity
dumpsys activity processes

依次简要说明这8条命令:

2.1 intents

//标志性开头,dumpPendingIntentsLocked
ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents)

输出对象:

  • PendingIntentRecord

2.2 broadcasts

//标志性开头,dumpBroadcastsLocked
ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)
    Registered Receivers:
    Receiver Resolver Table:
    Historical broadcasts [foreground]:
    Historical broadcasts summary [foreground]:
    Historical broadcasts [background]:
    Historical broadcasts summary [background]:
    Sticky broadcasts
    mHandler

主要输出的对象:

  • ReceiverList, BroadcastFilter,
  • IntentResolver,
  • BroadcastQueue, BroadcastRecord
  • Handler, Looper

2.3 provider

//标志性开头,dumpProvidersLocked
ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers)
    Published single-user content providers (by class):
    Published user [n] content providers (by class):
    Single-user authority to provider mappings:
    User [n] authority to provider mappings:

主要输出的对象:

  • ProviderMap
  • ContentProviderRecord, ContentProviderConnection

2.4 permissions

//标志性开头,dumpPermissionsLocked
ACTIVITY MANAGER URI PERMISSIONS (dumpsys activity permissions)

主要输出的对象:

  • UriPermission

2.5 Service

//标志性开头,newServiceDumperLocked().dumpLocked
ACTIVITY MANAGER SERVICES (dumpsys activity services)

主要输出的对象:

  • ActiveServices,
  • ServiceRecord, ConnectionRecord,ProcessRecord

2.6 recents

//标志性开头,dumpRecentsLocked
ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)

主要输出的对象:

  • TaskRecord

2.7 activities

//标志性开头,dumpActivitiesLocked
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #0:
        Task id #[n]
          * Hist #[m]:
      Stack #1:

主要输出的对象:

  • ActivityStackSupervisor, ActivityStack,
  • TaskRecord, ActivityRecord
  • ActivityThread, Activity
  • ViewRootImpl
  • Looper, MessageQueue

输出格式样例:

//{Hashcode #TaskId Affinity UserId 该task的Activity个数};
TaskRecord{e6d7a8e #156 A=com.gityuan.demo U=0 sz=1}
userId=0 effectiveUid=1000 mCallingUid=1000 mCallingPackage=android
realActivity=com.gityuan.demo/.Blog

//ProcessRecord{Hashcode pid:进程名/uid}
ProcessRecord{7c8a2af 12265:com.gityuan.demo/1000}

2.8 processes

//标志性开头,dumpProcessesLocked
ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
    All known processes:
    Isolated process list (sorted by uid):
    UID states:
    UID validation:
    Process LRU list (sorted by oom_adj, 60 total, non-act at 2, non-svc at 2):
    PID mappings:
    Foreground Processes:

主要输出的对象:

  • AMS各种进程对象
  • ProcessRecord, UidRecord
    原文作者:jiangnan2222
    原文地址: https://blog.csdn.net/jiangnan2222/article/details/82655385
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞