天天看點

adb shell dumpsys指令集合

  • 指令集合

    adb shell dumpsys

    指令是用于列印出目前系統資訊(更切确的說是dumpsys指令,因為adb shell隻是為了進入手機或模拟器的shell核心,使其能夠執行dumpsys指令),可以在指令後面加指定的service name(比如activity,location),如果不加則預設列印出裝置中所有service的資訊.

    下面列舉使用最多的指令:

    # 列出最近使用過的任務棧,按時間從近到遠排序:
    adb shell dumpsys activity
    # 檢視Activity的相關資訊
    adb shell dumpsys activity [包名]
    # 檢視最上層的activity的View布局
    adb shell dumpsys activity top
    # 檢視battery相關資訊
    adb shell dumpsys batterystats [包名]
    # 檢視Location相關資訊:最近請求過定位的app和最近請求定位的位址
    adb shell dumpsys location
    # 導出GPU 呈現模式分析結果,最近大約100幀的渲染情況,直接在控制台列印
    adb shell dumpsys gfxinfo 
    # 導出GPU 呈現模式分析結果,最近大約100幀的渲染情況,輸出到檔案
    adb shell dumpsys gfxinfo > test.txt
    
               

    adb shell dumpsys activity

    列出最近使用過的任務棧,按時間從近到遠排序:
    • intent清單
    • 廣播清單
    • 内容提供者清單
    • 權限請求清單
    • 服務清單
    • 任務清單(activity活動棧清單),同一個項目可能有多個activity_stack,也就是task
    • activity清單
    • 程序清單
    # 廣播清單
    ACTIVITY MANAGER BROADCAST STATE (dumpsys activity broadcasts)
      Historical broadcasts [foreground]:
      #0: BroadcastRecord{70d1854 u-1 android.intent.action.TIME_TICK}
        act=android.intent.action.TIME_TICK flg=0x50000114 (has extras)
        extras: Bundle[{android.intent.extra.ALARM_COUNT=1}]
    # provider清單
    ACTIVITY MANAGER CONTENT PROVIDERS (dumpsys activity providers)
      Published single-user content providers (by class):
      * ContentProviderRecord{9d7ed52 u0 com.android.providers.telephony/.HbpcdLookupProvider}
        proc=ProcessRecord{8b15373 1929:com.android.phone/1001}
        singleton=true
        authority=hbpcd_lookup
    # 權限請求清單
    ACTIVITY MANAGER URI PERMISSIONS (dumpsys activity permissions)
      Granted Uri Permissions:
      * UID 10005 holds:
    
    # 服務清單
    ACTIVITY MANAGER SERVICES (dumpsys activity services)
      User 0 active services:
      * ServiceRecord{4592bf8 u0 com.android.bluetooth/.hid.HidService isClone=0}
        app=ProcessRecord{cb56c55 22083:com.android.bluetooth/1002}
        created=-5h24m37s317ms started=true connections=1
        Connections:
          act=android.bluetooth.IBluetoothInputDevice -> 3881:com.android.systemui/u0a5
    
    # 活動棧清單
    ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)
      Recent tasks:
      * Recent #0: TaskRecord{42b1e3c #11525 A=com.alibaba.weex U=0 sz=1 isClone=0 encrypt=false}
    
    # 活動清單
    ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
    Display #0 (activities from top to bottom):
      Stack #1:
        Task id #11525
          TaskRecord{42b1e3c #11525 A=com.alibaba.weex U=0 sz=1 isClone=0 encrypt=false}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.alibaba.weex/.SplashActivity }
            Hist #0: ActivityRecord{8e4291a u0 com.alibaba.weex/.IndexActivity t11525}
              Intent { cmp=com.alibaba.weex/.IndexActivity }
              ProcessRecord{e455c23 11710:com.alibaba.weex/u0a678}
        Task id #11523
          TaskRecord{7fa57c5 #11523 A=com.weex.app.uat U=0 sz=1 isClone=0 encrypt=false}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.weex.app.uat/com.vanke.weexframe.main.MainActivity }
            Hist #0: ActivityRecord{69b60a8 u0 com.weex.app.uat/com.vanke.weexframe.main.MainActivity t11523}
              Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.weex.app.uat/com.vanke.weexframe.main.MainActivity bnds=[24,664][282,954] }
              ProcessRecord{6f5780e 11919:com.weex.app.uat/u0a683}
    #程序清單      
    ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes)
      Isolated process list (sorted by uid):
        Isolated # 0: ProcessRecord{a627aff 0:WebViewLoader-arm64-v8a/1037}  
               

    adb shell dumpsys activity top

    列出目前activity的視圖層次
    nzedeiMac:~ pactera$ adb shell dumpsys activity top
    TASK com.alibaba.weex id=11573
      ACTIVITY com.alibaba.weex/.IndexActivity b17a4b0 pid=27933
        Local Activity 1fade28 State:
          mResumed=true mStopped=false mFinished=false
          mChangingConfigurations=false
          mCurrentConfig={1.0 default 460mcc65535mnc zh_CN ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h s.170}
          mLoadersStarted=true
          FragmentManager misc state:
            mHost=android.app.Activity[email protected]
            mContainer=android.app.Activity[email protected]
            mCurState=5 mStateSaved=false mDestroyed=false
        ViewRoot:
          mAdded=true mRemoved=false
          mConsumeBatchedInputScheduled=false
          mConsumeBatchedInputImmediatelyScheduled=false
          mPendingInputEventCount=0
          mProcessInputEventsScheduled=false
          mTraversalScheduled=false
          android.view.ViewRootImpl$NativePreImeInputStage: mQueueLength=0
          android.view.ViewRootImpl$ImeInputStage: mQueueLength=0
          android.view.ViewRootImpl$NativePostImeInputStage: mQueueLength=0
        Choreographer:
          mFrameScheduled=true
          mLastFrameTime=754930059 (3 ms ago)
        View Hierarchy:
          com.android.internal.policy.PhoneWindow$DecorView{c53ce1b V.E...... R....... 0,0-1080,1920}
            android.widget.LinearLayout{21d69cf V.E...... ........ 0,0-1080,1920}
              android.view.ViewStub{923881 G.E...... ......I. 0,0-0,0 #10203a9 android:id/action_mode_bar_stub}
              android.widget.FrameLayout{1dd4f5c V.E...... ........ 0,0-1080,1920}
                android.support.v7.widget.FitWindowsLinearLayout{6910265 V.E...... ........ 0,0-1080,1920 #7f100084 app:id/action_bar_root}
                  android.support.v7.widget.ViewStubCompat{3f8d26 G.E...... ......I. 0,0-0,0 #7f100085 app:id/action_mode_bar_stub}
                  android.support.v7.widget.ContentFrameLayout{996fb3a V.E...... ........ 0,0-1080,1920 #1020002 android:id/content}
                    android.support.design.widget.CoordinatorLayout{eb0d3eb V.ED..... ........ 0,0-1080,1920}
                      android.support.design.widget.AppBarLayout{4fa6030 V.E...... ......ID 0,72-1080,72}
                        android.support.v7.widget.Toolbar{49e0548 G.E...... ......ID 0,0-1080,168 #7f100098 app:id/toolbar}
                          android.support.v7.widget.AppCompatTextView{a945fe1 V.ED..... ......I. 48,43-207,124}
                          android.support.v7.widget.ActionMenuView{b3bbade V.E...... ......ID 912,0-1080,168}
                            android.support.v7.view.menu.ActionMenuItemView{11264bf VFED..CL. ......ID 0,12-168,156 #7f1014be app:id/action_scan}
                      android.widget.RelativeLayout{d09c4a9 V.E...... ........ 0,72-1080,1920}
                        android.widget.FrameLayout{f699106 V.E...... ........ 0,0-1080,1848 #7f1000b5 app:id/index_container}
                          com.taobao.weex.RenderContainer{e7a69fd V.E...... ........ 0,0-1080,1848}
                            com.taobao.weex.ui.view.WXFrameLayout{d1866f2 V.E...... ........ 0,0-1080,1848 #1}
                              com.taobao.weex.ui.view.WXFrameLayout{8617e31 V.E...... ........ 0,0-1080,1267 #2}
                                com.taobao.weex.ui.view.WXFrameLayout{6c45297 V.E...... ........ 0,0-1080,1267 #3}
                                  com.taobao.weex.ui.view.WXImageView{d8cf4ee V.ED..... ........ 0,217-1080,674 #4}
                                  com.taobao.weex.ui.view.WXFrameLayout{bd771fa V.E...C.. ........ 216,747-864,977 #5}
                                    com.taobao.weex.ui.view.WXImageView{dfe3a08 V.ED..... ........ 0,0-648,230 #6}
                                    com.taobao.weex.ui.view.WXTextView{f40eeb4 V.ED..... ........ 94,61-554,168 #7}
                              com.taobao.weex.ui.view.WXFrameLayout{584220 V.E...... ........ 0,1267-1080,1847 #8}
                                com.taobao.weex.ui.view.WXFrameLayout{816759e V.E...... ........ 0,0-1080,290 #9}
                                  com.taobao.weex.ui.view.WXFrameLayout{9f04daa V.E...C.. ........ 0,1-540,289 #a}
                                    com.taobao.weex.ui.view.WXTextView{3dd9a76 V.ED..... ........ 0,96-538,191 #b}
                                  com.taobao.weex.ui.view.WXFrameLayout{2f5e911 V.E...C.. ........ 540,1-1080,289 #c}
                                    com.taobao.weex.ui.view.WXTextView{11747c V.ED..... ........ 0,96-540,191 #d}
                                com.taobao.weex.ui.view.WXFrameLayout{bbf054d V.E...... ........ 0,290-1080,580 #e}
                                  com.taobao.weex.ui.view.WXFrameLayout{31f9513 V.E...C.. ........ 0,1-540,289 #f}
                                    com.taobao.weex.ui.view.WXTextView{cd49105 V.ED..... ........ 0,96-538,191 #10}
                                  com.taobao.weex.ui.view.WXFrameLayout{819824e V.E...C.. ........ 540,1-1080,289 #11}
                                    com.taobao.weex.ui.view.WXTextView{98f755a V.ED..... ........ 0,96-540,191 #12}
                        android.widget.ProgressBar{ac6c3c7 G.ED..... ......ID 468,852-612,996 #7f1000b6 app:id/index_progressBar}
                        android.support.v7.widget.AppCompatTextView{9322df4 G.ED..... ......ID 449,1026-631,1083 #7f1000b7 app:id/index_tip}
        Looper (main, tid 1) {974dd67}
          Message 0: { when=+5s795ms what=132 target=android.app.ActivityThread$H }
          (Total messages: 1, polling=false, quitting=false)
        Local FragmentActivity 1fade28 State:
          mCreated=truemResumed=true mStopped=false mReallyStopped=false
          mLoadersStarted=true
        FragmentManager misc state:
          mHost=android.support.v4.app.FragmentActivity[email protected]
          mContainer=android.support.v4.app.FragmentActivity[email protected]
          mCurState=5 mStateSaved=false mDestroyed=false
               

adb shell dumpsys gfxinfo

導出GPU 呈現模式分析結果,最近大約100幀的渲染情況

// 輸出結果
com.zhy.sample_okhttp/com.zhy.sample_okhttp.MainActivity/[email protected] (visibility=0)
	Draw	Prepare	Process	Execute
	50.00	0.69	22.25	12.80
	50.00	0.51	2.36	8.44
	2.84	0.29	4.39	15.26
	
Stats since: 3115548352260ns
Total frames rendered: 92
Janky frames: 11 (11.96%)
90th percentile: 21ms
95th percentile: 61ms
99th percentile: 129ms
Number Missed Vsync: 3
Number High input latency: 0
Number Slow UI thread: 7
Number Slow bitmap uploads: 0
Number Slow issue draw commands: 8

View hierarchy:
  com.zhy.sample_okhttp/com.zhy.sample_okhttp.MainActivity/android.view.ViewRootIm[email protected]
  29 views, 42.37 kB of display lists


Total ViewRootImpl: 1
Total Views:        29
Total DisplayList:  42.37 kB
           

這裡将逐一解釋以上重點資訊:

  • Draw:測量繪制Display List的時間,也就是measure和layout的時間。
  • Prepare:标示準備時間
  • Process:OpenGL渲染Display的時間
  • Execute:CPU等待GPU處理的時間,主線程被其他任務占用的時間,比如:處理業務邏輯之類的
  • Graphics info for pid 31148 [com.android.settings]: 表明目前dump的為設定界面的幀資訊,pid為31148
  • Total frames rendered: 105 本次dump搜集了105幀的資訊
  • Janky frames: 2 (1.90%) 105幀中有2幀的耗時超過了16ms,卡頓機率為1.9%
  • Number Missed Vsync: 0 垂直同步失敗的幀
  • Number High input latency: 0 處理input時間逾時的幀數
  • Number Slow UI thread: 2 因UI線程上的工作導緻逾時的幀數
  • Number Slow bitmap uploads: 0 因bitmap的加載耗時的幀數
  • Number Slow issue draw commands: 1 因繪制導緻耗時的幀數
  • HISTOGRAM: 5ms=78 6ms=16 7ms=4 … 直方圖資料,表面耗時為0-5ms的幀數為78,耗時為5-6ms的幀數為16,同理類推。