Unverified Commit a8116e9e authored by liyuqian's avatar liyuqian Committed by GitHub

Allow profile widget builds in profile mode (#30990)

## Description

Previously, such function is only available in the debug mode. But the
performance information is very noisy in debug mode with JIT. I feel
that such function is as important and useful as the performance overlay
and the `--trace-skia` option for the GPU thread.  So we should give it
the same ability to run in both profile and debug mode.

I've tested it using flutter_gallery in the profile mode. There's no
observable difference in the performance overlay between toggling widget
build profiling.

## Related Issues

https://github.com/flutter/flutter/issues/30984
parent 330dc94c
......@@ -302,6 +302,16 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
};
},
);
// Expose the ability to send Widget rebuilds as [Timeline] events.
registerBoolServiceExtension(
name: 'profileWidgetBuilds',
getter: () async => debugProfileBuildsEnabled,
setter: (bool value) async {
if (debugProfileBuildsEnabled != value)
debugProfileBuildsEnabled = value;
},
);
}
assert(() {
......@@ -316,16 +326,6 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
},
);
// Expose the ability to send Widget rebuilds as [Timeline] events.
registerBoolServiceExtension(
name: 'profileWidgetBuilds',
getter: () async => debugProfileBuildsEnabled,
setter: (bool value) async {
if (debugProfileBuildsEnabled != value)
debugProfileBuildsEnabled = value;
},
);
// This service extension is deprecated and will be removed by 12/1/2018.
// Use ext.flutter.inspector.show instead.
registerBoolServiceExtension(
......
......@@ -3730,11 +3730,8 @@ abstract class ComponentElement extends Element {
/// [rebuild] when the element needs updating.
@override
void performRebuild() {
assert(() {
if (debugProfileBuildsEnabled)
Timeline.startSync('${widget.runtimeType}', arguments: timelineWhitelistArguments);
return true;
}());
if (!kReleaseMode && debugProfileBuildsEnabled)
Timeline.startSync('${widget.runtimeType}', arguments: timelineWhitelistArguments);
assert(_debugSetAllowIgnoredCallsToMarkNeedsBuild(true));
Widget built;
......@@ -3757,11 +3754,8 @@ abstract class ComponentElement extends Element {
_child = updateChild(null, built, slot);
}
assert(() {
if (debugProfileBuildsEnabled)
Timeline.finishSync();
return true;
}());
if (!kReleaseMode && debugProfileBuildsEnabled)
Timeline.finishSync();
}
/// Subclasses should override this function to actually call the appropriate
......
......@@ -884,7 +884,7 @@ abstract class ResidentRunner {
}
return true;
} else if (character == 'a') {
if (supportsServiceProtocol && isRunningDebug) {
if (supportsServiceProtocol) {
await _debugToggleProfileWidgetBuilds();
}
} else if (lower == 'o') {
......@@ -993,12 +993,12 @@ abstract class ResidentRunner {
printStatus('To toggle the widget inspector (WidgetsApp.showWidgetInspectorOverride), press "i".');
printStatus('To toggle the display of construction lines (debugPaintSizeEnabled), press "p".');
printStatus('To simulate different operating systems, (defaultTargetPlatform), press "o".');
printStatus('To enable timeline events for all widget build methods, (debugProfileWidgetBuilds), press "a"');
printStatus('To toggle the elevation checker, press "z".');
} else {
printStatus('To dump the accessibility tree (debugDumpSemantics), press "S" (for traversal order) or "U" (for inverse hit test order).');
}
printStatus('To display the performance overlay (WidgetsApp.showPerformanceOverlay), press "P".');
printStatus('To enable timeline events for all widget build methods, (debugProfileWidgetBuilds), press "a"');
}
if (flutterDevices.any((FlutterDevice d) => d.device.supportsScreenshot)) {
printStatus('To save a screenshot to flutter.png, press "s".');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment