1. 程式人生 > >adb shell dumpsys 命令

adb shell dumpsys 命令

圖片 sharesdk 選項 arm orm ram war runt apk

目錄結構

一、dumpsys 命令介紹

二、包信息查詢

三、avtivity 信息查詢

四、網絡信息查詢

五、其他常用服務信息查詢

六、用法補充

一、dumpsys命令介紹

1.命令說明

Dumpsys用戶系統診斷,它運行在設備上,並提供系統服務狀態信息

命令格式: adb shell dumpsys [system serbices]

2.系統服務查詢

如果直接運行adb shell dumpsys,將會獲得所有的系統服務信息,那是非常多的,為了更容易管理輸出,可以指定你想要檢查的服務,例如:

adb shell dumpsys –l

adb shell serverce list

#都是查看有哪些系統服務(需要哪些服務就指定哪些服務)

命令行參數:

不同的服務有不同的選項,一下兩個是常見的參數:

-h:對於大多數的服務,可以添加-h看到文本的幫助

-c:對於一些服務,可以添加-c查看數據會更友好

例如:

adb shell dumpsys meminfo –h

技術分享圖片

二、包信息查詢

子命令格式:

adb shell dumpsys package [-h] [-f] [—checkin] [cmd]…

參數

說明

-h 打印幫助信息
-f 打印intent filter的信息
--checkin 打印出已經登記的庫、系統功能、安裝包
cmd 子命令(可以在-h幫助文檔中查看有哪些子命令)

cmd子命令

說明

prov[iders] 獲取content providers
p[ackages] 獲取安裝包基本信息
s[hared-user] 獲取共享用戶ID的應用
m[essages] 打印運行時收集的信息
v[erifiers] 打印包校驗信息
version 打印數據庫版本信息
write 寫當前位置
<package.name> 輸出給定包的信息
installs 安裝會話的詳細信息
l[ibraries] 列出已知的共享庫
f[ibraries] 列出手機的功能
k[eysets] 列出各個包的Signing KeySets
r[esolvers] 獲取intent filter
perm[issions] 獲取權限
pref[erred] 打印包首選項
preferred-xml [—full] 打印包首選項,xml格式打印

三、activity信息查詢

子命令格式:

adb shell dumpsys activity [-a] [-c]…

參數

說明

-a 包括所有可用的服務器狀態
-c 包括客戶端狀態
-p 限制輸出為給定的包,例如:
adb shell dumpsys activity -p com.android.browser
-h 打印幫助信息
cmd 子命令

cmd子命令

說明

a[ctivities] activity堆棧狀態
r[recents] 最近activity的狀態
b[rodacasts] [package_name] [histpry [-s]] 廣播狀態
i[ntents] [package_name] 掛起的intent狀態
p[rocesses] [package_name] 進程狀態
o[om] oom管理
perm[issions] url權限授權狀態
prov[iders] [comp_spec…] content provider狀態
provider [comp_spec] provider客戶端狀態
s[ervices] [comp_spec…] 服務狀態
as[sociations] 跟蹤應用程序的關聯
service [comp_spec] 服務客戶端狀態
package [package_name] 給的包的所有狀態
all 轉儲所有的activityes
top 轉儲棧頂的activity
write 寫入所有掛起狀態存儲
track-associations 允許會話跟蹤
untrack-associations 禁用和明確會話跟蹤,命令參數可能也是一個comp_spec 轉儲的activity

四、網絡信息查詢

子命令

說明

命令格式

connectivity 網絡連接 adb shell dumpsys connectivity
netpolicy 網絡策略 adb shell dumpsys netpolicy
netstats 網絡狀態 adb shell dumpsys netstats
network_management 網絡管理 adb shell dumpsys network_management

五、其他常用服務信息查詢

子命令 說明 命令格式
meminfo 內存 adn shell dumpsys meminfo
cpuinfo CPU adn shell dumpsys cpuinfo
gfxinfo 幀率 adn shell dumpsys gfxinfo
display 顯示 adn shell dumpsys display
power 電源 adn shell dumpsys power
batterystats 電池狀態 adn shell dumpsys batterystats
battery 電池 adn shell dumpsys battery
alarm 鬧鐘 adn shell dumpsys alarm
location 位置 adn shell dumpsys location

六、用法補充

出發點一:

Android 引入了「任務棧」的概念,這個概念對於 Android 設備上的返回按鍵有極其重要的聯系。有時候按下返回按鈕或者點擊關閉當前 Activity 的操作,都不知道 Android 系統會把程序帶到哪個 Activity ,不確定這是否是最後一個 Activity 以致退出了整個程序。亦或者一些按鈕和操作循環產生 Activity 而造成內存膨脹。對於這些問題,如果能夠在調試期間知道當前任務棧的情況,就能很方便的觀察和發現問題存在的原因,進而選擇正確的 launchMode ,設置且當 Intent 的 Flag 來使程序達到預期的效果。

