Android帧率测试
SurfaceFlinger
SurfaceFlinger是Android的一个服务,运行在Android的System进程中,负责管理系统的帧缓冲区,绘制应用程序的UI。Android应用程序会请求SurfaceFlinger服务创建Surface,在上面绘制自己的UI,然后将这个已经绘制好了UI的Surface渲染到设备显示屏上去
$adb shell dumpsys SurfaceFlinger --latency-clear[void android::SurfaceFlinger::setMTKProperties(android::String8&)]========================================================================[AOSPpart] debug.sf.showupdates (mDebugRegion): 0 debug.sf.ddms(mDebugDDMS): 0[MTK SF part] debug.sf.busyswap (mBusySwap): 0 debug.sf.log_repaint (mLogRepaint): 0 debug.sf.log_buffer(mLogBuffer): 0 debug.sf.line_g3d (mLineG3D): 0 debug.sf.line_ss(mLineScreenShot): 0 debug.sf.dump_ss (mDumpScreenShot): 0debug.sf.slowmotion (mDelayTime): 0 debug.sf.contbufsenable(mContBufsDump): 0[MTK GUI part] debug.bq.line: 0 debug.st.line:0[MTK HWC part] debug.sf.line_ovl: 0 debug.sf.debug_oex:0==================================================================
获取可视窗口列表
$adb shell dumpsys SurfaceFlinger --list[void android::SurfaceFlinger::setMTKProperties(android::String8&)]========================================================================[AOSPpart] debug.sf.showupdates (mDebugRegion): 0 debug.sf.ddms(mDebugDDMS): 0[MTK SF part] debug.sf.busyswap (mBusySwap): 0 debug.sf.log_repaint (mLogRepaint): 0 debug.sf.log_buffer(mLogBuffer): 0 debug.sf.line_g3d (mLineG3D): 0 debug.sf.line_ss(mLineScreenShot): 0 debug.sf.dump_ss (mDumpScreenShot): 0debug.sf.slowmotion (mDelayTime): 0 debug.sf.contbufsenable(mContBufsDump): 0[MTK GUI part] debug.bq.line: 0 debug.st.line:0[MTK HWC part] debug.sf.line_ovl: 0 debug.sf.debug_oex:0========================================================================DimSurfacecom.android.systemui.ImageWallpapercom.tmall.wireless/com.tmall.wireless.maintab.module.TMMainTabActivitycom.tmall.wireless/com.tmall.wireless.module.category.TMNewCategoryActivitycom.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivityDimAnimatorStatusBa
r
越下面的窗口,越在上层。如我要找天猫打开的Activity,就取得包名为com.tmall.wireless
的最后一条数据xxx.TMSearchResultActivity
获取窗口的帧延时数据
$adb shell dumpsys SurfaceFlinger --latencycom.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity[voidandroid::SurfaceFlinger::setMTKProperties(android::String8&)]========================================================================[AOSPpart] debug.sf.showupdates (mDebugRegion): 0 debug.sf.ddms(mDebugDDMS): 0[MTK SF part] debug.sf.busyswap (mBusySwap): 0 debug.sf.log_repaint (mLogRepaint): 0 debug.sf.log_buffer(mLogBuffer): 0 debug.sf.line_g3d (mLineG3D): 0 debug.sf.line_ss(mLineScreenShot): 0 debug.sf.dump_ss (mDumpScreenShot): 0 debug.sf.slowmotion (mDelayTime): 0 debug.sf.contbufsenable(mContBufsDump): 0[MTK GUI part] debug.bq.line: 0 debug.st.line:0[MTK HWC part] debug.sf.line_ovl: 0 debug.sf.debug_oex:0========================================================================1734003818121933162051812209665589 18122106141281812212222282 181222712128218122279181281812239753051 1812261917205 181226252166718122732010511812296490820 1812297217743......1815880321744 181589651243618158976691281815897796051 1815913973205 181591502828218159150933591815931327974 18159324689741815933351974 1815948728436 1815949869743
latency帧率数据说明
说明:
刷新频率: 17340038118121933162051812209665589 1812210614128218122122222821812227121282 1812227918128318122397530511812261917205 1812262521667……12718159150933591815931327974 181593246897412818159333519741815948728436 1815949869743
Thefirst line currently contains the refresh period innanosecond.第一行是刷新频率,后面有128行,每行3个时间戳。
Each128 following line contains 3 timestamps, of respectively the appdraw time , the vsync timestamp just prior the call to set and thetimestamp of the call to set.在/Users/army/JavaDev/adt_20140702/sdk/sources/android-xx/com/android/uiautomator/platform/SurfaceFlingerHelper.java中包含framerate 的计算方法:
/** * Calculate frame rate * @return */ public staticdouble getFrameRate() { if (mRefreshPeriod < 0) { log(Run command + FRAME_LATENCY_CMD + before calcuating averageframe rate); return -1.0; } if(mFrameBufferData.get(0) == null) { log(Run command +FRAME_LATENCY_CMD + before retrieving frame buffer data); return-1.0; } long startTime =Long.parseLong(mFrameBufferData.get(0).get(1)); long endTime =Long.parseLong(mFrameBufferData.get(mFrameLatencySampleSize -1).get(1)); long totalDuration = endTime - startTime; return(double)((mFrameLatencySampleSize - 1) * Math.pow(10,9))/totalDuration; }
dumpsysgfxinfo
在开发者选项中有个“ GPU呈现模式分析(ProfileGPU rendering,计算adbshell dumpsysgfxinfo中的呈现时间)”功能,在开启这个功能后,系统就会记录保留每个界面最后128帧图像绘制的相关时间信息。在开启这个功能后,重新启动APP,滑动页面然后执行adb命令
$adb shell dumpsys gfxinfo com.tmall.wirelessApplications GraphicsAcceleration Info:Uptime: 386315 Realtime: 386308** Graphics info forpid 4887 [com.tmall.wireless] **Recent DisplayList operations ClipRect DrawText RestoreToCount RestoreToCount DrawPatchRestoreToCountDrawRectDrawPathDrawBitmapDrawText...multiDrawDrawTextDrawPatchDrawBitmapDrawBitmapRectDrawRectDrawOval...multiDrawDrawTextDrawPatchCaches:Current memory usage / total memory usage(bytes): TextureCache 15078192 / 25165824 LayerCache 311296 / 16777216 RenderBufferCache 0 / 2097152GradientCache 4096 / 524288 PathCache 1781076 /10485760 TextDropShadowCache 0 / 2097152 FontRenderer 0 524288 / 524288Other: FboCache 1 / 16 PatchCache 3 / 512Total memory usage: 17698948 bytes, 16.88 MBProfiledata inms:com.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity/android.view.ViewRootImpl@42f81df0DrawProcessExecute1.11 2.490.431.26 2.890.631.85 4.620.651.724.163.561.88 3.150.462.67 2.680.451.22 2.670.581.22 2.810.421.742.250.38102.77 10.32 0.522.48 5.480.532.19 4.990.562.10 4.770.501.102.550.402.26 4.040.47...View hierarchy:com.tmall.wireless/com.tmall.wireless.maintab.module.TMMainTabActivity/android.view.ViewRootImpl@42d08ee8138 views, 62.20 kB of display lists, 1637 frames renderedcom.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity/android.view.ViewRootImpl@42f81df0420 views, 82.98 kB of display lists, 862 frames renderedTotalViewRootImpl: 2Total Views: 558Total DisplayList: 145.18 kB
Draw:表示在Java中创建显示列表部分中,OnDraw()方法占用的时间。Process:表示渲染引擎执行显示列表所花的时间,view越多,时间就越长Execute:表示把一帧数据发送到屏幕上排版显示实际花费的时间。其实是实际显示帧数据的后台缓存区与前台缓冲区交换后并将前台缓冲区的内容显示到屏幕上的时间。Draw+ Process + Execute = 完整显示一帧,这个时间要小于16ms才能保存每秒60帧。
取得数据后,复制到excel中生成堆积柱状图.
图中可以清晰的看出在滑动时,耗时明显有很多帧超过16ms。这些都是需要结合操作进行优化的。
更多相关文章
- android 界面布局 很好的一篇总结 【转】
- Android(安卓): 隐藏软键盘
- android9.0 系统默认时间修改
- Android(安卓)双屏异显
- Android屏幕元素层次结构
- Android横竖屏限制切换
- Android之系统自带的文字外观设置及实际显示效果图 android:text
- 实现android启动界面字体的动画效果
- Android中EditText属性
随机推荐
- Android——Fragment介绍及两种基本使用
- android apk反编译(反编译—改代码—再编
- Android(安卓)ApiDemo学习——AutoComple
- Android软件开发之常用系统控件界面大合
- Android(安卓)ApiDemos示例解析(66):Grap
- Android(安卓)---- WebView与JavaScript
- Android(安卓)异步开发之 AsyncQueryHand
- 利用ViewDragHelper轻松实现Android拼图
- AndroidStudio3.4+ 导入旧版本moudle出现
- Android画布和图形绘制---Canvas and Dra