Perfetto性能优化:卡顿检测之FrameTimeline官方文档详细剖析

Perfetto slice提示App Deadline Missed 的问题通常是由于主线程被阻塞或任务执行时间过长。减少主线程的任务。优化 UI 渲染,简化布局和绘制逻辑。使用异步任务处理耗时操作。使用工具进行详细的性能分析,找到具体的瓶颈并优化。这些步骤有助于提升应用的流畅度,避免掉帧和卡顿。 阅读详情

Android Jank detection with FrameTimeline

NOTE: FrameTimeline requires Android 12(S) or higher

A frame is said to be janky if the time the frame was presented on screen does
not match the predicted present time given by the scheduler.

A jank can cause:

  • Unstable frame rate
  • Increased latency

FrameTimeline is a module within SurfaceFlinger that detects janks and reports
the source of the jank.
SurfaceViews
are currently not supported, but will be, in future.

UI

Two new tracks are added for every application that had at least one frame on
screen.
在这里插入图片描述

  • Expected Timeline
    Each slice represents the time given to the app for rendering the
    frame. To avoid janks in the system, the app is expected to finish within this
    time frame. The start time is the time the Choreographer callback was scheduled to run.

  • Actual Timeline
    These slices represent the actual time an app took to complete the frame
    (including GPU work) and send it to SurfaceFlinger for composition. The start time
    is the time that Choreographer#doFrame or AChoreographer_vsyncCallback started to run.
    The end time of the slices here represent max(gpu time, post time). Post time is the time the app’s frame was posted to
    SurfaceFlinger.

在这里插入图片描述

Similarly, SurfaceFlinger also gets these two new tracks representing the
expected time it’s supposed to finish within, and the actual time it took to
finish compositing frames and presenting on-screen. Here, SurfaceFlinger’s work
represents everything underneath it in the display stack. This includes the
Composer and the DisplayHAL. So, the slices represent SurfaceFlinger main
thread’s start to on-screen update.

The names of the slices represent the token received from
choreographer.
You can compare a slice in the actual timeline track to its corresponding slice
in the expected timeline track to see how the app performed compared to the
expectations. In addition, for debugging purposes, the token is added to the
app’s doFrame and RenderThread slices. For SurfaceFlinger, the same
token is shown in onMessageReceived.

在这里插入图片描述
在这里插入图片描述

Selecting an actual timeline slice

在这里插入图片描述

The selection details provide more information on what happened with the frame.
These include:

  • Present Type

Was the frame early, on time or late.

  • On time finish

Did the application finish its work for the frame on time?

  • Jank Type

Was there a jank observed with this frame? If yes, this shows what type of jank
was observed. If not, the type would be None.

  • Prediction type

Did the prediction expire by the time this frame was received by FrameTimeline?
If yes, this will say Expired Prediction. If not, Valid Prediction.

  • GPU Composition

Boolean that tells if the frame was composited by the GPU or not.

  • Layer Name

Name of the Layer/Surface to which the frame was presented. Some processes
update frames to multiple surfaces. Here, multiple slices with the same token
will be shown in the Actual Timeline. Layer Name can be a good way to
disambiguate between these slices.

  • Is Buffer?

Boolean that tells if the frame corresponds to a buffer or an animation.

Flow events

Selecting an actual timeline slice in the app also draws a line back to the
corresponding SurfaceFlinger timeline slice.

在这里插入图片描述

Since SurfaceFlinger can composite frames from multiple layers into a single
frame-on-screen (called a DisplayFrame), selecting a DisplayFrame draws
arrows to all the frames that were composited together. This can span over
multiple processes.

在这里插入图片描述

在这里插入图片描述

Color codes

| Color | Image | Description || :— | :—: | :— || Green |
在这里插入图片描述

| A good frame. No janks observed || Light Green |

在这里插入图片描述
| High latency state. The framerate is smooth but frames are presented late, resulting in an increased input latency.|| Red |
在这里插入图片描述

| Janky frame. The process the slice belongs to, is the reason for the jank. || Yellow |

在这里插入图片描述

| Used only by the apps. The frame is janky but app wasn’t the reason, SurfaceFlinger caused the jank. || Blue |
在这里插入图片描述

| Dropped frame. Not related to jank. The frame was dropped by SurfaceFlinger, preferring an updated frame over this. |

Janks explained

The jank types are defined in
JankInfo.h.
Since each app is written differently, there is no common way to go into the
internals of the apps and specify what the reason for the jank was. Our goal is
not to do this but rather, provide a quick way to tell if app was janky or if
SurfaceFlinger was janky.

None

