Skip to content

Commit

Permalink
Add profileRenderObjectPaints and profileRenderObjectLayouts serv…
Browse files Browse the repository at this point in the history
…ice extensions (flutter#91822)
  • Loading branch information
kenzieschmoll authored Oct 14, 2021
1 parent ccc8261 commit 8fa2a5e
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
18 changes: 16 additions & 2 deletions packages/flutter/lib/src/rendering/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
};
},
);

registerServiceExtension(
name: 'debugDumpSemanticsTreeInTraversalOrder',
callback: (Map<String, String> parameters) async {
Expand All @@ -164,7 +163,6 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
};
},
);

registerServiceExtension(
name: 'debugDumpSemanticsTreeInInverseHitTestOrder',
callback: (Map<String, String> parameters) async {
Expand All @@ -175,6 +173,22 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
};
},
);
registerBoolServiceExtension(
name: 'profileRenderObjectPaints',
getter: () async => debugProfilePaintsEnabled,
setter: (bool value) async {
if (debugProfilePaintsEnabled != value)
debugProfilePaintsEnabled = value;
},
);
registerBoolServiceExtension(
name: 'profileRenderObjectLayouts',
getter: () async => debugProfileLayoutsEnabled,
setter: (bool value) async {
if (debugProfileLayoutsEnabled != value)
debugProfileLayoutsEnabled = value;
},
);
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/flutter/lib/src/rendering/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ bool debugProfileLayoutsEnabled = false;

/// Adds [dart:developer.Timeline] events for every [RenderObject] painted.
///
/// This is only enabled in debug builds. The timing information this exposes is
/// not representative of actual paints. However, it can expose unexpected
/// painting in the timeline.
/// The timing information this flag exposes is not representative of actual
/// paints. However, it can expose unexpected painting in the timeline.
///
/// For details on how to use [dart:developer.Timeline] events in the Dart
/// Observatory to optimize your app, see:
Expand Down
11 changes: 4 additions & 7 deletions packages/flutter/lib/src/rendering/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ class PaintingContext extends ClipContext {
/// into the layer subtree associated with this painting context. Otherwise,
/// the child will be painted into the current PictureLayer for this context.
void paintChild(RenderObject child, Offset offset) {
if (!kReleaseMode && debugProfilePaintsEnabled)
Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent);
assert(() {
if (debugProfilePaintsEnabled)
Timeline.startSync('${child.runtimeType}', arguments: timelineArgumentsIndicatingLandmarkEvent);
debugOnProfilePaint?.call(child);
return true;
}());
Expand All @@ -189,11 +189,8 @@ class PaintingContext extends ClipContext {
child._paintWithContext(this, offset);
}

assert(() {
if (debugProfilePaintsEnabled)
Timeline.finishSync();
return true;
}());
if (!kReleaseMode && debugProfilePaintsEnabled)
Timeline.finishSync();
}

void _compositeChild(RenderObject child, Offset offset) {
Expand Down
60 changes: 59 additions & 1 deletion packages/flutter/test/foundation/service_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void main() {
const int disabledExtensions = kIsWeb ? 2 : 0;
// If you add a service extension... TEST IT! :-)
// ...then increment this number.
expect(binding.extensions.length, 33 + widgetInspectorExtensionCount - disabledExtensions);
expect(binding.extensions.length, 35 + widgetInspectorExtensionCount - disabledExtensions);

expect(console, isEmpty);
debugPrint = debugPrintThrottled;
Expand Down Expand Up @@ -442,6 +442,64 @@ void main() {
expect(binding.frameScheduled, isFalse);
});

test('Service extensions - profileRenderObjectPaints', () async {
Map<String, dynamic> result;

expect(binding.frameScheduled, isFalse);
expect(debugProfileBuildsEnabled, false);

result = await binding.testExtension('profileRenderObjectPaints', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfilePaintsEnabled, false);

result = await binding.testExtension('profileRenderObjectPaints', <String, String>{'enabled': 'true'});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfilePaintsEnabled, true);

result = await binding.testExtension('profileRenderObjectPaints', <String, String>{});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfilePaintsEnabled, true);

result = await binding.testExtension('profileRenderObjectPaints', <String, String>{'enabled': 'false'});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfilePaintsEnabled, false);

result = await binding.testExtension('profileRenderObjectPaints', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfilePaintsEnabled, false);

expect(binding.frameScheduled, isFalse);
});

test('Service extensions - profileRenderObjectLayouts', () async {
Map<String, dynamic> result;

expect(binding.frameScheduled, isFalse);
expect(debugProfileLayoutsEnabled, false);

result = await binding.testExtension('profileRenderObjectLayouts', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileLayoutsEnabled, false);

result = await binding.testExtension('profileRenderObjectLayouts', <String, String>{'enabled': 'true'});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfileLayoutsEnabled, true);

result = await binding.testExtension('profileRenderObjectLayouts', <String, String>{});
expect(result, <String, String>{'enabled': 'true'});
expect(debugProfileLayoutsEnabled, true);

result = await binding.testExtension('profileRenderObjectLayouts', <String, String>{'enabled': 'false'});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileLayoutsEnabled, false);

result = await binding.testExtension('profileRenderObjectLayouts', <String, String>{});
expect(result, <String, String>{'enabled': 'false'});
expect(debugProfileLayoutsEnabled, false);

expect(binding.frameScheduled, isFalse);
});

test('Service extensions - evict', () async {
Map<String, dynamic> result;
bool completed;
Expand Down

0 comments on commit 8fa2a5e

Please sign in to comment.