andorid——dumpsys

Android提供的dumpsys工具可以用于查看手机中的应用程序和系统服务信息与状态,手机连接电脑后可以直接命令行执行adb shell dumpsys 查看所有支持的Service但是这样输出的太多,可以通过dumpsys | grep "DUMP OF SERVICE" 仅显示主要的Service的信息。关于这个命令的使用方法在这里做一下记录,以备使用。

关于`adb shell dumpsy` 命令的源码分析请参考我的博客Android 深入理解 dumpsys

1、dumpsys支持的所有命令

输入:

  1. adb shell dumpsys -l  
adb shell dumpsys -l

可以查看当前支持的所有系统服务列表


输入:

  1. adb shell dumpsys | grep DUMP  
adb shell dumpsys | grep DUMP

  1. adb shell dumpsys | grep "DUMP OF SERVICE"  
adb shell dumpsys | grep "DUMP OF SERVICE"

也可以列出当前手机支持的所有dumpsys参数:

  1. DUMP OF SERVICE Exynos.HWCService:  
  2. DUMP OF SERVICE SurfaceFlinger:  
  3. DUMP OF SERVICE access_control:  
  4. DUMP OF SERVICE accessibility:  
  5. DUMP OF SERVICE account:  
  6. DUMP OF SERVICE activity:  
  7. DUMP OF SERVICE alarm:  
  8. DUMP OF SERVICE android.security.keystore:  
  9. DUMP OF SERVICE appops:  
  10. DUMP OF SERVICE appwidget:  
  11. DUMP OF SERVICE audio:  
  12. DUMP OF SERVICE backup:  
  13. DUMP OF SERVICE battery:  
  14. DUMP OF SERVICE batterypropreg:  
  15. DUMP OF SERVICE batterystats:  
  16. DUMP OF SERVICE bluetooth_manager:  
  17. DUMP OF SERVICE blurglassinfo:  
  18. DUMP OF SERVICE clipboard:  
  19. DUMP OF SERVICE com.meizu.nfc.NxpExt:  
  20. DUMP OF SERVICE commontime_management:  
  21. DUMP OF SERVICE connectivity:  
  22. DUMP OF SERVICE consumer_ir:  
  23. DUMP OF SERVICE content:  
  24. DUMP OF SERVICE country_detector:  
  25. DUMP OF SERVICE cpuinfo:  
  26. DUMP OF SERVICE dbinfo:  
  27. DUMP OF SERVICE deivce_states:  
  28. DUMP OF SERVICE device_policy:  
  29. DUMP OF SERVICE devicestoragemonitor:  
  30. DUMP OF SERVICE diskstats:  
  31. DUMP OF SERVICE display:  
  32. DUMP OF SERVICE dreams:  
  33. DUMP OF SERVICE drm.drmManager:  
  34. DUMP OF SERVICE dropbox:  
  35. DUMP OF SERVICE entropy:  
  36. DUMP OF SERVICE gesture_manager:  
  37. DUMP OF SERVICE gfxinfo:  
  38. DUMP OF SERVICE hardware:  
  39. DUMP OF SERVICE input:  
  40. DUMP OF SERVICE input_method:  
  41. DUMP OF SERVICE iphonesubinfo:  
  42. DUMP OF SERVICE isms:  
  43. DUMP OF SERVICE location:  
  44. DUMP OF SERVICE lock_settings:  
  45. DUMP OF SERVICE media.audio_flinger:  
  46. DUMP OF SERVICE media.audio_policy:  
  47. DUMP OF SERVICE media.camera:  
  48. DUMP OF SERVICE media.player:  
  49. DUMP OF SERVICE media_router:  
  50. DUMP OF SERVICE meizu.camera:  
  51. DUMP OF SERVICE meminfo:  
  52. DUMP OF SERVICE mount:  
  53. DUMP OF SERVICE netpolicy:  
  54. DUMP OF SERVICE netstats:  
  55. DUMP OF SERVICE network_management:  
  56. DUMP OF SERVICE nfc:  
  57. DUMP OF SERVICE notification:  
  58. DUMP OF SERVICE package:  
  59. DUMP OF SERVICE permission:  
  60. DUMP OF SERVICE phone:  
  61. DUMP OF SERVICE phone_ext:  
  62. DUMP OF SERVICE power:  
  63. DUMP OF SERVICE pppoe:  
  64. DUMP OF SERVICE print:  
  65. DUMP OF SERVICE procstats:  
  66. DUMP OF SERVICE samba_client:  
  67. DUMP OF SERVICE samba_server:  
  68. DUMP OF SERVICE samplingprofiler:  
  69. DUMP OF SERVICE scheduling_policy:  
  70. DUMP OF SERVICE search:  
  71. DUMP OF SERVICE secloader:  
  72. DUMP OF SERVICE secloader2:  
  73. DUMP OF SERVICE secsystemserver:  
  74. DUMP OF SERVICE sensorservice:  
  75. DUMP OF SERVICE serial:  
  76. DUMP OF SERVICE servicediscovery:  
  77. DUMP OF SERVICE simphonebook:  
  78. DUMP OF SERVICE sip:  
  79. DUMP OF SERVICE statusbar:  
  80. DUMP OF SERVICE telephony.registry:  
  81. DUMP OF SERVICE textservices:  
  82. DUMP OF SERVICE uimode:  
  83. DUMP OF SERVICE updatelock:  
  84. DUMP OF SERVICE usagestats:  
  85. DUMP OF SERVICE usb:  
  86. DUMP OF SERVICE user:  
  87. DUMP OF SERVICE vibrator:  
  88. DUMP OF SERVICE voicesense:  
  89. DUMP OF SERVICE wallpaper:  
  90. DUMP OF SERVICE wifi:  
  91. DUMP OF SERVICE wifip2p:  
  92. DUMP OF SERVICE window:  
