Android dump的使用1

android源码中很多service提供了dump函数,并会输出当前的状态。如何使用dump函数就是这篇文档要做的事儿

首先,进入adb shell
第二,执行dumpsys –help
这样就能了解dumpsys命令的基本用法

255|generic_x86_64:/ # dumpsys --help
usage: dumpsys
         To dump all services.
or:
       dumpsys [-t TIMEOUT] [--help | -l | --skip SERVICES | SERVICE [ARGS]]
         --help: shows this help
         -l: only list services, do not dump them
         -t TIMEOUT: TIMEOUT to use in seconds instead of default 10 seconds
         --skip SERVICES: dumps all services but SERVICES (comma-separated list)
         SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it

第三,dumpsys -l 查看系统中支持dump的模块

generic_x86_64:/ # dumpsys -l
Currently running services:
  DockObserver
  SurfaceFlinger
  accessibility
  account
  activity
  alarm
  android.hardware.fingerprint.IFingerprintDaemon
  android.security.keystore
  android.service.gatekeeper.IGateKeeperService
  appops
  appwidget
  assetatlas
  audio
  backup
  battery
  batteryproperties
  batterystats
  carrier_config
  clipboard
  com.android.car.vehiclenetwork.IVehicleNetwork
  commontime_management
  connectivity
  connectivity_metrics_logger
  consumer_ir
  content
  contexthub_service
  country_detector
  cpuinfo
  dbinfo
  device_policy
  deviceidle
  devicestoragemonitor
  diskstats
  display
  dns_listener
  dreams
  drm.drmManager
  dropbox
  ethernet
  gfxinfo
  gpu
  graphicsstats
  hardware_properties
  imms
  input
  input_method
  iphonesubinfo
  isms
  isub
  jobscheduler
  launcherapps
  location
  lock_settings
  media.audio_flinger
  media.audio_policy
  media.camera
  media.camera.proxy
  media.codec
  media.drm
  media.extractor
  media.player
  media.radio
  media.resource_manager
  media.sound_trigger_hw
  media_projection
  media_router
  media_session
  meminfo
  mount
  netd
  netpolicy
  netstats
  network_management
  network_score
  network_time_update_service
  notification
  otadexopt
  package
  permission
  phone
  pinner
  power
  print
  processinfo
  procstats
  recovery
  restrictions
  rttmanager
  samplingprofiler
  scheduling_policy
  search
  sensorservice
  serial
  servicediscovery
  shortcut
  simphonebook
  soundtrigger
  statusbar
  telecom
  telephony.registry
  textservices
  trust
  uimode
  updatelock
  usagestats
  usb
  user
  vibrator
  voiceinteraction
  vrmanager
  wallpaper
  webviewupdate
  wifi
  wifip2p
  wifiscanner
  window

第四,以WindowManagerService为例
dumpsys window会列出所有WindowManagerService的dump函数提供的log

generic_x86_64:/ # dumpsys window

WINDOW MANAGER LAST ANR (dumpsys window lastanr)
  <no ANR has occurred since boot>