All good. No jank with the frame. The ideal state that should be aimed for.

App janks

  • AppDeadlineMissed

The app ran longer than expected causing a jank. The total time taken by the app
frame is calculated by using the choreographer wake-up as the start time and
max(gpu, post time) as the end time. Post time is the time the frame was sent to
SurfaceFlinger. Since the GPU usually runs in parallel, it could be that the gpu
finished later than the post time.

  • BufferStuffing

This is more of a state than a jank. This happens if the app keeps sending new
frames to SurfaceFlinger before the previous frame was even presented. The
internal Buffer Queue is stuffed with buffers that are yet to be presented,
hence the name, Buffer Stuffing. These extra buffers in the queue are presented
only one after the other thus resulting in extra latency.
This can also result in a stage where there are no more buffers for the app to
use and it goes into a dequeue blocking wait.
The actual duration of work performed by the app might still be within the
deadline, but due to the stuffed nature, all the frames will be presented at
least one vsync late no matter how quickly the app finishes its work.
Frames will still be smooth in this state but there is an increased input
latency associated with the late present.

SurfaceFlinger Janks

There are two ways SurfaceFlinger can composite frames.

  • Device Composition - uses a dedicated hardware
  • GPU/Client composition - uses GPU to composite

An important thing to note is that performing device composition happens as a
blocking call on the main thread. However, GPU composition happens in parallel.
SurfaceFlinger performs the necessary draw calls and then hands over the gpu
fence to the display device. The display device then waits for the fence to be
signaled, and then presents the frame.

  • SurfaceFlingerCpuDeadlineMissed

SurfaceFlinger is expected to finish within the given deadline. If the main
thread ran for longer than that, the jank is then
SurfaceFlingerCpuDeadlineMissed. SurfaceFlinger’s CPU time is the time spent on
the main thread. This includes the entire composition time if device composition
was used. If GPU composition was used, this includes the time to write the draw
calls and handing over the frame to the GPU.

  • SurfaceFlingerGpuDeadlineMissed

The time taken by SurfaceFlinger’s main thread on the CPU + the GPU composition
time together were longer than expected. Here, the CPU time would have still
been within the deadline but since the work on the GPU wasn’t ready on time, the
frame got pushed to the next vsync.

  • DisplayHAL

DisplayHAL jank refers to the case where SurfaceFlinger finished its work and
sent the frame down to the HAL on time, but the frame wasn’t presented on the
vsync. It was presented on the next vsync. It could be that SurfaceFlinger did
not give enough time for the HAL’s work or it could be that there was a genuine
delay in the HAL’s work.

  • PredictionError

SurfaceFlinger’s scheduler plans ahead the time to present the frames. However,
this prediction sometimes drifts away from the actual hardware vsync time. For
example, a frame might have predicted present time as 20ms. Due to a drift in
estimation, the actual present time of the frame could be 23ms. This is called a
Prediction Error in SurfaceFlinger’s scheduler. The scheduler corrects itself
periodically, so this drift isn’t permanent. However, the frames that had a
drift in prediction will still be classified as jank for tracking purposes.

Isolated prediction errors are not usually perceived by the user as the
scheduler is quick to adapt and fix the drift.

Unknown jank

As the name suggests, the reason for the jank is unknown in this case. An
example here would be that SurfaceFlinger or the App took longer than expected
and missed the deadline but the frame was still presented early. The probability
of such a jank happening is very low but not impossible.

SQL

At the SQL level, frametimeline data is available in two tables

select ts, dur, surface_frame_token as app_token, display_frame_token as sf_token, process.name
from expected_frame_timeline_slice left join process using(upid)
tsdurapp_tokensf_tokenname
602304534752050000031353142com.google.android.apps.nexuslauncher
602416775402050000031373144com.google.android.apps.nexuslauncher
602528954122050000031393146com.google.android.apps.nexuslauncher
602846142411050000003144/system/bin/surfaceflinger
602958582991050000003146/system/bin/surfaceflinger
602977989132050000031473150com.android.systemui
603070757281050000003148/system/bin/surfaceflinger
603182977461050000003150/system/bin/surfaceflinger
603202364682050000031513154com.android.systemui
603295114011050000003152/system/bin/surfaceflinger
603407329561050000003154/system/bin/surfaceflinger
603426730642050000031553158com.android.systemui
select ts, dur, surface_frame_token as app_token, display_frame_token, jank_type, on_time_finish, present_type, layer_name, process.name
from actual_frame_timeline_slice left join process using(upid)
tsdurapp_tokensf_tokenjank_typeon_time_finishpresent_typelayer_namename
602304534752652637931353142Buffer Stuffing1Late PresentTX - com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity#0com.google.android.apps.nexuslauncher
602416775402823580531373144Buffer Stuffing1Late PresentTX - com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity#0com.google.android.apps.nexuslauncher
60252895412254652531393142None1On-time PresentTX - NavigationBar0#0com.android.systemui
602528954122794538231393146Buffer Stuffing1Late PresentTX - com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity#0com.google.android.apps.nexuslauncher
602848081901031823003144None1On-time Present[NULL]/system/bin/surfaceflinger
602960677221026557403146None1On-time Present[NULL]/system/bin/surfaceflinger
60297798913523922731473150None1On-time PresentTX - NavigationBar0#0com.android.systemui
603072461611030177203148None1On-time Present[NULL]/system/bin/surfaceflinger
603184972041028119903150None1On-time Present[NULL]/system/bin/surfaceflinger
60320236468274755931513154None1On-time PresentTX - NavigationBar0#0com.android.systemui

