Android 性能优化(21)*性能工具之「GPU呈现模式分析」Profiling GPU Rendering Walkthrough:分析View显示是否超标

Profiling GPU Rendering Walkthrough

  This walkthrough shows how to use Profile GPU Rendering on your mobile device.

  Profile GPU Rendering gives you a quick visual representation of how much time it takes to render the frames of a UI window relative to the 16-ms-per-frame benchmark.

 可以查看基于每帧16ms这个参考点,ui所用时间是否正常。

  What it's good for:

  • Quickly seeing how a UI window performs against the 16-ms-per-frame target.
  • Identifying whether any part of the rendering pipeline stands out in using processing time.
  • Looking for spikes in frame rendering time associated with user or program actions.

2.Prerequisites

3.Working with Profile GPU Rendering 开启Profile GPU Rendering 的方法

    1. On your mobile device, go to Settings >Developer Options.
    2. In the Monitoring section, select Profile GPU Rendering.
    3. In the Profile GPU Rendering popup, choose On screen as bars to overlay the graphs on the screen of your mobile device.
    4. Go to the app that you want to profile.

          

          Figure 1. Turning on Profile GPU Rendering.

      5.1.1中文版的图正如下:它有两个选项,一个是直接在屏幕上显示,一个是显示在命令行中显示。

        

          Figure5.中文版设置界面

4.What you see

    • For each visible application, the tool displays a graph.
    • The horizontal axis shows time elapsing, and the vertical axis time per frame in milliseconds.
    • As you interact with your application, vertical bars show up on your screen, appearing from left to right, graphing frame performance over time.
    • Each vertical bar represents one frame of rendering. The taller the bar, the longer it took to render.
    • The green line marks the 16 millisecond target. Every time a frame crosses the green line, your app is missing a frame, and your users may see this as stuttering images.

      

        Figure 2. Screen when Profile GPU Rendering is on.

5.The Profile GPU Rendering Graph

  

    Figure 3. Enlarged Annotated Profile GPU Rendering graph.

  

    Figure6.示例

  In this enlarged image of the Profile GPU Rending graph you can see the colored sections of the graph, and what phase of the rendering pipeline each color represents.

 开启「GPU呈现模式分析」之后,运行目标程序时,会上屏幕上产生图表,如上图。其中不同颜色代表的含义:
  • The green line represents 16 milliseconds. To achieve 60 frames per second, the vertical bar for each frame needs to stay below this 16 ms mark. Any time a bar pushes above this line, there may be pauses in the animations.
    为了保证每秒能绘60帧,每帧应该保持低于16 ms。上图中的绿色横线是一条基线,高于它的说明有问题。
  • Each bar has a blue, purple (only for Android version 4.0 and higher), red, and orange component.
  • The blue section of the bar represents the time used to create and update the View's display lists. If this part of the bar is tall, there may be a lot of custom view drawing, or a lot of work in onDraw methods.
    蓝色竖线 代表创建、更新view的时间,如果它高于基线,说有很多个自定义的view在绘制、更新或者某个onDraw方法中有大量工作。
  • Android 4.0 and higher: The purple section of the bar represents the time spent transferring resources to the render thread.
    紫色坚线 代表资源转移到绘制线程消耗的时间。
  • The red section of the bar represents the time spent by Android's 2D renderer issuing commands to OpenGL to draw and redraw display lists. The height of this bar is directly proportional to the sum of the time it takes each display list to execute—more display lists equals a taller red bar.
    红色竖线 代表 Android 2D 引擎把绘制指令传给 OpenGL 模块消耗的时间。
  • The orange section of the bar represents the time the CPU is waiting for the GPU to finish its work. If this bar gets tall, it means the app is doing too much work on the GPU.
    一般GPU的指令从CPU传来,如果GPU队列満了,CPU就要等待。
    橙色竖线 代表CPU等待GPU完成工作的时间,它过高,说明GPU有大量的工作。注意,是CPU等待GPU。

  Note: While this tool is named Profile GPU Rendering, all monitored processes actually occur in the CPU. Rendering happens by submitting commands to the GPU, and the GPU renders the screen asynchronously. In certain situations, the GPU can have too much work to do, and your CPU will have to wait before it can submit new commands. When this happens, you'll see spikes in the Process (orange bar) and Execute (red bar) stages, and the command submission will block until more room is made on the GPU command queue.

6. adb shell dumpsys gfxinfo 命令

  这个命令就是Figure5中的第2个选项,下面是示例:

6.1 运行目标程序一段时间:

6.2 运行命令,查看它有系统信息:

$ adb shell dumpsys gfxinfo com.e.weixin

得到如下输出:可以把这些数据复制到Excel表格中,来显示一个累积柱状图。

Applications Graphics Acceleration Info:
Uptime: 4701875 Realtime: 12789537

** Graphics info for pid 12328 [com.e.weixin] **

Recent DisplayList operations
                      DrawPatch
                      DrawPatch
                      DrawPatch
                      DrawPatch
                      DrawPatch
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                      DrawDisplayList
                        Save
                        ClipRect
                        DrawDisplayList
                        DrawDisplayList
                        DrawDisplayList
                        RestoreToCount
                DrawDisplayList
              DrawDisplayList
      DrawPatch

Caches:
Current memory usage / total memory usage (bytes):
  TextureCache         10435956 / 25165824
  LayerCache                  0 / 16777216
  GradientCache               0 /   524288
  PathCache                 930 /  4194304
  CircleShapeCache            0 /  1048576
  OvalShapeCache              0 /  1048576
  RoundRectShapeCache         0 /  1048576
  RectShapeCache              0 /  1048576
  ArcShapeCache               0 /  1048576
  TextDropShadowCache         0 /  2097152
  FontRenderer 0         262144 /   262144
  FontRenderer 1         262144 /   262144
  FontRenderer 2         262144 /   262144
Other:
  FboCache                    0 /       16
  PatchCache                  3 /      512
Total memory usage:
  11223318 bytes, 10.70 MB

Profile data in ms:

    com.e.weixin/com.e.weixin.main.presenter.MainActivity/android.view.ViewRootImpl@422ce8a8
    Draw    Process    Execute
    2.67    2.35      1.72
    8.87    2.59      1.77
    1.97    1.45      7.42
    1.91    1.56      7.87
    3.57    0.83      4.38
    2.88    1.71      3.76
    2.63    0.78      4.96
    3.57    0.84      3.84
    2.10    0.80      5.89
    1.77    0.81      4.58
    2.61    1.41      2.10
    2.90    1.65      1.42
    3.50    0.84      1.49
    4.58    0.84      1.55
    4.24    0.85      1.48
    3.98    0.85      2.91
    0.76    1.95      1.75
    13.61   36.21     1.98
    2.33    1.69      1.02
    4.74    2.51      1.53
    0.25    2.41      1.22
    9.61    13.62      1.49
    0.37    2.62      1.25
    9.09    11.78      1.89
    1.53    1.59      0.90
    2.93    2.76      1.11
    0.27    1.66      1.38
    2.65    1.59      3.88
    0.26    1.65      1.68
    3.20    2.20      1.03
    0.76    2.52      1.85
    1.35    2.07      1.37
    2.38    0.73      1.49
    1.98    0.67      1.36
    2.39    1.59      2.10
    3.78    4.09      1.90
    3.89    0.98      11.62
    1.91    0.84      13.99
    2.10    0.62      12.38
    1.57    0.65      12.04
    3.16    0.68      11.16
    2.20    0.69      12.04
    2.60    1.02      11.25
    2.48    0.67      11.29
    2.12    0.88      11.31
    2.27    0.69      11.21

View hierarchy:

  com.e.weixin/com.e.weixin.main.presenter.MainActivity/android.view.ViewRootImpl@422ce8a8
  181 views, 12.45 kB of display lists, 50 frames rendered


Total ViewRootImpl: 1
Total Views:        181
Total DisplayList:  12.45 kB

注意 “Profile data in ms”的区域

  每列数据显示了渲染每一帧需要的时间:

  1. Draw 是在Java中创建显示列表所需要的时间。这个值显示了运行绘图函数用了多长时间,比如View.onDraw(Canvas)。
  2. Process 是Android 2D引擎渲染显示列表所需要的时间。在界面中View数目越多,则有越多的绘制命令需要执行。
  3. Execute 是把一帧数据送到屏幕上排版显示的时间,这个时间通常比较小。

屏幕上显示的每一帧都要经过3步:java创建绘制列表,渲染引擎显示列表,把每一帧送到屏幕上排版显示。

6.3 初步分析

  要流畅的运行60帧/秒, 则需要每帧的处理时间不超过16ms。如上图中有个36.21 ,如果多个超过16ms,那么说明有严重问题。


posted @ 2016-04-21 15:45  f9q  阅读(1736)  评论(0编辑  收藏  举报