跳转至正文

调试 Web 应用性能

学习如何使用 Chrome DevTools 调试 Web 性能问题。

Flutter 框架在构建帧、绘制场景以及跟踪垃圾回收等活动时会发出 timeline 事件。这些事件会暴露在 Chrome DevTools performance panel(性能面板)中,供调试使用。

你还可以使用 dart:developerTimelineTimelineTask API 发出自定义 timeline 事件,以进行更深入的性能分析。

Screenshot of the Chrome DevTools performance panel

用于增强跟踪的可选标志

#

要在应用中配置跟踪哪些 timeline 事件,请在 main 方法中将以下任一顶层属性设为 true

操作步骤

#
  1. [Optional] Set any desired tracing flags to true from your app's main method.

  2. [可选] 在应用的 main 方法中将所需的跟踪标志设为 true。

  3. Run your Flutter web app in profile mode.

  4. profile mode(profile 模式)运行 Flutter Web 应用。

  5. Open up the Chrome DevTools Performance panel for your application, and start recording to capture timeline events.

  6. 为应用打开 Chrome DevTools Performance panel(性能面板),并 start recording(开始录制)以捕获 timeline 事件。