TraceConfig

Trace Protos:
FrameTimelineEvent

Datasource:

data_sources {
    config {
        name: "android.surfaceflinger.frametimeline"
    }
}

原文地址:https://mp.weixin.qq.com/s/gOvEbqbQ0XNS5BeMEr6Kwg
更多framework实战干货,请关注下面“千里马学框架”

Android 12+卡顿检测实战:用Perfetto的FrameTimeline揪出掉帧元凶(附SQL查询技巧) 本文详细介绍了如何利用Android 12引入的FrameTimeline模块和Perfetto工具进行卡顿检测与性能优化。通过解析FrameTimeline的核心机制、实战分析流程搭建以及典型卡顿模式诊断,帮助开发者精准定位掉帧问题,并提供SQL查询技巧和优化方案,显著提升应用流畅度。 阅读详情

相关推荐

Perfetto性能优化:FrameTimeline卡顿检测实战与源码解析

本文深入解析Android 12引入的FrameTimeline卡顿检测机制,通过Perfetto工具实战演示数据采集与SQL分析技巧。详细剖析应用绘制、SurfaceFlinger合成等环节的卡顿类型诊断方法,并提供源码级工作原理解读与多级优化策略,帮助开发者系统掌握Android性能优化关键技术。

rgv234567的博客 687

【免费下载】 Perfetto项目中的FrameTimeline:Android卡顿检测技术解析

在Android性能分析工具Perfetto中,FrameTimeline是一个重要的数据源模块,专门用于检测和分析Android系统中的帧渲染卡顿问题。本文将深入解析FrameTimeline的工作原理、使用方法和数据分析技巧。 ## FrameTimeline简介 FrameTimeline是Android 12(S)及以上版本中引入的卡顿检测模块,集成在SurfaceFlinger中。它...

gitblog_00779的博客 931

Android性能优化实战:用Perfetto揪出FrameTimeline中的卡顿元凶(附完整SQL查询)

本文深入探讨了如何利用Perfetto的SQL查询功能,深度剖析Android FrameTimeline数据,精准定位应用卡顿根源。通过实战SQL示例,详细讲解了从宏观卡顿类型统计到微观单帧生命周期链追踪的分析方法,帮助开发者构建数据驱动的性能优化体系,有效解决AppDeadlineMissed等核心卡顿问题。

seed的博客 500

Android系统Surface机制的SurfaceFlinger服务对帧缓冲区(Frame Buffer)的管理分析

在前文中,我们分析了SurfaceFlinger服务的启动过程。SurfaceFlinger服务在启动的过程中,会对系统的硬件帧缓冲区进行初始化。由于系统的硬件帧缓冲区一般只有一个,并且不是谁都可以随便访问的,因此,它就需要由一个服务来统一管理。在Android系统中,这个服务便是SurfaceFlinger。在本文中,我们就详细分析SurfaceFlinger服务是如何管理系统的硬件帧缓冲...

移动开发记录 245

SurfaceFlinger 合成(8)

本节会来介绍SurfaceFlinger的核心函数:合成,这个也是SurfaceFLinger最重要的功能之一。前面我们介绍过应用的窗口怎么把图元Buffer,窗口属性传递给SurfaceFlinger,而SurfaceFlinger就是要讲这些信息整合在一起,然后讲各个应用的窗口全部都合成一个,最后送到drm驱动中去显示。这个过程有大量计算机图像绘制使用的变量,还有一些gles的使用,有的我们会简单提一下,不关心的可以跳过这些,看一下总体的流程。

起司锅仔的博客 2136

搭建微信机器人的方案都在这了!

功能超级强大,虽不支持二次开发,但已有的功能足够个人使用,可惜官方作品已被腾讯告死,好在市面上还流落着不少破解版,有需要的自行搜索。可惜的是,微信官方已不准许新的微信号再使用 web 登录,这就直接从源头扼杀了 web 协议的微信机器人,虽说老的微信号还是能凑合着用,不过部分功能也受限。所以,这些都属于 PC 端的微信机器人。无论是 PC 端还是手机端,用 hook 方式实现的最大缺点就是要和某一个版本的微信客户端进行绑定,如果框架本身不对最新版本的微信适配,那使用的时候就无法升级到最新版本的微信。

weixin_47246330的博客 1万+

如何使用Perfetto通过trace分析性能问题(一)——使用Timeline检测Android Jank

perfetto, trace教程, 如何看懂trace

m0_37999066的博客 4586

基于淘宝商城用户购物行为数据分析系统

本文使用HIve+superset技术对阿里云天池提供的淘宝用户购物数据进行处理分析,得到有价值的信息并对平台提出有建设性意义的意见。

m0_51388399的博客 2821

Android FrameTimeline技术解析与性能优化实践

在移动开发领域,图形渲染性能直接影响用户体验。Android系统通过VSync信号同步屏幕刷新,但传统卡顿检测工具难以精确定位性能瓶颈。FrameTimeline作为Android 12引入的帧生命周期监控技术,通过植入系统关键路径探针,实现了从应用绘制到屏幕显示的全链路追踪。其核心原理是建立帧状态机模型,记录每帧的VSync时间戳、绘制耗时、渲染时长等关键数据。这项技术为开发者提供了类似地铁运行图的直观视图,能快速定位应用绘制超时、GPU瓶颈或合成器负载等典型问题。结合Perfetto分析工具,可以识别列

weixin_30522983的博客 228

保姆级教程:Windows下用GDC-Client下载TCGA数据,从环境变量配置到成功下载

本文提供Windows平台下使用GDC-Client下载TCGA数据的完整教程,从环境变量配置到成功下载。详细介绍了GDC-Client工具的安装、系统环境变量设置、配置文件优化以及数据下载实战技巧,帮助生物信息学研究者高效获取TCGA数据库中的癌症基因组数据。

weixin_42520025的博客 405

Matlab仿真:均匀面阵方向图、均匀线阵方向图、均匀圆阵方向图

其中,阵列方向图是评价阵列性能的重要参数之一。均匀面阵由若干个相同的阵元构成,阵元间等距排列,阵元的方向图形状为一个圆盘。均匀线阵由若干个相同的阵元构成,阵元间等距排列,阵元的方向图形状为一个矩形。本文将采用Matlab进行仿真,分别实现均匀面阵方向图、均匀线阵方向图和均匀圆阵方向图,并对三种阵列进行比较分析。通过以上代码仿真,我们可以对均匀面阵、均匀线阵和均匀圆阵进行方向图的绘制,进一步分析不同阵列在天线性能方面的差异。Matlab仿真:均匀面阵方向图、均匀线阵方向图、均匀圆阵方向图。

2301_79326857的博客 3439

实时刷新率Fps实现相关知识讲解

1、利用FrameTimeLine来获取实时fps的数据2、直接使用SurfaceFlinger中的RefreshRateOverlay这个图层类来负责显示这个实时fps数据

learnframework的博客 1610

【单片机】STM32F103C8T6 最小系统板原理图

STM32F103C8T6是一款基于ARM Cortex-M3内核的32位微控制器,由STMicroelectronics(ST)公司生产。它是STMicroelectronics的STM32系列微控制器中的一员,被广泛应用于嵌入式系统和电子设备中。LQFP48封装(Low-profile Quad Flat Package,48引脚)SRAM(静态随机访问存储器):20 KB。支持JTAG调试和编程接口(可选)多个通用输入/输出口(GPIO)USB接口(用于USB设备模式)内置调试和编程接口(SWD)

q742971636的博客 6万+

当我们讨论流畅度的时候,我们究竟在说什么?

前言:那些年我们用过的显示性能指标相对其他 Android 性能指标(如内存、CPU、功耗等)而言,显示性能(包括但不仅限于我们常说的“流畅度”)的概念本来就相对复杂。让我们更蛋疼的是,业界对显示测试评估方式也是丰富多样,这无疑更加重了我们对其理解的复杂程度。笔者简单搜集了一些业界中提及的显示性能指标,大家可以来品评一下: 指标名称:FPS 相关资料:Android性能测试之fps获取

xiaosongluo的专栏 2万+

Playwright MCP:开启浏览器自动化的新篇章

