除錯 Web 應用的效能
瞭解如何使用 Chrome DevTools 除錯 Web 效能問題。
Flutter 框架會在構建幀、繪製場景以及追蹤垃圾回收等活動時發出時間軸事件。這些事件會顯示在 Chrome DevTools 效能面板中,供你進行除錯。
你還可以使用 dart:developer 中的 Timeline 和 TimelineTask API 發出自己的時間軸事件,以進行更深入的效能分析。
用於增強跟蹤的可選標誌
#若要配置要跟蹤哪些時間軸事件,請在應用的 main 方法中將以下任意頂級屬性設定為 true。
-
debugProfileBuildsEnabled:為每個構建的
Widget新增Timeline事件。 -
debugProfileBuildsEnabledUserWidgets:為每個使用者建立的
Widget構建新增Timeline事件。 -
debugProfileLayoutsEnabled:為每個
RenderObject佈局新增Timeline事件。 -
debugProfilePaintsEnabled:為每個
RenderObject繪製新增Timeline事件。
操作說明
#- [可選] 在應用的 main 方法中,將所需的任何跟蹤標誌設定為 true。
- 以 Profile 模式執行你的 Flutter Web 應用。
- 為你的應用開啟 Chrome DevTools 效能面板,然後開始錄製以捕獲時間軸事件。