出發點二:

手機裏裝著一個應用,在不反編譯也不做其他處理的情況下,你可以對這個應用了解多少。

出發點三:「出自官方文檔」

dumpsys is a tool that runs on Android devices and provides information about system services. You can call dumpsys from the command line using the Android Debug Bridge (ADB) to get diagnostic output for all system services running on a connected device. This output is typically more verbose than you may want, so use the command line options described below to get output for only the system services you‘re interested in. This page also describes how to use dumpsys to accomplish common tasks, such as inspecting input, RAM, battery, or network diagnostics.

命令格式:
adb shell dumpsys activity [options] [WHAT]

option 參數
options含義
-a 包括所有可用 Servier 狀態
-c 包括 Client 狀態,即 App 端情況
-p PACKAGE 限定輸出指定包名
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 

輸出:

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 com.jianshu.haruki id=101
  ACTIVITY com.jianshu.haruki/com.baiji.jianshu.MainActivity fb571c1 pid=21291
// ... 只舉出了前兩行,省略了 N 行代碼

獲取當前 Android 系統中與用戶交互的 Activity 的詳細信息,根據輸出可得到簡書的應用包名是:「com.jianshu .haruki」

練習三:

輸入:

adb shell dumpsys activity activities

意義:

顯示當前所有在運行的任務棧,它們的 id 分別是什麽。對於每個 Task 也有 Activity 數量等信息,同時也列出了其中的 Activity 列表,並且對於每個 Activity 也有比較詳細的描述,比如啟動它的 Intent 的內容。如果覺得內容過多,只想看看棧的內容,也可以直接跳到「Running activities (most recent first) 那部分,比較簡潔而又明了的列出了棧中的 Activity 列表,就能知道當按下返回鍵的時候會應該回到哪個 Activity 」
練習四:

輸入:

adb shell dumpsys package com.jianshu.haruki[此處寫的是『簡書』的應用包名]

輸出:

Activity Resolver Table: // 標註:這裏開始解析「activity」標簽
  Full MIME Types:
      text/plain:
        28edf2a com.jianshu.haruki/com.baiji.jianshu.ui.editor.EditorActivityV19

  Base MIME Types:
      text:
        28edf2a com.jianshu.haruki/com.baiji.jianshu.ui.editor.EditorActivityV19

  Schemes: 
      jianshu: // 標註:列出了所有以 jianshu 為 scheme 的 Activity
        3057264 com.jianshu.haruki/com.baiji.jianshu.ui.messages.submission.SubmissionDetailActivity
        350011b com.jianshu.haruki/com.baiji.jianshu.MainActivity
        96cc891 com.jianshu.haruki/com.baiji.jianshu.ui.user.collection.CollectionActivity (2 filters)
        993c3f6 com.jianshu.haruki/com.baiji.jianshu.ui.user.userinfo.UserCenterActivity (2 filters)
        f48e2b8 com.jianshu.haruki/com.baiji.jianshu.activity.NotifyDetailActivity
        f845ccd com.jianshu.haruki/com.baiji.jianshu.ui.articledetail.ArticleDetailActivity
        fe393f7 com.jianshu.haruki/com.baiji.jianshu.ui.user.notebook.normal.NotebookActivity (2 filters)
      tencent100410602:
        3302982 com.jianshu.haruki/com.tencent.tauth.AuthActivity

  Non-Data Actions: // 標註:列出了所有有「intent-filter」標簽但是無「data」標簽的 Activity
      android.intent.action.MAIN:
        4b37893 com.jianshu.haruki/com.baiji.jianshu.ui.splash.SplashScreenActivity
      com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY:
        3d950d0 com.jianshu.haruki/haruki.jianshu.com.lib_share.weibo.WBShareActivity
      android.intent.action.CREATE_SHORTCUT:
        28edf2a com.jianshu.haruki/com.baiji.jianshu.ui.editor.EditorActivityV19
      // 省略多行

  MIME Typed Actions:
      android.intent.action.SEND:
        28edf2a com.jianshu.haruki/com.baiji.jianshu.ui.editor.EditorActivityV19

Receiver Resolver Table: // 標註:這裏開始解析「receiver」標簽
  Schemes:
      package: // 標註:列出了所有以 jianshu 為 scheme 的 receiver
        c930aef com.jianshu.haruki/com.huawei.android.pushagent.PushEventReceiver

  Non-Data Actions:// 標註:列出了所有含「intent-filter」標簽但是無「action」標簽的 receiver
      com.xiaomi.mipush.MESSAGE_ARRIVED:
        bcaa9fc com.jianshu.haruki/com.baiji.jianshu.ui.receiver.xiaomi.XiaoMiPushReceiver
      android.intent.action.ACTION_POWER_DISCONNECTED:
        9fd5885 com.jianshu.haruki/com.igexin.sdk.PushReceiver
      // 省略多行

