dumpsys是一种在Android设备上运行的工具,它提供有关系统服务的信息。 您可以使用Android(ADB)从命令行调用dumpsys,以获取在连接设备上运行的所有系统服务的诊断输出。 此输出通常比您想要的更冗长,因此请使用下面描述的命令行选项仅为您感兴趣的系统服务获取输出。此页面还介绍了如何使用dumpsys完成常见任务,例如检查输入 ,RAM,电池或网络诊断.
来自官方文档(dumpsys详细使用指南请戳这里)
adb shell dumpsys activity [options] [WHAT]
option | 含义 |
---|---|
-a | 包括所有可用 Servier 状态 |
-c | 包括 Client 状态,即 App 端情况 |
-p PackageName | 限定输出指定包名 |
WHAT | 含义 |
---|---|
a[ctivities] | activity 状态 |
b[roadcasts] [PACKAGE_NAME] | broadcast 状态 |
s[ervices] [COMP_SPEC …] | service 状态 |
prov[iders] [COMP_SPEC …] | content provider 状态 |
p[rocesses][PACKAGE_NAME] | 进程状态 |
o[om] | 内存管理 |
i[ntents] [PACKAGE_NAME] | pending intent 状态 |
r[ecents] | 最近 activity |
perm[issions] | URI 授权情况 |
all | 所有 activities 信息 |
top | 顶部 activity 信息 |
package | package 相关信息 |
adb shell dumpsys activity
输出
ACTIVITY MANAGER PENDING INTENTS (dumpsys activity intents) //注意一下
* PendingIntentRecord{1004eb1 com.tencent.mobileqq broadcastIntent}
* PendingIntentRecord{a9858c7 com.google.android.gms broadcastIntent}
* PendingIntentRecord{dc3ae3d com.tencent.mm startService}
// 省略 N 行 ...
ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts) //注意一下
Historical broadcasts [foreground]:
#0: BroadcastRecord{63c6dd9 u-1 android.hardware.usb.action.USB_STATE}
// 省略 N 行 ...
ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers) //注意一下
Published single-user content providers (by class):
* ContentProviderRecord{ef6fc1f u0 com.android.providers.telephony/.TelephonyProvider}
proc=ProcessRecord{efab720 3684:com.android.phone/1001}
singleton=true
authority=telephony
// 省略 N 行 ...
ACTIVITY MANAGER URI PERMISSIONS (dumpsys activity permissions) //注意一下
Granted Uri Permissions:
* UID 10129 holds:
UriPermission{b827fb4 0 @ content://downloads/all_downloads/125}
UriPermission{2b167dd 0 @ content://downloads/all_downloads/134}
UriPermission{51cbf52 0 @ content://downloads/all_downloads/148}
UriPermission{af4a223 0 @ content://downloads/all_downloads/169}
ACTIVITY MANAGER SERVICES (dumpsys activity services) //注意一下
User 0 active services:
* ServiceRecord{da1e320 u0 com.android.bluetooth/.hid.HidService}
app=null
created=-12d3h35m44s197ms started=false connections=1
// 省略 N 行 ...
ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents) //注意一下
Recent tasks:
* Recent #0: TaskRecord{162657c #917 A=android.task.mms U=0 sz=1}
// 省略 N 行 ...
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities) //注意一下
Display #0 (activities from top to bottom):
// 省略 N 行 ...
ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes) //注意一下
Isolated process list (sorted by uid):
Isolated # 0: ProcessRecord{ffa12e5 3187:WebViewLoader-arm64-v8a/1037}
UID states:
UID 1000: UidRecord{15a01ba 1000 P / 19 procs}
// 省略 N 行 ...
adb shell dumpsys activity」命令等价于依次输出下面 8 条命令:
adb shell dumpsys activity intents // 主要输出 PendingIntentRecord
adb shell dumpsys activity broadcasts
adb shell dumpsys activity providers// Published single-user content providers (by class) / Published user 0 content providers (by class)
adb shell dumpsys activity permissions
adb shell dumpsys activity services
adb shell dumpsys activity recents
adb shell dumpsys activity activities
adb shell dumpsys activity processes
adb shell dumpsys activity top
输出
TASK android.task.contacts id=42 userId=0
ACTIVITY com.android.contacts/.activities.PeopleActivity 6cf28a9 pid=19638
Local Activity e579e8d State:
mResumed=true mStopped=false mFinished=false
// ... 只举出了前两行,省略了 N 行代码
获取当前 Android 系统中与用户交互的 Activity 的详细信息,根据输出可得到联系人的应用包名是:「com.android.contacts」
adb shell dumpsys activity activities
意义:显示当前所有在运行的任务栈,它们的 id 分别是什么。对于每个 Task 也有 Activity 数量等信息,同时也列出了其中的 Activity 列表,并且对于每个 Activity 也有比较详细的描述,比如启动它的 Intent 的内容。如果觉得内容过多,只想看看栈的内容,也可以直接跳到「Running activities (most recent first) 那部分,比较简洁而又明了的列出了栈中的 Activity 列表,就能知道当按下返回键的时候会应该回到哪个 Activity 」
adb shell dumpsys package com.android.contacts
输出
Activity Resolver Table: // 这里开始解析activity标签
Full MIME Types:
vnd.android.cursor.dir/raw_contact:
2245068 com.android.contacts/.activities.ContactEditorActivity filter 9f79e7c
Action: "android.intent.action.INSERT"
Category: "android.intent.category.DEFAULT"
Type: "vnd.android.cursor.dir/person"
Type: "vnd.android.cursor.dir/contact"
Type: "vnd.android.cursor.dir/raw_contact"
...
Base MIME Types:
vnd.android.cursor.dir:
cfcad03 com.android.contacts/.activities.PeopleActivity filter b9aba95
Action: "android.intent.action.SEARCH"
Category: "android.intent.category.DEFAULT"
Type: "vnd.android.cursor.dir/contact"
...
Schemes:
mailto: // 列出了所有以 mailto 为 scheme 的 Activity
66ba8ac com.android.contacts/.activities.ShowOrCreateActivity filter 7a6e202
Action: "com.android.contacts.action.SHOW_OR_CREATE_CONTACT"
Category: "android.intent.category.DEFAULT"
Scheme: "mailto"
Scheme: "tel"
...
Non-Data Actions: // 列出了所有有「intent-filter」标签但是无「data」标签的 Activity
com.android.contacts.action.LIST_CONTACTS_WITH_PHONES:
cfcad03 com.android.contacts/.activities.PeopleActivity filter 51759d9
Action: "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES"
Category: "android.intent.category.DEFAULT"
Category: "android.intent.category.TAB"
...
Receiver Resolver Table: // 这里开始解析「receiver」标签
Non-Data Actions: // 列出了所有含「intent-filter」标签但是无「action」标签的 receiver
android.intent.action.BOOT_COMPLETED:
ef89fd6 com.android.contacts/.interactions.OnBootOrUpgradeReceiver filter 558b4
Action: "android.intent.action.BOOT_COMPLETED"
Action: "android.intent.action.MY_PACKAGE_REPLACED"
...
Service Resolver Table: // 这里开始解析「service」标签
Full MIME Types:
vnd.android.cursor.item/contact:
6137257 com.android.contacts/.ViewNotificationService filter 914e187 permission android.permission.WRITE_CONTACTS
Action: "com.android.contacts.VIEW_NOTIFICATION"
Type: "vnd.android.cursor.item/contact"
...
Permissions:
...
Registered ContentProviders:
...
ContentProvider Authorities:
...
Key Set Manager:
...
Packages:
...
requested permissions:
...
install permissions:
...
runtime permissions:
...
Package Changes:
...
Dexopt state:
...
Compiler stats:
adb shell dumpsys meminfo com.android.contacts
输出
Applications Memory Usage (in Kilobytes):
Uptime: 175444093 Realtime: 258827118
** MEMINFO in pid 19638 [com.android.contacts] **
Pss Private Private SwapPss Heap Heap Heap
Total Dirty Clean Dirty Size Alloc Free
------ ------ ------ ------ ------ ------ ------
Native Heap 4736 4720 0 24 6656 5753 902
Dalvik Heap 1088 1076 0 30 3123 1562 1561
Dalvik Other 204 204 0 0
Stack 36 36 0 0
Cursor 2 0 0 0
Ashmem 2 0 0 0
Other dev 23 4 16 0
.so mmap 1786 140 8 3
.apk mmap 4616 0 3640 0
.ttf mmap 173 0 112 0
.dex mmap 2475 4 1268 0
.oat mmap 984 0 48 0
.art mmap 2164 1664 76 0
Other mmap 546 4 44 0
GL mtrack 1816 1816 0 0
Unknown 574 572 0 0
TOTAL 21282 10240 5212 57 9779 7315 2463
App Summary
Pss(KB)
------
Java Heap: 2816
Native Heap: 4720
Code: 5220
Stack: 36
Graphics: 1816
Private Other: 844
System: 5830
TOTAL: 21282 TOTAL SWAP PSS: 57
Objects
Views: 90 ViewRootImpl: 1
AppContexts: 5 Activities: 1
Assets: 5 AssetManagers: 0
Local Binders: 25 Proxy Binders: 32
Parcel memory: 4 Parcel count: 18
Death Recipients: 0 OpenSSL Sockets: 0
WebViews: 0
SQL
MEMORY_USED: 0
PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0
command | description |
---|---|
adb shell dumpsys activity | 获取当前 Android 系统 Activity 栈中 Activity 信息 |
adb shell dumpsys activity top | 获取当前 Android 系统 中与用户交互的 Activity 的详细信息 |
adb shell dumpsys meminfo [应用包名] | 查看应用的内存使用情况 |
adb shell dumpsys package [应用报名] | 获取手机里面某个 apk 的应用信息、版本信息 |
adb shell dumpsys activity activities | 显示当前所有在运行的任务栈,并可查看栈中所有的 Activity 的列表 |