android调试——教你用dumpsys命令调试

Posted 一代小强

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android调试——教你用dumpsys命令调试相关的知识,希望对你有一定的参考价值。

“这一篇就聊聊dumpsys 比较常用的命令“

dumpsys 服务

基本用法

adb shell dumpsys [-t timeout] [--help | -l | --skip services | service [arguments] | -c | -h]

查看可与 dumpsys 配合使用的系统服务的完整列表,请使用以下命令:

adb shell dumpsys -l

某些服务可能允许您传递可选参数。您可以通过将 -h 选项与服务名称一起传递来了解这些可选参数,如下所示:

adb shell dumpsys procstats -h
// 查看 com.demo.package 应用的 servicecs 启动记录
adb shell dumpsys activity services -p com.demo.package

// 查看activity启动记录 
adb shell dumpsys activity

官网有一些用法的说明 可见 dumpsys命令

其实官网上的介绍也是比较简单,并且没有什么实际用途

所以,这里列举了大部分开发中会用到的服务

1、dumpsys SurfaceFlinger

查看屏幕静态帧信息

Static screen stats:
  < 1 frames: 0.335 s (1.5%) // 每帧的耗时情况
  < 2 frames: 2.049 s (9.1%)
	。。。。
  7+ frames: 19.625 s (87.1%)

查看BufferLayer(缓冲区)情况