Service Resolver Table:// 標註:這裏開始解析「service」標簽
  Non-Data Actions:// 標註:列出了所有含「intent-filter」標簽但是無「action」標簽的 service
      com.google.firebase.INSTANCE_ID_EVENT:
        649f732 com.jianshu.haruki/com.google.firebase.iid.FirebaseInstanceIdService
      com.igexin.sdk.action.service.message:
        97bac83 com.jianshu.haruki/com.igexin.sdk.PushService

Permissions:
  Permission [com.jianshu.haruki.permission.C2D_MESSAGE] (88a8e00):
    sourcePackage=com.jianshu.haruki
    uid=10141 gids=null type=0 prot=signature
    perm=Permission{e42a639 com.jianshu.haruki.permission.C2D_MESSAGE}
    packageSetting=PackageSetting{a1c547e com.jianshu.haruki/10141}
  Permission [getui.permission.GetuiService.com.jianshu.haruki] (7428ddf):
    sourcePackage=com.jianshu.haruki
    uid=10141 gids=null type=0 prot=normal
    perm=Permission{80a8a2c getui.permission.GetuiService.com.jianshu.haruki}
    packageSetting=PackageSetting{a1c547e com.jianshu.haruki/10141}
  Permission [com.jianshu.haruki.permission.MIPUSH_RECEIVE] (c9e6cf5):
    sourcePackage=com.jianshu.haruki
    uid=10141 gids=null type=0 prot=signature
    perm=Permission{f253a8a com.jianshu.haruki.permission.MIPUSH_RECEIVE}
    packageSetting=PackageSetting{a1c547e com.jianshu.haruki/10141}

Registered ContentProviders:
  com.jianshu.haruki/com.google.firebase.provider.FirebaseInitProvider:
    Provider{b6c28fb com.jianshu.haruki/com.google.firebase.provider.FirebaseInitProvider}
  com.jianshu.haruki/com.baiji.jianshu.db.core.JianshuProvider:
    Provider{eac1d18 com.jianshu.haruki/com.baiji.jianshu.db.core.JianshuProvider}
  com.jianshu.haruki/com.sensorsdata.analytics.android.sdk.SensorsDataContentProvider:
    Provider{8b5e371 com.jianshu.haruki/com.sensorsdata.analytics.android.sdk.SensorsDataContentProvider}

ContentProvider Authorities:
  [com.jianshu.haruki.SensorsDataContentProvider]:
    Provider{8b5e371 com.jianshu.haruki/com.sensorsdata.analytics.android.sdk.SensorsDataContentProvider}
      applicationInfo=ApplicationInfo{b247556 com.jianshu.haruki}
  [com.jianshu.haruki.firebaseinitprovider]:
    Provider{b6c28fb com.jianshu.haruki/com.google.firebase.provider.FirebaseInitProvider}
      applicationInfo=ApplicationInfo{b247556 com.jianshu.haruki}
  [com.jianshu.haruki.provider]:
    Provider{eac1d18 com.jianshu.haruki/com.baiji.jianshu.db.core.JianshuProvider}
      applicationInfo=ApplicationInfo{b247556 com.jianshu.haruki}

Key Set Manager:
  [com.jianshu.haruki]
      Signing KeySets: 67