WINDOW MANAGER POLICY STATE (dumpsys window policy)
    mSafeMode=false mSystemReady=true mSystemBooted=true
    mLidState=-1 mLidOpenRotation=-1 mCameraLensCoverState=-1 mHdmiPlugged=false
    mLastSystemUiFlags=0x80000708 mResettingSystemUiFlags=0x0 mForceClearedSystemUiFlags=0x0
    mWakeGestureEnabledSetting=true
    mSupportAutoRotation=true
    mUiMode=3 mDockMode=0 mEnableCarDockHomeCapture=false mCarDockRotation=-1 mDeskDockRotation=-1
    mUserRotationMode=0 mUserRotation=0 mAllowAllRotations=1
    mCurrentAppOrientation=-1
    mCarDockEnablesAccelerometer=true mDeskDockEnablesAccelerometer=true
    mLidKeyboardAccessibility=0 mLidNavigationAccessibility=0 mLidControlsScreenLock=false
 mLidControlsSleep=false
     mLongPressOnBackBehavior=0
    mShortPressOnPowerBehavior=1 mLongPressOnPowerBehavior=1
    mDoublePressOnPowerBehavior=0 mTriplePressOnPowerBehavior=0
    mHasSoftInput=true
    mAwake=true
    mScreenOnEarly=true mScreenOnFully=true
    mKeyguardDrawComplete=true mWindowManagerDrawComplete=true
    mOrientationSensorEnabled=true
    mOverscanScreen=(0,0) 1280x720
    mRestrictedOverscanScreen=(0,0) 1280x624
    mUnrestrictedScreen=(0,0) 1280x720
    mRestrictedScreen=(0,0) 1280x624
    mStableFullscreen=(0,0)-(1280,624)
    mStable=(0,96)-(1280,624)
    mSystem=(0,0)-(1280,720)
    mCur=(0,96)-(1280,624)
    mContent=(0,96)-(1280,624)
    mVoiceContent=(0,96)-(1280,624)
    mDock=(0,96)-(1280,624)
    mDockLayer=268435456 mStatusBarLayer=161000
    mShowingLockscreen=false mShowingDream=false mDreamingLockscreen=false mDreamingSleepToken=null
    mStatusBar=Window{2e5a79 u0 StatusBar} isStatusBarKeyguard=false
    mNavigationBar=Window{b1d5017 u0 CarNavigationBar}
    mFocusedWindow=Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}
    mFocusedApp=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}
    mTopFullscreenOpaqueWindowState=Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}
    mTopFullscreenOpaqueOrDimmingWindowState=Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}
    mTopIsFullscreen=false mHideLockScreen=false
    mForceStatusBar=false mForceStatusBarFromKeyguard=false
    mDismissKeyguard=0 mWinDismissingKeyguard=null mHomePressed=false
    mAllowLockscreenWhenOn=false mLockScreenTimeout=60000 mLockScreenTimerActive=false
    mEndcallBehavior=2 mIncallPowerBehavior=1 mLongPressOnHomeBehavior=0
    mLandscapeRotation=0 mSeascapeRotation=2
    mPortraitRotation=0 mUpsideDownRotation=1
    mDemoHdmiRotation=0 mDemoHdmiRotationLock=false
    mUndockedHdmiRotation=-1
    mKeyMapping.size=0
    BarController.StatusBar
      mState=WINDOW_STATE_SHOWING
      mTransientBar=TRANSIENT_BAR_NONE
    BarController.NavigationBar
      mState=WINDOW_STATE_SHOWING
      mTransientBar=TRANSIENT_BAR_NONE
    PolicyControl.sImmersiveStatusFilter=null
    PolicyControl.sImmersiveNavigationFilter=null
    PolicyControl.sImmersivePreconfirmationsFilter=null
    WakeGestureListener
      mTriggerRequested=false
      mSensor=null
    WindowOrientationListener
      mEnabled=true
      mCurrentRotation=0
      mSensorType=null
      mSensor={Sensor name="Goldfish 3-axis Accelerometer", vendor="The Android Open Source Project", version=1, type=1, maxRange=2.8, resolution=2.480159E-4, power=3.0, minDelay=0}
      mRate=2
      AccelSensorJudge
        mProposedRotation=0
        mPredictedRotation=0
        mLastFilteredX=0.0
        mLastFilteredY=9.8
        mLastFilteredZ=0.0
        mLastFilteredTimestampNanos=4266969915566 (10.301224ms ago)
        mTiltHistory={last: 0.0}
        mFlat=false
        mSwinging=false
        mAccelerating=false
        mOverhead=false
        mTouched=false
        mTiltToleranceConfig=[[-25, 70], [-25, 65], [-25, 60], [-25, 65]]
    KeyguardServiceDelegate
      showing=false
      showingAndNotOccluded=true
      inputRestricted=false
      occluded=false
      secure=false
      dreaming=false
      systemIsReady=true
      deviceHasKeyguard=true
      enabled=false
      offReason=0
      currentUser=-10000
      bootCompleted=true
      screenState=2
      interactiveState=1
      KeyguardStateMonitor
        mIsShowing=false
        mSimSecure=false
        mInputRestricted=false
        mTrusted=false
        mCurrentUserId=0

WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)
    DisplayContentsAnimator #0:
      Window #0: WindowStateAnimator{97f8f89 com.android.systemui.ImageWallpaper}
      Window #1: WindowStateAnimator{6020b8e com.android.launcher/com.android.launcher2.Launcher}
      Window #2: WindowStateAnimator{c385faf DockedStackDivider}
      Window #3: WindowStateAnimator{1823fbc KeyguardScrim}
      Window #4: WindowStateAnimator{b489b45 StatusBar}
      Window #5: WindowStateAnimator{997529a CarNavigationBar}


    mBulkUpdateParams=0x8 ORIENTATION_CHANGE_COMPLETE

WINDOW MANAGER SESSIONS (dumpsys window sessions)
  Session Session{6d01ba 1962:u0a10016}:
    mNumWindow=1 mClientDead=false mSurfaceSession=android.view.SurfaceSession@db547cb
  Session Session{2f5d9cc 1625:u0a10026}:
    mNumWindow=4 mClientDead=false mSurfaceSession=android.view.SurfaceSession@4119ba8
  Session Session{4fbbeed 1778:1000}:
    mNumWindow=0 mClientDead=false mSurfaceSession=android.view.SurfaceSession@4dca6c1
  Session Session{b57d878 1413:1000}:
    mNumWindow=1 mClientDead=false mSurfaceSession=android.view.SurfaceSession@707fe66


WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
  Display: mDisplayId=0
    init=1280x720 160dpi cur=1280x720 app=1280x624 rng=720x528-1280x1184
    deferred=false layoutNeeded=false

  Application tokens in top down Z order:
    mStackId=0
    mDeferDetach=false
    mFullscreen=true
    mBounds=[0,0][1280,720]
      taskId=30
        mFullscreen=true
        mBounds=[0,0][1280,720]
        mdr=false
        appTokens=[AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}]
        mTempInsetBounds=[0,0][0,0]
          Activity #0 AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}
          windows=[Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}]
          windowType=2 hidden=false hasVisible=true
          app=true voiceInteraction=false
          allAppWindows=[Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}]
          task={taskId=30 appTokens=[AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}] mdr=false}
           appFullscreen=true requestedOrientation=-1
          hiddenRequested=false clientHidden=false reportedDrawn=true reportedVisible=true
          numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
          startingData=null removed=false firstWindowDrawn=true mIsExiting=false


    DimLayerController
      Task=30
        dimLayer=shared, animator=null, continueDimming=false
        mDimSurface=null mLayer=-1 mAlpha=0.0
        mLastBounds=[0,0][0,0] mBounds=[-320,-180][1600,900]
        Last animation:  mDuration=0 mStartTime=0 curTime=4266980
         mStartAlpha=0.0 mTargetAlpha=0.0
      Stack=0
        dimLayer=shared, animator=null, continueDimming=false
        mDimSurface=null mLayer=-1 mAlpha=0.0
        mLastBounds=[0,0][0,0] mBounds=[-320,-180][1600,900]
        Last animation:  mDuration=0 mStartTime=0 curTime=4266980
         mStartAlpha=0.0 mTargetAlpha=0.0

    DockedStackDividerController
      mLastVisibility=false
      mMinimizedDock=false
      mAdjustedForIme=false
      mAdjustedForDivider=false

WINDOW MANAGER TOKENS (dumpsys window tokens)
  All tokens:
  WindowToken{6ce95a7 android.os.Binder@dc9aa89}
  WindowToken{db8ca54 android.os.Binder@e93907f}
  WindowToken{64bedfd null}
  AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}

  Wallpaper tokens:
  Wallpaper #0 WindowToken{6ce95a7 android.os.Binder@dc9aa89}

