From a8116e9ea3dd21eb450c1c00780f1985e1f33967 Mon Sep 17 00:00:00 2001 From: liyuqian Date: Mon, 15 Apr 2019 13:57:43 -0700 Subject: [PATCH] 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 --- packages/flutter/lib/src/widgets/binding.dart | 20 +++++++++---------- .../flutter/lib/src/widgets/framework.dart | 14 ++++--------- .../lib/src/resident_runner.dart | 4 ++-- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index 70f25ffc5d..0599fe0131 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -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( diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index aaf052721a..31d34f272d 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -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 diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index d6dea4b85a..2fd1b1952b 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -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".');