+ BufferLayer (WindowToken3c467fd android.os.BinderProxy@3eec54#0)
  Region TransparentRegion (this=a2fed158 count=1)
    [  0,   0,   0,   0]
  Region VisibleRegion (this=a2fed008 count=1)
    [  0,   0,   0,   0]
  Region SurfaceDamageRegion (this=a2fed044 count=1)
    [  0,   0,   0,   0]
      layerStack=   0, z=        0, pos=(0,0), size=(2560,2560), crop=[  0,   0,  -1,  -1], finalCrop=[  0,   0,  -1,  -1], isOpaque=0, invalidate=1, dataspace=Default, defaultPixelFormat=RGBx_8888, color=(0.000,0.000,0.000,1.000), flags=0x00000000, tr=[1.00, 0.00][0.00, 1.00]
      parent=mAboveAppWindowsContainers#0  // 所属父类
      zOrderRelativeOf=none
      activeBuffer=[   0x   0:   0,Unknown/None], queued-frames=0, mRefreshPending=0, windowType=-1, appId=-1

Displays信息(比如屏幕分辨率)

+ DisplayDevice: Built-in Screen
   type=0, hwcId=0, layerStack=0, (1280x 720), ANativeWindow=0xa52e7808 (8:8:8:8), orient= 0 (type=00000000), flips=280, isSecure=1, powerMode=2, activeConfig=0, numLayers=2
   v:[0,0,1280,720], f:[0,0,1280,720], s:[0,0,1280,720],transform:[[1.000,0.000,-0.000][0.000,1.000,-0.000][0.000,0.000,1.000]]
   wideColorGamut=0, hdr10=0, colorMode=ColorMode::NATIVE, dataspace: Default (0)
  FramebufferSurface: dataspace: Default(0)
   
default-size=[1280x720] default-format=1 transform-hint=00 frame-counter=280 // 屏幕分辨率信息

其他信息

EGL implementation : 1.4 Linux-r8p0-01rel0 // EGL 版本
GLES: ARM, Mali-450 MP, OpenGL ES 2.0 3d6a80e // OpenGL 架构信息
refresh-rate              : 60.000002 fps // 刷新率
x-dpi                     : 160.156998 // x dpi
y-dpi                     : 160.421005 // y dpi
VSYNC state: disabled // 垂直同步状态
soft-vsync: disabled // 当屏幕亮着的,就是disabled,如果关闭屏幕,这里为enabled

2、dumpsys activity

  • dumpsys activity o

    获取OOM等级信息,home进程、上一次的进程内容

    generic_x86:/ $ dumpsys activity o
      OOM levels:
        -900: SYSTEM_ADJ (   32,768K) 。。。
          
      mHomeProcess: ProcessRecorda3cea50 18515:com.android.launcher3/u0a19
      mPreviousProcess: ProcessRecord3758933 23311:com.android.settings/1000
    
  • dumpsys activity a

    从顶部到底部打印 TaskRecord(activity) 信息,包含如下内容

    * TaskRecord9e6567 #150 A=com.android.settings U=0 StackId=1 sz=2
      * Hist #1: ActivityRecorde5fb34f u0 com.android.settings/.Settings$MemorySettingsActivity t150
              packageName=com.android.settings processName=com.android.settings
              launchedFromUid=1000 launchedFromPackage=com.android.settings userId=0
              app=ProcessRecord3758933 23311:com.android.settings/1000
              Intent  flg=0x8000 cmp=com.android.settings/.Settings$MemorySettingsActivity (has extras) 
              frontOfTask=false task=TaskRecord9e6567 #150 A=com.android.settings U=0 StackId=1 sz=2
              taskAffinity=null
              realActivity=com.android.settings/.Settings$MemorySettingsActivity
              baseDir=/system/priv-app/Settings/Settings.apk
              dataDir=/data/user_de/0/com.android.settings
              state=RESUMED stopped=false delayedResume=false finishing=false
    
  • dumpsys activity r

    打印最近的TaskRecord信息,信息内容与a参数的类似

  • dumpsys activity b [PACKAGE_NAME]

    打印指定包创建的进程信息,包含已经注册的广播接收器action信息,创建的handler

    generic_x86:/ $ dumpsys activity b com.google.android.ext.services
    ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)
    
      mBroadcastsScheduled [foreground]=false
      mBroadcastsScheduled [background]=false
      mHandler:
        Handler (com.android.server.am.ActivityManagerService$MainHandler) 32cc7bf @ 26049725
          Looper (ActivityManager, tid 16) ba76e8c
            Message 0:  when=+8m0s963ms what=27 target=com.android.server.am.ActivityManagerService$MainHandler 
            Message 1:  when=+10m14s258ms callback=com.android.server.am.ActiveServices$1 target=com.android.server.am.ActivityManagerService$MainHandler 
            Message 2:  when=+23m38s921ms callback=com.android.server.AppOpsService$1 target=com.android.server.am.ActivityManagerService$MainHandler 
            (Total messages: 3, polling=true, quitting=false)
    
  • dumpsys activity p [PACKAGE_NAME]

    打印指定包创建的进程信息,包含:

    requiredAbi:要求的架构
    lastSwapPss:内存使用情况
    lastRequestedGc:上次GC请求

    generic_x86:/ $ dumpsys activity p com.google.android.ext.services
    ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
      requiredAbi=x86 instructionSet=null
      adjSeq=18970 lruSeq=0 lastPss=4.1MB lastSwapPss=0.00 lastCachedPss=0.00 lastCachedSwapPss=0.00
      lastRequestedGc=-4h9m54s33ms lastLowMemory=-4h9m54s33ms reportLowMemory=false .....
      
    
  • dumpsys activity s

    打印ServiceRecord信息,包含
    intent:intent信息
    packageName:包名
    IntentBindRecord:已绑定该服务的信息

    ServiceRecorda4d66c6 u0 com.android.chrome/org.chromium.chrome.browser.omaha.OmahaClient
        intent=act=org.chromium.chrome.browser.omaha.ACTION_REGISTER_REQUEST cmp=com.android.chrome/org.chromium.chrome.browser.omaha.OmahaClient
        packageName=com.android.chrome ....
    
  • dumpsys activity settings

    打印ServiceRecord信息,包含
    intent:intent信息
    packageName:包名
    IntentBindRecord:已绑定该服务的信息

    generic_x86:/ $ dumpsys activity settings
    TASK com.android.settings id=150
      ACTIVITY com.android.settings/.Settings$MemorySettingsActivity e5fb34f pid=23311
        Local Activity ebdaec State:
          mResumed=true mStopped=false mFinished=false .....
    
  • dumpsys activity all

    打印全部的activity,包含
    生命周期状态
    View Hierarchy: view的层次结构

    generic_x86:/ $ dumpsys activity all
    TASK com.example.flutter_web id=149  ...
      
        View Hierarchy:
          DecorView@6f37f9c[MainActivity]
            android.widget.LinearLayout5370da5 V.E...... .......D 0,0-1080,1794
              android.view.ViewStub137457a G.E...... ......I. 0,0-0,0 #10203e8 android:id/action_mode_bar_stub
              android.widget.FrameLayout20ff12b V.E...... .......D 0,0-1080,1794 #1020002 android:id/content ....
    
  • dumpsys activity top

    与all参数类似,但是只打印顶层activity的信息

  • dumpsys activity starter

    打印对应的启动者

  • dumpsys activity lastanr

    打印 ANR list信息

3、 dumpsys cpuinfo

查看CPU使用情况

CPU usage from 1251999ms to 351197ms ago (2020-02-23 17:21:02.541 to 2020-02-23 17:36:03.343):
  4.2% 20215/com.android.chrome:sandboxed_process0: 1.1% user + 3% kernel / faults: 396490 minor 1 major
   .....
6.6% TOTAL: 1.2% user + 4.9% kernel + 0% iowait + 0% irq + 0.3% softirq