WINDOW MANAGER WINDOWS (dumpsys window windows)
  Window #5 Window{b1d5017 u0 CarNavigationBar}:
    mDisplayId=0 stackId=0 mSession=Session{2f5d9cc 1625:u0a10026} mClient=android.os.BinderProxy@a2c5c96
    mOwnerUid=10026 mShowToOwnerOnly=false package=com.android.systemui appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=2019 fl=#1840068 fmt=-3}
    Requested w=1280 h=528 mLayoutSeq=95
    mHasSurface=true mShownPosition=[0,624] isReadyForDisplay()=true hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{997529a CarNavigationBar}:
      Surface: shown=true layer=211000 alpha=1.0 rect=(0.0,624.0) 1280.0 x 96.0
    mLastFreezeDuration=+165ms
  Window #4 Window{2e5a79 u0 StatusBar}:
    mDisplayId=0 stackId=0 mSession=Session{2f5d9cc 1625:u0a10026} mClient=android.os.BinderProxy@b3f6b40
    mOwnerUid=10026 mShowToOwnerOnly=false package=com.android.systemui appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(fillx96) gr=#30 sim=#10 ty=2000 fl=#81840048 fmt=-3 vsysui=0x600}
    Requested w=1280 h=96 mLayoutSeq=95
    mHasSurface=true mShownPosition=[0,0] isReadyForDisplay()=true hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{b489b45 StatusBar}:
      Surface: shown=true layer=161000 alpha=1.0 rect=(0.0,0.0) 1280.0 x 96.0
    mLastFreezeDuration=+165ms
  Window #3 Window{9c9d9a7 u0 KeyguardScrim}:
    mDisplayId=0 stackId=0 mSession=Session{b57d878 1413:1000} mClient=android.view.ViewRootImpl$W@96cbe54
    mOwnerUid=1000 mShowToOwnerOnly=false package=android appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(fillxfill) sim=#10 ty=2029 fl=#1110900 pfl=0x1 fmt=-3 or=5 vsysui=0x3610000}
    Requested w=1280 h=624 mLayoutSeq=49
    mHasSurface=false mShownPosition=[0,0] isReadyForDisplay()=false hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{1823fbc KeyguardScrim}:
  Window #2 Window{5a3f626 u0 DockedStackDivider}:
    mDisplayId=0 stackId=0 mSession=Session{2f5d9cc 1625:u0a10026} mClient=android.os.BinderProxy@e92a581
    mOwnerUid=10026 mShowToOwnerOnly=false package=com.android.systemui appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(48xfill) sim=#20 ty=2034 fl=#21840028 pfl=0x40 fmt=-3 vsysui=0x700}
    Requested w=48 h=528 mLayoutSeq=95
    mPolicyVisibility=false mPolicyVisibilityAfterAnim=false mAppOpVisibility=true mAttachedHidden=false
    mHasSurface=false mShownPosition=[0,0] isReadyForDisplay()=false hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{c385faf DockedStackDivider}:
      mShownAlpha=0.0 mAlpha=1.0 mLastAlpha=0.0
  Window #1 Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}:
    mDisplayId=0 stackId=0 mSession=Session{6d01ba 1962:u0a10016} mClient=android.os.BinderProxy@f4fafc8
    mOwnerUid=10016 mShowToOwnerOnly=true package=com.android.launcher appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(fillxfill) sim=#20 ty=1 fl=#d910100 pfl=0x20000 fmt=-2 wanim=0x10303ea vsysui=0x700 needsMenuKey=2}
    Requested w=1280 h=528 mLayoutSeq=95
    mHasSurface=true mShownPosition=[0,0] isReadyForDisplay()=true hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{6020b8e com.android.launcher/com.android.launcher2.Launcher}:
      Surface: shown=true layer=21005 alpha=1.0 rect=(0.0,0.0) 1280.0 x 720.0
    mWallpaperX=0.0 mWallpaperY=0.5
    mWallpaperXStep=0.0 mWallpaperYStep=0.0
  Window #0 Window{cc4fae7 u0 com.android.systemui.ImageWallpaper}:
    mDisplayId=0 stackId=0 mSession=Session{2f5d9cc 1625:u0a10026} mClient=android.os.BinderProxy@b6fb0a6
    mOwnerUid=10026 mShowToOwnerOnly=true package=com.android.systemui appop=NONE
    mAttrs=WM.LayoutParams{(0,0)(1280x720) gr=#800033 ty=2013 fl=#10318 fmt=2 wanim=0x10302f2}
    Requested w=1280 h=720 mLayoutSeq=95
    mIsImWindow=false mIsWallpaper=true mIsFloatingLayer=true mWallpaperVisible=true
    mHasSurface=true mShownPosition=[0,0] isReadyForDisplay()=true hasSavedSurface()=false mWindowRemovalAllowed=false
    WindowStateAnimator{97f8f89 com.android.systemui.ImageWallpaper}:
      Surface: shown=true layer=21000 alpha=1.0 rect=(0.0,0.0) 1280.0 x 720.0
    mLastFreezeDuration=+166ms
    mWallpaperX=0.0 mWallpaperY=0.5
    mWallpaperXStep=0.0 mWallpaperYStep=0.0

  mCurConfiguration={1.0 310mcc260mnc [en_US] ldltr sw720dp w1280dp h528dp 160dpi lrg land car night finger -keyb/v/h tball/v s.9}
  mHasPermanentDpad=false
  mCurrentFocus=Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}
  mFocusedApp=AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}
  mInTouchMode=true mLayoutSeq=95
  mLastDisplayFreezeDuration=+171ms due to Window{b1d5017 u0 CarNavigationBar}
  mLastWakeLockHoldingWindow=null mLastWakeLockObscuringWindow=null