Packages:
  Package [com.jianshu.haruki] (a1c547e):
    userId=10141
    pkg=Package{ca59d7 com.jianshu.haruki}
    codePath=/data/app/com.jianshu.haruki-2
    resourcePath=/data/app/com.jianshu.haruki-2
    legacyNativeLibraryDir=/data/app/com.jianshu.haruki-2/lib
    primaryCpuAbi=arm64-v8a
    secondaryCpuAbi=null
    versionCode=2017082915 targetSdk=23
    versionName=2.6.0
    splits=[base]
    applicationInfo=ApplicationInfo{b247556 com.jianshu.haruki}
    flags=[ HAS_CODE ALLOW_CLEAR_USER_DATA LARGE_HEAP ]
    dataDir=/data/user/0/com.jianshu.haruki
    supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
    timeStamp=2017-09-22 15:39:43
    firstInstallTime=2017-09-22 15:38:20
    lastUpdateTime=2017-09-22 15:40:02
    signatures=PackageSignatures{d1f2c4 [8f445ad]}
    installPermissionsFixed=true installStatus=1
    pkgFlags=[ HAS_CODE ALLOW_CLEAR_USER_DATA LARGE_HEAP ]
    declared permissions:
      getui.permission.GetuiService.com.jianshu.haruki: prot=normal, INSTALLED
      com.jianshu.haruki.permission.MIPUSH_RECEIVE: prot=signature, INSTALLED
      com.jianshu.haruki.permission.C2D_MESSAGE: prot=signature, INSTALLED
    requested permissions:
      android.permission.INTERNET
      android.permission.WRITE_EXTERNAL_STORAGE
      // 省略多行
    install permissions:
      com.jianshu.haruki.permission.C2D_MESSAGE: granted=true
      com.google.android.c2dm.permission.RECEIVE: granted=true
      android.permission.MANAGE_ACCOUNTS: granted=true
      getui.permission.GetuiService.com.jianshu.haruki: granted=true
      // 省略多行
    User 0:  installed=true hidden=false stopped=false notLaunched=false enabled=0
      gids=[3002, 3003, 3001]
      runtime permissions:
        android.permission.READ_EXTERNAL_STORAGE: granted=true
        android.permission.READ_PHONE_STATE: granted=true
        android.permission.WRITE_EXTERNAL_STORAGE: granted=true
      disabledComponents:
        com.huawei.android.pushagent.PushBootReceiver
練習五:

輸入:

adb shell dumpsys meminfo com.jianshu.haruki[此處寫的是『簡書』的應用包名]

輸出:

Applications Memory Usage (kB):
Uptime: 94384953 Realtime: 367426401

** MEMINFO in pid 21291 [com.jianshu.haruki] **
                   Pss  Private  Private  Swapped     Heap     Heap     Heap
                 Total    Dirty    Clean    Dirty     Size    Alloc     Free
                ------   ------   ------   ------   ------   ------   ------
  Native Heap    20236    19432        0     1180    50580    48838     1741
  Dalvik Heap    12299    12264        0       56    52530    45197     7333
 Dalvik Other    23104    23064        0     9680                           
        Stack     1484     1484        0        0                           
       Ashmem      134      128        0        0                           
      Gfx dev    14698    14596        0        0                           
    Other dev       10        0        8        0                           
     .so mmap     5924      252     4312     2908                           
    .apk mmap    27189      144    26692        0                           
    .ttf mmap      130        0      104        0                           
    .dex mmap    12242       12    11060        0                           
    .oat mmap     3661        0     1256        4                           
    .art mmap     2450     1940       92      144                           
   Other mmap     1300       12     1280        0                           
   EGL mtrack    41280    41280        0        0                           
      Unknown     6052     6044        0       84                           
        TOTAL   172193   120652    44804    14056   103110    94035     9074
 
 App Summary
                       Pss(KB)
                        ------
           Java Heap:    14296
         Native Heap:    19432
                Code:    43832
               Stack:     1484
            Graphics:    55876
       Private Other:    30536
              System:     6737
 
               TOTAL:   172193      TOTAL SWAP (KB):    14056
 
 Objects
               Views:      837         ViewRootImpl:        1
         AppContexts:        2           Activities:        1
              Assets:        4        AssetManagers:        2
       Local Binders:       31        Proxy Binders:       31
       Parcel memory:       23         Parcel count:       92
    Death Recipients:        1      OpenSSL Sockets:        2
 
 SQL
         MEMORY_USED:     1054
  PAGECACHE_OVERFLOW:      297          MALLOC_SIZE:       62
 
 DATABASES
      pgsz     dbsz   Lookaside(b)          cache  Dbname
         4       24             36       112/19/5  /data/user/0/com.jianshu.haruki/databases/com.jianshu.haruki
         4       76            176      116/64/25  /data/user/0/com.jianshu.haruki/databases/google_app_measurement.db
         4       40             33         6/21/5  /data/user/0/com.jianshu.haruki/databases/tencent_analysis.db
         4       32             98       75/26/12  /data/user/0/com.jianshu.haruki/databases/bugly_db_
         4       40             19         4/19/3  /data/user/0/com.jianshu.haruki/databases/pri_tencent_analysis.db
         4       20             34         3/18/4  /data/user/0/com.jianshu.haruki/databases/ThrowalbeLog.db
         4       20             32       786/19/5  /data/user/0/com.jianshu.haruki/databases/sharesdk.db
         4      124             57       45/24/10  /data/user/0/com.jianshu.haruki/databases/jian_shu.db

commanddescription
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 的列表

參考鏈接:
官方文檔,這裏有比較詳細的文檔介紹: https://developer.android.com/studio/command-line/dumpsys.html
開發必備---你應該知道的一些 ADB 命令 http://www.jianshu.com/p/0693b841c83b
dumpsys 命令用法 http://gityuan.com/2017/07/04/ams_dumpsys/

adb shell dumpsys 命令