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&)]========================================================================[AOSP part]   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========================================================================

获取可视窗口列表

$ adb shell dumpsys SurfaceFlinger --list[void android::SurfaceFlinger::setMTKProperties(android::String8&)]========================================================================[AOSP part]   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========================================================================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.TMSearchResultActivityDimAnimatorStatusBar

越下面的窗口,越在上层。如我要找天猫打开的Activity, 就取得包名为 com.tmall.wireless 的最后一条数据 xxx.TMSearchResultActivity

获取窗口的帧延时数据

$ adb shell dumpsys SurfaceFlinger --latency com.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity[void android::SurfaceFlinger::setMTKProperties(android::String8&)]========================================================================[AOSP part]   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========================================================================173400381812193316205 1812209665589 18122106141281812212222282 1812227121282 18122279181281812239753051 1812261917205 18122625216671812273201051 1812296490820 1812297217743......1815880321744 1815896512436 18158976691281815897796051 1815913973205 18159150282821815915093359 1815931327974 18159324689741815933351974 1815948728436 1815949869743

latency 帧率数据说明

说明:

刷新频率: 17340038
1 18121933162051812209665589 1812210614128
2 18122122222821812227121282 1812227918128
3 18122397530511812261917205 1812262521667


127 18159150933591815931327974 1815932468974
128 18159333519741815948728436 1815949869743

The first line currently contains the refresh period in nanosecond.
第一行是刷新频率,后面有128行,每行3个时间戳。

Each 128 following line contains 3 timestamps, of respectively the app draw time , the vsync timestamp just prior the call to set and the timestamp of the call to set.
在 /Users/army/JavaDev/adt_20140702/sdk/sources/android-xx/com/android/uiautomator/platform/SurfaceFlingerHelper.java 中包含 frame rate 的计算方法:

    /** * Calculate frame rate * @return */    public static double getFrameRate() {        if (mRefreshPeriod < 0) {            log("Run command \"" + FRAME_LATENCY_CMD + " \" before calcuating average frame 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;    }

dumpsys gfxinfo

在开发者选项中有个“ GPU呈现模式分析(Profile GPU rendering,计算adb shell dumpsys gfxinfo中的呈现时间)”功能,在开启这个功能后,系统就会记录保留每个界面最后128帧图像绘制的相关时间信息。在开启这个功能后,重新启动APP,滑动页面然后执行adb命令。

$ adb shell dumpsys gfxinfo com.tmall.wirelessApplications Graphics Acceleration Info:Uptime: 386315 Realtime: 386308** Graphics info for pid 4887 [com.tmall.wireless] **Recent DisplayList operations             ClipRect             DrawText             RestoreToCount     RestoreToCount   DrawPatch RestoreToCountDrawRectDrawPathDrawBitmapDrawText...multiDraw DrawTextDrawPatchDrawBitmapDrawBitmapRectDrawRectDrawOval...multiDraw DrawTextDrawPatchCaches:Current memory usage / total memory usage (bytes): TextureCache         15078192 / 25165824 LayerCache             311296 / 16777216 RenderBufferCache           0 /  2097152 GradientCache            4096 /   524288 PathCache             1781076 / 10485760 TextDropShadowCache         0 /  2097152 FontRenderer 0         524288 /   524288Other: FboCache                    1 /       16 PatchCache                  3 /      512Total memory usage: 17698948 bytes, 16.88 MBProfile data in ms:com.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity/android.view.ViewRootImpl@42f81df0Draw Process Execute1.11 2.49 0.431.26 2.89 0.631.85 4.62 0.651.72 4.16 3.561.88 3.15 0.462.67 2.68 0.451.22 2.67 0.581.22 2.81 0.421.74 2.25 0.38102.77 10.32 0.522.48 5.48 0.532.19 4.99 0.562.10 4.77 0.501.10 2.55 0.402.26 4.04 0.47...View hierarchy:com.tmall.wireless/com.tmall.wireless.maintab.module.TMMainTabActivity/android.view.ViewRootImpl@42d08ee8 138 views, 62.20 kB of display lists, 1637 frames renderedcom.tmall.wireless/com.tmall.wireless.module.search.searchResult.TMSearchResultActivity/android.view.ViewRootImpl@42f81df0 420 views, 82.98 kB of display lists, 862 frames renderedTotal ViewRootImpl: 2Total Views:        558Total DisplayList:  145.18 kB

注意 Profile data in ms: 下面的数据
Draw:表示在Java中创建显示列表部分中,OnDraw()方法占用的时间。
Process:表示渲染引擎执行显示列表所花的时间,view越多,时间就越长
Execute:表示把一帧数据发送到屏幕上排版显示实际花费的时间。其实是实际显示帧数据的后台缓存区与前台缓冲区交换后并将前台缓冲区的内容显示到屏幕上的时间。
Draw + Process + Execute = 完整显示一帧 ,这个时间要小于16ms才能保证每秒60帧。

取得数据后,复制到excel中生成堆积柱状图.

图中可以清晰的看出在滑动时,耗时明显有很多帧超过16ms。这些都是需要结合操作进行优化的。

Android帧率测试_第1张图片

更多相关文章

  1. android中的UI中的窗口之Window类介绍
  2. Android 高效的SQLite型数据库greenDAO使用
  3. Android五种常用数据的存储方式
  4. Android 弹出窗口 PopupWindow
  5. Android ListView中带有时间数据的排序
  6. 【黑马Android】(02)短信发送器/布局演示/android下单位/android
  7. Android的数据库--sqlite(一)
  8. android时间控件DigitalClock的使用

随机推荐

  1. Android(安卓)开发技巧总结
  2. Android(安卓)Studio 设置背景色
  3. 坑中速记整理! 使用 kotlin 写第一个 Rea
  4. EditText 行间距 以及光标高度和样式
  5. Android高手进阶教程(八)之----Android(
  6. Android(安卓)Adapter使用总结
  7. android 编译自己的sdk
  8. Android(安卓)系统下模拟触点击的功能与
  9. 从零学Android(八)、Android资源类型之Draw
  10. 基于Android的WiFi对讲机项目简介