文章目錄
簡介
dumpsys是一種在Android設備上運行的工具,它提供有關係統服務的信息。 您可以使用Android(ADB)從命令行調用dumpsys,以獲取在連接設備上運行的所有系統服務的診斷輸出。 此輸出通常比您想要的更冗長,因此請使用下面描述的命令行選項僅爲您感興趣的系統服務獲取輸出。此頁面還介紹瞭如何使用dumpsys完成常見任務,例如檢查輸入 ,RAM,電池或網絡診斷.
來自官方文檔(dumpsys詳細使用指南請戳這裏)
命令格式
adb shell dumpsys activity [options] [WHAT]
- option 參數
option | 含義 |
---|---|
-a | 包括所有可用 Servier 狀態 |
-c | 包括 Client 狀態,即 App 端情況 |
-p PackageName | 限定輸出指定包名 |
- WHAT 參數
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
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
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
adb shell dumpsys activity activities
意義:顯示當前所有在運行的任務棧,它們的 id 分別是什麼。對於每個 Task 也有 Activity 數量等信息,同時也列出了其中的 Activity 列表,並且對於每個 Activity 也有比較詳細的描述,比如啓動它的 Intent 的內容。如果覺得內容過多,只想看看棧的內容,也可以直接跳到「Running activities (most recent first) 那部分,比較簡潔而又明瞭的列出了棧中的 Activity 列表,就能知道當按下返回鍵的時候會應該回到哪個 Activity 」
adb shell dumpsys 「PackageName」
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 「PackageName」
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 的列表 |