4、dumpsys diskstats

查看磁盘使用情况

Latency: 1ms [512B Data Write]
Data-Free: 1195820K / 2031440K total = 58% free
Cache-Free: 61000K / 62416K total = 97% free
System-Free: 250356K / 2031440K total = 12% free

5、dumpsys display

屏幕物理信息

mDefaultViewport=DisplayViewportvalid=true, displayId=0, orientation=0, logicalFrame=Rect(0, 0 - 1080, 1920), physicalFrame=Rect(0, 0 - 1080, 1920), deviceWidth=1080, deviceHeight=1920
  mExternalTouchViewport=DisplayViewportvalid=false, displayId=0, orientation=0, logicalFrame=Rect(0, 0 - 0, 0), physicalFrame=Rect(0, 0 - 0, 0), deviceWidth=0, deviceHeight=0


mDisplayInfos=
   PhysicalDisplayInfo1920 x 1080, 60.000004 fps, density 1.5, 159.895 x 160.421 dpi, secure true, appVsyncOffset 1000000, bufferDeadline 16666666

6、dumpsys ethernet

查看IP,网关(ifconfig也能查看)

onNewDhcpResults(IP address 172.19.110.23/24 Gateway 172.19.110.1  DNS servers: [ 10.254.254.254 ] Domains gz.cvte.cn DHCP server /10.22.4.10 Vendor info null lease 7200 seconds)

7、dumpsys meminfo

查看系统各个应用内存使用情况

Total PSS by process:
     36,511K: system (pid 1929)
     3,903K: android.ext.services (pid 2881)
     .....
Total PSS by OOM adjustment:
     76,848K: Native
          4,411K: zygote (pid 1676)
          .....
Total PSS by category:
     78,104K: Native
     22,149K: Dalvik
    	......

Total RAM:   991,316K (status critical)
 Free RAM:   412,181K (   10,761K cached pss +   144,448K cached kernel +   256,972K free)
 Used RAM:   433,189K (  326,881K used pss +   106,308K kernel)
 Lost RAM:   193,772K
     ZRAM:    16,628K physical used for    74,012K in swap (  317,216K total swap)
   Tuning: 128 (large 256), oom   184,320K, restore limit    61,440K (low-ram)

8、dumpsys overlay

查看overlay的包状态

com.android.systemui.theme.dark:0 
    mPackageName.......: com.android.systemui.theme.dark  //overlay 的apk 包名
    mUserId............: 0
    mTargetPackageName.: com.android.systemui // 目标包名
    mBaseCodePath......: /vendor/overlay/SysuiDarkTheme/SysuiDarkThemeOverlay.apk // overlay的apk路径
    mState.............: STATE_DISABLED
    mIsEnabled.........: false 
    mIsStatic..........: false 
    mPriority..........: 1
    mCategory..........: null
  

9、dumpsys package

  • dumpsys package l

    列举已知的lib库

    Libraries:
      android.test.base ->  (jar) /system/framework/android.test.base.jar ....
    
  • dumpsys package f

    列举设备支持的功能

    Features:
      android.software.leanback_only ......
    
  • dumpsys package r

    列举 所有的 [activity|service|receiver|content ] intent 解析器,其中包含各个应用的入口,action对应的组件

    Activity Resolver Table: // activity 入口
      Non-Data Actions: 
           android.settings.HOME_SETTINGS:  // action 
              c25027 com.android.tv.settings/.EmptyStubActivity  // 响应该action的组件
         ....
    MIME Typed Actions:
          android.intent.action.INSTALL_PACKAGE:
            7215b10 com.android.packageinstaller/.InstallStart
           .....
    Receiver Resolver Table:  // 广播接收器
    Non-Data Actions:
          android.intent.action.LOCALE_CHANGED:
    			        1a15a84 com.android.providers.media/.MediaScannerReceiver
    
  • dumpsys package permission [permissionName …]

    列举所有申明该权限的应用信息,其中可以查看应用的版本信息,标签,使用的lib库和jar路径,首次安装时间,更新时间,签名信息,已经获取的权限,安装需要的权限以及overlay文件的路径

    xxxx:/ $ dumpsys package permission android.permission.VIBRATE
    Packages:
      pkg=Packagea077660 com.ecloud.eshare.server
      codePath=/system/priv-app/eshare-service
      versionCode=20190820 minSdk=8 targetSdk=8
      versionName=v5Android调试常用命令

    Android调试常用命令

    软件测试 | 手把手教你如何使用 ABD调试工具,学不会算我的!

    Android adb,adb命令

    Android 进阶——Framework 核心之dumpsys命令浅析

    Android 进阶——Framework 核心之dumpsys命令浅析