DUMP OF SERVICE Exynos.HWCService:
DUMP OF SERVICE SurfaceFlinger:
DUMP OF SERVICE access_control:
DUMP OF SERVICE accessibility:
DUMP OF SERVICE account:
DUMP OF SERVICE activity:
DUMP OF SERVICE alarm:
DUMP OF SERVICE android.security.keystore:
DUMP OF SERVICE appops:
DUMP OF SERVICE appwidget:
DUMP OF SERVICE audio:
DUMP OF SERVICE backup:
DUMP OF SERVICE battery:
DUMP OF SERVICE batterypropreg:
DUMP OF SERVICE batterystats:
DUMP OF SERVICE bluetooth_manager:
DUMP OF SERVICE blurglassinfo:
DUMP OF SERVICE clipboard:
DUMP OF SERVICE com.meizu.nfc.NxpExt:
DUMP OF SERVICE commontime_management:
DUMP OF SERVICE connectivity:
DUMP OF SERVICE consumer_ir:
DUMP OF SERVICE content:
DUMP OF SERVICE country_detector:
DUMP OF SERVICE cpuinfo:
DUMP OF SERVICE dbinfo:
DUMP OF SERVICE deivce_states:
DUMP OF SERVICE device_policy:
DUMP OF SERVICE devicestoragemonitor:
DUMP OF SERVICE diskstats:
DUMP OF SERVICE display:
DUMP OF SERVICE dreams:
DUMP OF SERVICE drm.drmManager:
DUMP OF SERVICE dropbox:
DUMP OF SERVICE entropy:
DUMP OF SERVICE gesture_manager:
DUMP OF SERVICE gfxinfo:
DUMP OF SERVICE hardware:
DUMP OF SERVICE input:
DUMP OF SERVICE input_method:
DUMP OF SERVICE iphonesubinfo:
DUMP OF SERVICE isms:
DUMP OF SERVICE location:
DUMP OF SERVICE lock_settings:
DUMP OF SERVICE media.audio_flinger:
DUMP OF SERVICE media.audio_policy:
DUMP OF SERVICE media.camera:
DUMP OF SERVICE media.player:
DUMP OF SERVICE media_router:
DUMP OF SERVICE meizu.camera:
DUMP OF SERVICE meminfo:
DUMP OF SERVICE mount:
DUMP OF SERVICE netpolicy:
DUMP OF SERVICE netstats:
DUMP OF SERVICE network_management:
DUMP OF SERVICE nfc:
DUMP OF SERVICE notification:
DUMP OF SERVICE package:
DUMP OF SERVICE permission:
DUMP OF SERVICE phone:
DUMP OF SERVICE phone_ext:
DUMP OF SERVICE power:
DUMP OF SERVICE pppoe:
DUMP OF SERVICE print:
DUMP OF SERVICE procstats:
DUMP OF SERVICE samba_client:
DUMP OF SERVICE samba_server:
DUMP OF SERVICE samplingprofiler:
DUMP OF SERVICE scheduling_policy:
DUMP OF SERVICE search:
DUMP OF SERVICE secloader:
DUMP OF SERVICE secloader2:
DUMP OF SERVICE secsystemserver:
DUMP OF SERVICE sensorservice:
DUMP OF SERVICE serial:
DUMP OF SERVICE servicediscovery:
DUMP OF SERVICE simphonebook:
DUMP OF SERVICE sip:
DUMP OF SERVICE statusbar:
DUMP OF SERVICE telephony.registry:
DUMP OF SERVICE textservices:
DUMP OF SERVICE uimode:
DUMP OF SERVICE updatelock:
DUMP OF SERVICE usagestats:
DUMP OF SERVICE usb:
DUMP OF SERVICE user:
DUMP OF SERVICE vibrator:
DUMP OF SERVICE voicesense:
DUMP OF SERVICE wallpaper:
DUMP OF SERVICE wifi:
DUMP OF SERVICE wifip2p:
DUMP OF SERVICE window:

2、具体命令如何查看帮助

从上面可以看出可以查看的Service非常多,“DUMP OF SERVICE”关键字后面的单词都可以直接通过 dumpsys + 单词 查看相关信息,具体每一个如何使用有一种通用的查看帮助的办法。
查看每一个命令的使用帮助,以下以activity为例演示:

  1. $ adb shell dumpsys activity -h  
  2.   
  3. Activity manager dump options:  
  4.   [-a] [-c] [-h] [cmd] ...  
  5.   cmd may be one of:  
  6.     a[ctivities]: activity stack state  
  7.     b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state  
  8.     i[ntents] [PACKAGE_NAME]: pending intent state  
  9.     p[rocesses] [PACKAGE_NAME]: process state  
  10.     o[om]: out of memory management  
  11.     prov[iders] [COMP_SPEC ...]: content provider state  
  12.     provider [COMP_SPEC]: provider client-side state  
  13.     s[ervices] [COMP_SPEC ...]: service state  
  14.     service [COMP_SPEC]: service client-side state  
  15.     package [PACKAGE_NAME]: all state related to given package  
  16.     all: dump all activities  
  17.     top: dump the top activity  
  18.   cmd may also be a COMP_SPEC to dump activities.  
  19.   COMP_SPEC may be a component name (com.foo/.myApp),  
  20.     a partial substring in a component name, a  
  21.     hex object identifier.  
  22.   -a: include all available server state.  
  23.   -c: include client state.  
$ adb shell dumpsys activity -h

Activity manager dump options:
  [-a] [-c] [-h] [cmd] ...
  cmd may be one of:
    a[ctivities]: activity stack state
    b[roadcasts] [PACKAGE_NAME] [history [-s]]: broadcast state
    i[ntents] [PACKAGE_NAME]: pending intent state
    p[rocesses] [PACKAGE_NAME]: process state
    o[om]: out of memory management
    prov[iders] [COMP_SPEC ...]: content provider state
    provider [COMP_SPEC]: provider client-side state
    s[ervices] [COMP_SPEC ...]: service state
    service [COMP_SPEC]: service client-side state
    package [PACKAGE_NAME]: all state related to given package
    all: dump all activities
    top: dump the top activity
  cmd may also be a COMP_SPEC to dump activities.
  COMP_SPEC may be a component name (com.foo/.myApp),
    a partial substring in a component name, a
    hex object identifier.
  -a: include all available server state.
  -c: include client state.

这样就可以清楚每个命名的使用方法以及对应输出内容的信息查看方法。

以window为例:

  1. $ adb shell dumpsys window -h  
  2.   
  3. Window manager dump options:  
  4.   [-a] [-h] [cmd] ...  
  5.   cmd may be one of:  
  6.     i[input]: input subsystem state  
  7.     p[policy]: policy state  
  8.     s[essions]: active sessions  
  9.     surfaces: active surfaces (debugging enabled only)  
  10.     d[isplays]: active display contents  
  11.     t[okens]: token list  
  12.     w[indows]: window list  
  13.   cmd may also be a NAME to dump windows.  NAME may  
  14.     be a partial substring in a window name, a  
  15.     Window hex object identifier, or  
  16.     "all" for all windows, or  
  17.     "visible" for the visible windows.  
  18.   -a: include all available server state.  
  19.   -d list                     list the all of debug zones  
  20.   -d enable  <zone zone ...>  enable the debug zone  
  21.   -d disable <zone zone ...>  disable the debug zone  
  22.   zone usage :   
  23.     0  : DEBUG  
  24.     1  : DEBUG_FOCUS  
  25.     2  : DEBUG_ANIM  
  26.     3  : DEBUG_LAYOUT  
  27.     4  : DEBUG_RESIZE  
  28.     5  : DEBUG_LAYERS  
  29.     6  : DEBUG_INPUT  
  30.     7  : DEBUG_INPUT_METHOD  
  31.     8  : DEBUG_VISIBILITY  
  32.     9  : DEBUG_WINDOW_MOVEMENT  
  33.     10 : DEBUG_ORIENTATION  
  34.     11 : DEBUG_CONFIGURATION  
  35.     12 : DEBUG_APP_TRANSITIONS  
  36.     13 : DEBUG_STARTING_WINDOW  
  37.     14 : DEBUG_REORDER  
  38.     15 : DEBUG_WALLPAPER  
  39.     16 : DEBUG_WALLPAPER_LIGHT  
  40.     17 : SHOW_TRANSCATIONS  
  41.     18 : HIDE_STACK_CRAWLS  
  42.     19 : PROFILE_ORIENTATION  
  43.     20 : DEBUG_TASK_MOVEMENT  
  44.     21 : DEBUG_ADD_REMOVE  
  45.     22 : DEBUG_TOKEN_MOVEMENT  
  46.     23 : DEBUG_APP_ORIENTATION  
  47.     24 : DEBUG_DRAG  
  48.     25 : DEBUG_SCREEN_ON  
  49.     26 : DEBUG_SCREENSHOT  
  50.     27 : DEBUG_BOOT  
  51.     28 : SHOW_SURFACE_ALLOC  
  52.     29 : SHOW_LIGHT_TRANSACTIONS  
  53.     30 : DEBUG_LAYOUT_REPEATS  
  54.     31 : DEBUG_SURFACE_TRACE  
  55.     32 : DEBUG_WINDOW_TRACE  
  56.     33 : DEBUG_WINDOW  
  57.     34 : DEBUG_STACK  
  58.     35 : DEBUG_DIM_LAYER  
  59.     36 : DEBUG_KEYGUARD  