在当今数字化时代,浏览器自动化技术在众多领域发挥着至关重要的作用,从简单的网页爬取到复杂的自动化测试,再到智能代理与网页的交互等场景,都离不开高效、可靠的浏览器自动化工具。而微软推出的项目,正是在这一领域的一次创新性探索,它为开发者带来了全新的视角和强大的功能支持。本文将深入探讨的概念、架构、代码示例、应用场景、注意事项以及未来发展方向,帮助读者全面了解这一前沿技术。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 5271

【二】MADDPG多智能体算法实现(parl)【追逐游戏复现】

论文全称:Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments 论文原文:https://download.youkuaiyun.com/download/sinat_39620217/16203960 论文翻译:https://blog.youkuaiyun.com/qiusuoxiaozi/article/details/79066612 ...

丨汀、的博客 2万+

Android Graphics 显示系统 - Android Jank detection with FrameTimeline

Android Jank detection with FrameTimeline

向晚流年 2431

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

深入理解SurfaceFlinger

Handle其实就是个binder对象,相当于SurfaceFlinger把此对象的代理对象返回给SurfaceComposerClient的进程,即wms所在的进程-system_server进程,再在注释27处基于此binder对象来创建SurfaceControl对象,再把SurfaceControl对象的内存地址传给wms进程的java端,再返回给客户端,客户端就可以基于此地址来操作SurfaceControl,即变相操作SurfaceFlinger的layer完成合成等操作。

qq_15915161的博客 1825

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Android SurfaceFlinger

SurfaceFlinger是Android系统中的一个重要组件,它主要负责窗口管理与界面显示。具体来说,SurfaceFlinger作为系统的显示引擎,负责接收各应用程序发来的图像数据,并组合成一张完整的画面,并输出到显示屏上。SurfaceFlinger通过重绘整个屏幕或部分屏幕来更新UI界面。它还提供了多种硬件加速技术,如OpenGL ES、Vulkan等,使应用程序能够更快地渲染UI界面。SurfaceFlinger还支持窗口叠加、透明度、混合模式等特性,以支持复杂的多层UI界面。

liuning1985622的博客 3959

Android Visualizer 实战:把声音画出来

是系统提供的音频效果(AudioEffect)之一。它挂在音频链路上,,把数据回吐给你——画波形、画频谱、做响度表。

Android的专栏 320

PHP多维数组排序完全指南

需求:订单按「待付款 → 待发货 → 已完成 → 已取消」排,而不是按字典序。??});用??给未知状态兜底,避免警告。/*** 多字段排序(usort 版,支持保留键名与自定义比较器)* 用法:* @param array $list 待排序数组* @param array $rules [字段名, 方向 asc|desc, 类型 numeric|string|natural|regular]* @param bool $keepKeys 是否保留键名(true 用 uasort)

qq_19716091的博客 183

Android 开发入门实践(十三):用 Intent、UiState 和 Reducer 理解 MVI 的状态更新

本文记录第141—145课对MVI架构的入门实践,通过“返回列表”功能逐步构建意图(NewsIntent)、状态(NewsUiState)与状态转换(reduce)机制。基于单向数据流,用户操作生成意图,ViewModel通过Reducer根据旧状态计算新状态,并通过StateFlow更新Compose界面。代码实现清晰分离关注点,强化了对状态管理、事件驱动与数据流的理解。

Easyhood的博客 356

RK-RK3572-Android16- 编译打包优化-OTA整包-差分包打包

这里主要记录一下 RK3572 在Android16 上面进行OTA升级的整包和差分包制作经验的一个分享,整理知识点,方便后续自己和其它同事开发提高工作效率、直接使用。不管哪一个平台,MTK 也好、RK也好 基本上都是不同Android版本各个子系统之间还是有一点点区别的,所以有必要记录整理知识点,方便提高开发效率、生产效率。针对OTA升级问题 ,再一次说明还是要看官方提供的文档,按照文档来。

十年饮冰,难凉热血 213

安卓APK下载后安装全流程:从点击下载到第一次启动,每一步的检查点

这套流程听起来繁琐,但真正需要每次都做的只有来源核对和签名校验两步,其他都是出问题时才查。养成习惯之后,能挡掉绝大多数"装了垃圾包""装完闪退"的情况。如果要省事,直接用这类会标注包名、版本号和校验信息的站点,比在搜索结果里挨个试要稳得多。

qq362196705的专栏 193
上一篇: android图形绘制学习之从0写一个native层的绘图应用程序3种方式
下一篇: wms开发常用调试开发技巧之WMShell的实用命令
千里马学框架
博客等级 码龄6年 1万+粉丝 651原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值