估计CPU和GPU帧处理时间(帧时间)对于理解应用程序的性能和查找瓶颈至关重要。当您使用AGI分析应用程序时,系统分析器会提供可用于估计帧时间跟踪数据。
CPU时间
在AGI中,您可以在系统分析的CPU轨道中查看总CPU帧时间和活动CPU帧时间。
总CPU时间
要测量花费的总CPU时间,选择包含连续帧提交事件之间的时间范围。帧提交事件是eglSwapBuffers
(对于OpenGL)和vkQueuePresentKHR
(对于Vulkan)。

eglSwapBuffer
事件。
vkQueuePresentKHR
事件。此测量是总CPU时间的估计值,但不一定代表活动CPU时间。例如,在GPU绑定应用程序中,CPU可能需要等待GPU完成其工作,然后才能提交新帧。当dequeueBuffer
、eglSwapBuffer
(对于OpenGL)或vkQueuePresent
(对于Vulkan)事件占用大部分CPU时间时,通常会发生这种情况。等待时间包含在总CPU时间中,但不包含在活动CPU时间中。

dequeueBuffer
和eglSwapBuffer
事件期间大量空闲。活动CPU时间
活动CPU时间确定CPU何时运行应用程序代码而没有处于空闲状态。
要测量活动CPU时间,请查看CPU事件正上方的正在运行切片。计算两个帧提交事件之间跟踪中处于正在运行状态的所有部分。确保包括工作线程。


测量活动CPU时间的另一种方法是在CPU轨道中查看应用程序切片。这些切片指示CPU何时运行,并且与正在运行切片相对应。

为了帮助识别应用程序切片,您可以向您的应用程序添加ATrace标记。这将在系统分析器的CPU轨道中显示标记。

估计GPU帧时间
要估计GPU帧时间,您可以使用系统分析器中的GPU切片或GPU计数器。使用GPU切片时,估计值更准确。
GPU切片
如果系统分析器有可用的GPU切片信息,您可以通过测量应用程序用于处理与单个帧关联的任务的总时间来获得非常准确的GPU帧时间信息。
Mali设备
在Mali设备上,GPU切片具有片段、非片段以及偶尔的补充非片段轨道。对于不太复杂的帧,片段和非片段工作是顺序的,因此可以通过查找活动GPU工作之间的间隙来区分一个帧的工作与另一个帧的工作。
或者,如果您熟悉提交到GPU的工作,则识别提交的渲染通道的模式将提供有关帧何时开始和结束的信息。


对于具有更高度并行化的GPU工作流程的应用程序,您可以通过查找每个切片的选择窗格中具有相同submissionID的所有帧来获取GPU帧时间。
对于基于Vulkan的应用程序,可以使用多个提交来组合帧。通过使用Vulkan事件轨道跟踪提交ID,该轨道包含每个提交的切片。选择提交切片将突出显示与提交相对应的所有GPU活动切片。


Adreno设备
在Adreno设备上,GPU切片显示在GPU队列0轨道中,并且始终顺序表示,因此您可以查看表示帧的渲染通道的所有切片,并使用它们来测量GPU帧时间。


类似于前面描述的Mali场景:如果应用程序使用Vulkan,则Vulkan事件轨道提供有关提交到执行帧的工作的信息。要突出显示渲染通道,请单击与帧关联的Vulkan事件切片。

在某些情况下,由于应用程序严重依赖GPU,因此更难以区分GPU帧边界。在这些情况下,如果您熟悉提交到GPU的工作,则可以识别渲染通道正在执行的模式,并根据该信息确定帧边界。

GPU计数器
如果跟踪中没有GPU切片信息,则可以使用GPU计数器轨道来估计GPU帧时间。
Mali设备
在Mali设备上,您可以使用GPU利用率轨道来估计非GPU密集型应用程序的GPU帧时间。当应用程序的GPU密集程度较低时,它们具有规律的高GPU活动和低GPU活动周期,而不是持续的高活动。要使用GPU利用率轨道估计GPU帧时间,请测量轨道中高活动周期的持续时间。

如果应用对 GPU 的占用较高,您可以使用**片段**和**非片段**轨道来估算 GPU 帧时间。通过观察**片段**和**非片段**轨道的活动水平模式,您可以大致估算出帧的边界在哪里,并以此来测量 GPU 帧时间。

Adreno设备
在 Adreno 设备上,如果应用对 GPU 的占用不高,您可以像上一节中使用Mali 设备一样估算 GPU 帧时间。

如果应用对 GPU 的占用较高,您可以使用**每秒顶点指令数**和**每秒片段指令数**轨道来估算 GPU 帧时间。通过观察这些轨道的活动水平模式,您可以大致估算出帧的边界在哪里,并以此来测量 GPU 帧时间。

以下其他轨道可能提供类似的信息
- 每秒着色顶点数
- 每秒着色片段数
- 顶点着色时间百分比
- 片段时间百分比