$ adb shell dumpsys window -h

Window manager dump options:
  [-a] [-h] [cmd] ...
  cmd may be one of:
    i[input]: input subsystem state
    p[policy]: policy state
    s[essions]: active sessions
    surfaces: active surfaces (debugging enabled only)
    d[isplays]: active display contents
    t[okens]: token list
    w[indows]: window list
  cmd may also be a NAME to dump windows.  NAME may
    be a partial substring in a window name, a
    Window hex object identifier, or
    "all" for all windows, or
    "visible" for the visible windows.
  -a: include all available server state.
  -d list                     list the all of debug zones
  -d enable  <zone zone ...>  enable the debug zone
  -d disable <zone zone ...>  disable the debug zone
  zone usage : 
    0  : DEBUG
    1  : DEBUG_FOCUS
    2  : DEBUG_ANIM
    3  : DEBUG_LAYOUT
    4  : DEBUG_RESIZE
    5  : DEBUG_LAYERS
    6  : DEBUG_INPUT
    7  : DEBUG_INPUT_METHOD
    8  : DEBUG_VISIBILITY
    9  : DEBUG_WINDOW_MOVEMENT
    10 : DEBUG_ORIENTATION
    11 : DEBUG_CONFIGURATION
    12 : DEBUG_APP_TRANSITIONS
    13 : DEBUG_STARTING_WINDOW
    14 : DEBUG_REORDER
    15 : DEBUG_WALLPAPER
    16 : DEBUG_WALLPAPER_LIGHT
    17 : SHOW_TRANSCATIONS
    18 : HIDE_STACK_CRAWLS
    19 : PROFILE_ORIENTATION
    20 : DEBUG_TASK_MOVEMENT
    21 : DEBUG_ADD_REMOVE
    22 : DEBUG_TOKEN_MOVEMENT
    23 : DEBUG_APP_ORIENTATION
    24 : DEBUG_DRAG
    25 : DEBUG_SCREEN_ON
    26 : DEBUG_SCREENSHOT
    27 : DEBUG_BOOT
    28 : SHOW_SURFACE_ALLOC
    29 : SHOW_LIGHT_TRANSACTIONS
    30 : DEBUG_LAYOUT_REPEATS
    31 : DEBUG_SURFACE_TRACE
    32 : DEBUG_WINDOW_TRACE
    33 : DEBUG_WINDOW
    34 : DEBUG_STACK
    35 : DEBUG_DIM_LAYER
    36 : DEBUG_KEYGUARD

比如adb shell dumpsys window -d enable 10就是打开DEBUG_ORIENTATION,这样就把代码中的关于屏幕方向旋转相关的Log打印出来。

3、查看某个具体应用的信息

比如查看浏览器的内存使用信息:
adb shell dumpsys meminfo com.android.browser

4、一些常用命令解释

adb shell dumpsys activity: 显示activity的相关信息,包括任务栈等;

adb shell dumpsys meminfo:查看各个进程内存使用情况
adb shell dumpsys SurfaceFlinger: 查看UI绘制的各个层级信息
adb shell dumpsys window: 显示键盘,窗口和它们的关系

adb shell dumpsys package <包名>: 查看该包的具体信息
adb shell dumpsys statusbar: 显示状态栏相关信息
adb shell dumpsys usagestats: 每个应用的启动次数和时间
adb shell dumpsys battery: 电池信息
adb shell dumpsys diskstats: 磁盘相关信息
adb shell dumpsys alarm: 显示Alarm信息
adb shell dumpsys wifi: 显示wifi信息
adb shell dumpsys user:查看当前的用户情况

5、参考资料:

http://www.open-open.com/lib/view/open1405061994872.html
https://source.android.com/devices/tech/input/dumpsys.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值