码迷,mamicode.com
首页 > 数据库 > 详细

adb shell dumpsys 命令

时间:2019-02-17 10:47:44      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:用法   括号   用户系统   c89   man   format   列表   this   proxy   

 目录结构

一、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 命令

标签:用法   括号   用户系统   c89   man   format   列表   this   proxy   

原文地址:https://www.cnblogs.com/xiaowenshu/p/10390246.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!