-
命令集合
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,同理类推。