Skip to content

Commit 14cf4da

Browse files
Add debugging flags to enhance the timeline arguments for Build, Layout, and Paint (#101602)
1 parent 675b961 commit 14cf4da

File tree

6 files changed

+94
-10
lines changed

6 files changed

+94
-10
lines changed

dev/tracing_tests/test/timeline_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void main() {
100100
Map<String, String> args;
101101

102102
debugProfileBuildsEnabled = true;
103+
debugEnhanceBuildTimelineArguments = true;
103104
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF))); });
104105
events = await fetchInterestingEvents(interestingLabels);
105106
expect(
@@ -109,8 +110,10 @@ void main() {
109110
args = (events.where((TimelineEvent event) => event.json!['name'] == '$Placeholder').single.json!['args'] as Map<String, Object?>).cast<String, String>();
110111
expect(args['color'], 'Color(0xffffffff)');
111112
debugProfileBuildsEnabled = false;
113+
debugEnhanceBuildTimelineArguments = false;
112114

113115
debugProfileBuildsEnabledUserWidgets = true;
116+
debugEnhanceBuildTimelineArguments = true;
114117
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey(), color: const Color(0xFFFFFFFF))); });
115118
events = await fetchInterestingEvents(interestingLabels);
116119
expect(
@@ -120,8 +123,10 @@ void main() {
120123
args = (events.where((TimelineEvent event) => event.json!['name'] == '$Placeholder').single.json!['args'] as Map<String, Object?>).cast<String, String>();
121124
expect(args['color'], 'Color(0xffffffff)');
122125
debugProfileBuildsEnabledUserWidgets = false;
126+
debugEnhanceBuildTimelineArguments = false;
123127

124128
debugProfileLayoutsEnabled = true;
129+
debugEnhanceLayoutTimelineArguments = true;
125130
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey())); });
126131
events = await fetchInterestingEvents(interestingLabels);
127132
expect(
@@ -133,8 +138,10 @@ void main() {
133138
expect(args['creator'], contains('Placeholder'));
134139
expect(args['painter'], startsWith('_PlaceholderPainter#'));
135140
debugProfileLayoutsEnabled = false;
141+
debugEnhanceLayoutTimelineArguments = false;
136142

137143
debugProfilePaintsEnabled = true;
144+
debugEnhancePaintTimelineArguments = true;
138145
await runFrame(() { TestRoot.state.updateWidget(Placeholder(key: UniqueKey())); });
139146
events = await fetchInterestingEvents(interestingLabels);
140147
expect(
@@ -146,6 +153,7 @@ void main() {
146153
expect(args['creator'], contains('Placeholder'));
147154
expect(args['painter'], startsWith('_PlaceholderPainter#'));
148155
debugProfilePaintsEnabled = false;
156+
debugEnhancePaintTimelineArguments = false;
149157

150158
}, skip: isBrowser); // [intended] uses dart:isolate and io.
151159
}

packages/flutter/lib/src/rendering/box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ abstract class RenderBox extends RenderObject {
13711371
if (shouldCache) {
13721372
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
13731373
assert(() {
1374-
if (debugProfileLayoutsEnabled) {
1374+
if (debugEnhanceLayoutTimelineArguments) {
13751375
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
13761376
} else {
13771377
debugTimelineArguments = Map<String, String>.of(debugTimelineArguments);
@@ -1835,7 +1835,7 @@ abstract class RenderBox extends RenderObject {
18351835
if (shouldCache) {
18361836
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
18371837
assert(() {
1838-
if (debugProfileLayoutsEnabled) {
1838+
if (debugEnhanceLayoutTimelineArguments) {
18391839
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
18401840
} else {
18411841
debugTimelineArguments = Map<String, String>.of(debugTimelineArguments);

packages/flutter/lib/src/rendering/debug.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ bool debugCheckIntrinsicSizes = false;
116116
/// * [debugProfileBuildsEnabled], which does something similar for widgets
117117
/// being rebuilt.
118118
/// * [debugProfilePaintsEnabled], which does something similar for painting.
119+
/// * [debugEnhanceLayoutTimelineArguments], which enhances the trace with
120+
/// debugging information related to [RenderObject] layouts.
119121
bool debugProfileLayoutsEnabled = false;
120122

121123
/// Adds [dart:developer.Timeline] events for every [RenderObject] painted.
@@ -143,8 +145,52 @@ bool debugProfileLayoutsEnabled = false;
143145
/// * The discussion at [RendererBinding.drawFrame].
144146
/// * [RepaintBoundary], which can be used to contain repaints when unchanged
145147
/// areas are being excessively repainted.
148+
/// * [debugEnhancePaintTimelineArguments], which enhances the trace with
149+
/// debugging information related to [RenderObject] paints.
146150
bool debugProfilePaintsEnabled = false;
147151

152+
/// Adds debugging information to [Timeline] events related to [RenderObject]
153+
/// layouts.
154+
///
155+
/// This flag will only add [Timeline] event arguments for debug builds.
156+
/// Additional arguments will be added for the "LAYOUT" timeline event and for
157+
/// all [RenderObject] layout [Timeline] events, which are the events that are
158+
/// added when [debugProfileLayoutsEnabled] is true. The debugging information
159+
/// that will be added in trace arguments includes stats around [RenderObject]
160+
/// dirty states and [RenderObject] diagnostic information (i.e. [RenderObject]
161+
/// properties).
162+
///
163+
/// See also:
164+
///
165+
/// * [debugProfileLayoutsEnabled], which adds [Timeline] events for every
166+
/// [RenderObject] layout.
167+
/// * [debugEnhancePaintTimelineArguments], which does something similar for
168+
/// events related to [RenderObject] paints.
169+
/// * [debugEnhanceBuildTimelineArguments], which does something similar for
170+
/// events related to [Widget] builds.
171+
bool debugEnhanceLayoutTimelineArguments = false;
172+
173+
/// Adds debugging information to [Timeline] events related to [RenderObject]
174+
/// paints.
175+
///
176+
/// This flag will only add [Timeline] event arguments for debug builds.
177+
/// Additional arguments will be added for the "PAINT" timeline event and for
178+
/// all [RenderObject] paint [Timeline] events, which are the [Timeline] events
179+
/// that are added when [debugProfilePaintsEnabled] is true. The debugging
180+
/// information that will be added in trace arguments includes stats around
181+
/// [RenderObject] dirty states and [RenderObject] diagnostic information
182+
/// (i.e. [RenderObject] properties).
183+
///
184+
/// See also:
185+
///
186+
/// * [debugProfilePaintsEnabled], which adds [Timeline] events for every
187+
/// [RenderObject] paint.
188+
/// * [debugEnhanceLayoutTimelineArguments], which does something similar for
189+
/// events related to [RenderObject] layouts.
190+
/// * [debugEnhanceBuildTimelineArguments], which does something similar for
191+
/// events related to [Widget] builds.
192+
bool debugEnhancePaintTimelineArguments = false;
193+
148194
/// Signature for [debugOnProfilePaint] implementations.
149195
typedef ProfilePaintCallback = void Function(RenderObject renderObject);
150196

packages/flutter/lib/src/rendering/object.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ class PipelineOwner {
860860
if (!kReleaseMode) {
861861
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
862862
assert(() {
863-
if (debugProfileLayoutsEnabled) {
863+
if (debugEnhanceLayoutTimelineArguments) {
864864
debugTimelineArguments = <String, String>{
865865
...debugTimelineArguments,
866866
'dirty count': '${_nodesNeedingLayout.length}',
@@ -966,7 +966,7 @@ class PipelineOwner {
966966
if (!kReleaseMode) {
967967
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
968968
assert(() {
969-
if (debugProfilePaintsEnabled) {
969+
if (debugEnhancePaintTimelineArguments) {
970970
debugTimelineArguments = <String, String>{
971971
...debugTimelineArguments,
972972
'dirty count': '${_nodesNeedingPaint.length}',
@@ -1798,7 +1798,9 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
17981798
if (!kReleaseMode && debugProfileLayoutsEnabled) {
17991799
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
18001800
assert(() {
1801-
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
1801+
if (debugEnhanceLayoutTimelineArguments) {
1802+
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
1803+
}
18021804
return true;
18031805
}());
18041806
Timeline.startSync(
@@ -2402,7 +2404,9 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
24022404
if (!kReleaseMode && debugProfilePaintsEnabled) {
24032405
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
24042406
assert(() {
2405-
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
2407+
if (debugEnhancePaintTimelineArguments) {
2408+
debugTimelineArguments = toDiagnosticsNode().toTimelineArguments();
2409+
}
24062410
return true;
24072411
}());
24082412
Timeline.startSync(

packages/flutter/lib/src/widgets/debug.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ bool debugPrintGlobalKeyedWidgetLifecycle = false;
116116
/// * [debugProfilePaintsEnabled], which does something similar for painting.
117117
/// * [debugProfileBuildsEnabledUserWidgets], which adds events for user-created
118118
/// [Widget] build times and incurs less overhead.
119+
/// * [debugEnhanceBuildTimelineArguments], which enhances the trace with
120+
/// debugging information related to [Widget] builds.
119121
bool debugProfileBuildsEnabled = false;
120122

121123
/// Adds [Timeline] events for every user-created [Widget] built.
@@ -130,8 +132,32 @@ bool debugProfileBuildsEnabled = false;
130132
///
131133
/// * [debugProfileBuildsEnabled], which functions similarly but shows events
132134
/// for every widget and has a higher overhead cost.
135+
/// * [debugEnhanceBuildTimelineArguments], which enhances the trace with
136+
/// debugging information related to [Widget] builds.
133137
bool debugProfileBuildsEnabledUserWidgets = false;
134138

139+
/// Adds debugging information to [Timeline] events related to [Widget] builds.
140+
///
141+
/// This flag will only add [Timeline] event arguments for debug builds.
142+
/// Additional arguments will be added for the "BUILD" [Timeline] event and for
143+
/// all [Widget] build [Timeline] events, which are the [Timeline] events that
144+
/// are added when either of [debugProfileBuildsEnabled] and
145+
/// [debugProfileBuildsEnabledUserWidgets] are true. The debugging information
146+
/// that will be added in trace arguments includes stats around [Widget] dirty
147+
/// states and [Widget] diagnostic information (i.e. [Widget] properties).
148+
///
149+
/// See also:
150+
///
151+
/// * [debugProfileBuildsEnabled], which adds [Timeline] events for every
152+
/// [Widget] built.
153+
/// * [debugProfileBuildsEnabledUserWidgets], which adds [Timeline] events for
154+
/// every user-created [Widget] built.
155+
/// * [debugEnhanceLayoutTimelineArguments], which does something similar for
156+
/// events related to [RenderObject] layouts.
157+
/// * [debugEnhancePaintTimelineArguments], which does something similar for
158+
/// events related to [RenderObject] paints.
159+
bool debugEnhanceBuildTimelineArguments = false;
160+
135161
/// Show banners for deprecated widgets.
136162
bool debugHighlightDeprecatedWidgets = false;
137163

packages/flutter/lib/src/widgets/framework.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ class BuildOwner {
25652565
if (!kReleaseMode) {
25662566
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
25672567
assert(() {
2568-
if (debugProfileBuildsEnabled) {
2568+
if (debugEnhanceBuildTimelineArguments) {
25692569
debugTimelineArguments = <String, String>{
25702570
...debugTimelineArguments,
25712571
'dirty count': '${_dirtyElements.length}',
@@ -2645,7 +2645,7 @@ class BuildOwner {
26452645
if (isTimelineTracked) {
26462646
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
26472647
assert(() {
2648-
if (kDebugMode) {
2648+
if (kDebugMode && debugEnhanceBuildTimelineArguments) {
26492649
debugTimelineArguments = element.widget.toDiagnosticsNode().toTimelineArguments();
26502650
}
26512651
return true;
@@ -3517,7 +3517,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
35173517
if (isTimelineTracked) {
35183518
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
35193519
assert(() {
3520-
if (kDebugMode) {
3520+
if (kDebugMode && debugEnhanceBuildTimelineArguments) {
35213521
debugTimelineArguments = newWidget.toDiagnosticsNode().toTimelineArguments();
35223522
}
35233523
return true;
@@ -3782,7 +3782,7 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
37823782
if (isTimelineTracked) {
37833783
Map<String, String> debugTimelineArguments = timelineArgumentsIndicatingLandmarkEvent;
37843784
assert(() {
3785-
if (kDebugMode) {
3785+
if (kDebugMode && debugEnhanceBuildTimelineArguments) {
37863786
debugTimelineArguments = newWidget.toDiagnosticsNode().toTimelineArguments();
37873787
}
37883788
return true;

0 commit comments

Comments
 (0)