Add --trace flag to flutter build apk for build profiling#116
Draft
eseidel wants to merge 3 commits intoshorebird/devfrom
Draft
Add --trace flag to flutter build apk for build profiling#116eseidel wants to merge 3 commits intoshorebird/devfrom
eseidel wants to merge 3 commits intoshorebird/devfrom
Conversation
Adds a --trace option that produces a Chrome Trace Event Format JSON file showing where time is spent across all build layers (flutter tool, Gradle, flutter assemble targets). The output can be viewed in Perfetto at https://ui.perfetto.dev.
The intermediate trace file path is shared across all Gradle variants. This is safe today since flutter build apk only runs one variant per invocation, but would need per-variant paths if that changes.
- Add --trace option to flutter build ios / flutter build ipa - Pass TRACE_FILE through Xcode build settings to xcode_backend.dart - Instrument buildXcodeProject() in mac.dart with pre-xcode, xcode, and post-xcode spans - Merge flutter assemble trace events from intermediate file - Remove TRACE_FILE from toEnvironmentConfig() since both Android and iOS orchestrators compute intermediate paths directly
f02f9f9 to
8ea86fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--traceoption toflutter build apk,flutter build ios, andflutter build ipathat produces a Chrome Trace Event Format JSON fileUsage
Implementation
Core:
BuildTracerutility class for collecting, merging, and writing Chrome Trace Event Format events--trace-fileoption threaded through both Gradle plugin (Kotlin) and Xcode build phases (xcode_backend.dart) to flutter assemblePerformanceMeasurementfor accurate cross-process timingAndroid path:
gradle.dart→ Gradle-Ptrace-fileproperty →FlutterPlugin.kt→BaseFlutterTaskHelper.kt→flutter assemble --trace-fileiOS path:
mac.dart→TRACE_FILEXcode build setting →xcode_backend.dart→flutter assemble --trace-fileThree trace rows (tids) in Perfetto:
Test plan
BuildTracerandBuildTraceEvent(8 tests)writeTraceDatain assembledart analyzeclean on all modified filesflutter build apk --trace=trace.jsonon a sample app, view in Perfettoflutter build ios --trace=trace.jsonon a sample app, view in Perfetto