从上面的log结果可以看到dump分几个部分
WINDOW MANAGER LAST ANR (dumpsys window lastanr)
WINDOW MANAGER POLICY STATE (dumpsys window policy)
WINDOW MANAGER ANIMATOR STATE (dumpsys window animator)
WINDOW MANAGER SESSIONS (dumpsys window sessions)
WINDOW MANAGER DISPLAY CONTENTS (dumpsys window displays)
WINDOW MANAGER TOKENS (dumpsys window tokens)
WINDOW MANAGER WINDOWS (dumpsys window windows)

如果想查看其中的某一部分,可以执行()中的命令
以window tokens为例:
执行dumpsys window tokens

generic_x86_64:/ # dumpsys window tokens
WINDOW MANAGER TOKENS (dumpsys window tokens)
  All tokens:
  WindowToken{6ce95a7 android.os.Binder@dc9aa89}:
    windows=[Window{cc4fae7 u0 com.android.systemui.ImageWallpaper}]
    windowType=2013 hidden=false hasVisible=true
  WindowToken{db8ca54 android.os.Binder@e93907f}:
    windows=[]
    windowType=2011 hidden=false hasVisible=false
  WindowToken{64bedfd null}:
    windows=[Window{5a3f626 u0 DockedStackDivider}, Window{b1d5017 u0 CarNavigationBar}, Window{2e5a79 u0 StatusBar}, Window{9c9d9a7 u0 KeyguardScrim}]
    windowType=-1 hidden=false hasVisible=true
  AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}:
    windows=[Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}]
    windowType=2 hidden=false hasVisible=true
    app=true voiceInteraction=false
    allAppWindows=[Window{92cf861 u0 com.android.launcher/com.android.launcher2.Launcher}]
    task={taskId=30 appTokens=[AppWindowToken{c35846f token=Token{e777649 ActivityRecord{3ef5450 u0 com.android.launcher/com.android.launcher2.Launcher t30}}}] mdr=false}
     appFullscreen=true requestedOrientation=-1
    hiddenRequested=false clientHidden=false reportedDrawn=true reportedVisible=true
    numInterestingWindows=1 numDrawnWindows=1 inPendingTransaction=false allDrawn=true (animator=true)
    startingData=null removed=false firstWindowDrawn=true mIsExiting=false

  Wallpaper tokens:
  Wallpaper #0 WindowToken{6ce95a7 android.os.Binder@dc9aa89}:
    windows=[Window{cc4fae7 u0 com.android.systemui.ImageWallpaper}]
    windowType=2013 hidden=false hasVisible=true

其他的模块也可以用类似的方法,针对自己感兴趣的部分进行dump,查看当前系统模块的状态

那么如果对于的模块或者类的dump函数没有出现在dumpsys -l的列表中怎么办呢?
这个请参考下面的文章
Android dump的使用2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值