Unverified Commit e9be230a authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Deprecate profile() (#29054)

parent c2f4386c
...@@ -8,7 +8,7 @@ import 'dart:isolate'; ...@@ -8,7 +8,7 @@ import 'dart:isolate';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'profile.dart'; import 'constants.dart';
/// Signature for the callback passed to [compute]. /// Signature for the callback passed to [compute].
/// ///
...@@ -45,7 +45,9 @@ typedef ComputeCallback<Q, R> = R Function(Q message); ...@@ -45,7 +45,9 @@ typedef ComputeCallback<Q, R> = R Function(Q message);
/// The `debugLabel` argument can be specified to provide a name to add to the /// The `debugLabel` argument can be specified to provide a name to add to the
/// [Timeline]. This is useful when profiling an application. /// [Timeline]. This is useful when profiling an application.
Future<R> compute<Q, R>(ComputeCallback<Q, R> callback, Q message, { String debugLabel }) async { Future<R> compute<Q, R>(ComputeCallback<Q, R> callback, Q message, { String debugLabel }) async {
profile(() { debugLabel ??= callback.toString(); }); if (!kReleaseMode) {
debugLabel ??= callback.toString();
}
final Flow flow = Flow.begin(); final Flow flow = Flow.begin();
Timeline.startSync('$debugLabel: start', flow: flow); Timeline.startSync('$debugLabel: start', flow: flow);
final ReceivePort resultPort = ReceivePort(); final ReceivePort resultPort = ReceivePort();
......
...@@ -6,10 +6,16 @@ import 'dart:ui' show VoidCallback; ...@@ -6,10 +6,16 @@ import 'dart:ui' show VoidCallback;
import 'constants.dart'; import 'constants.dart';
/// When running in profile mode (or debug mode), invoke the given function. /// DEPRECATED. `function` cannot be treeshaken out of release builds.
/// ///
/// In release mode, the function is not invoked. /// Instead use:
// TODO(devoncarew): Going forward, we'll want the call to profile() to be tree-shaken out. ///
/// ```dart
/// if (!kReleaseMode) {
/// function();
/// }
/// ```
@Deprecated('Use `if (!kReleaseMode) { function(); }` instead')
void profile(VoidCallback function) { void profile(VoidCallback function) {
if (kReleaseMode) if (kReleaseMode)
return; return;
......
...@@ -749,9 +749,9 @@ class PipelineOwner { ...@@ -749,9 +749,9 @@ class PipelineOwner {
/// ///
/// See [RendererBinding] for an example of how this function is used. /// See [RendererBinding] for an example of how this function is used.
void flushLayout() { void flushLayout() {
profile(() { if (!kReleaseMode) {
Timeline.startSync('Layout', arguments: timelineWhitelistArguments); Timeline.startSync('Layout', arguments: timelineWhitelistArguments);
}); }
assert(() { assert(() {
_debugDoingLayout = true; _debugDoingLayout = true;
return true; return true;
...@@ -771,9 +771,9 @@ class PipelineOwner { ...@@ -771,9 +771,9 @@ class PipelineOwner {
_debugDoingLayout = false; _debugDoingLayout = false;
return true; return true;
}()); }());
profile(() { if (!kReleaseMode) {
Timeline.finishSync(); Timeline.finishSync();
}); }
} }
} }
...@@ -809,14 +809,18 @@ class PipelineOwner { ...@@ -809,14 +809,18 @@ class PipelineOwner {
/// Called as part of the rendering pipeline after [flushLayout] and before /// Called as part of the rendering pipeline after [flushLayout] and before
/// [flushPaint]. /// [flushPaint].
void flushCompositingBits() { void flushCompositingBits() {
profile(() { Timeline.startSync('Compositing bits'); }); if (!kReleaseMode) {
Timeline.startSync('Compositing bits');
}
_nodesNeedingCompositingBitsUpdate.sort((RenderObject a, RenderObject b) => a.depth - b.depth); _nodesNeedingCompositingBitsUpdate.sort((RenderObject a, RenderObject b) => a.depth - b.depth);
for (RenderObject node in _nodesNeedingCompositingBitsUpdate) { for (RenderObject node in _nodesNeedingCompositingBitsUpdate) {
if (node._needsCompositingBitsUpdate && node.owner == this) if (node._needsCompositingBitsUpdate && node.owner == this)
node._updateCompositingBits(); node._updateCompositingBits();
} }
_nodesNeedingCompositingBitsUpdate.clear(); _nodesNeedingCompositingBitsUpdate.clear();
profile(() { Timeline.finishSync(); }); if (!kReleaseMode) {
Timeline.finishSync();
}
} }
List<RenderObject> _nodesNeedingPaint = <RenderObject>[]; List<RenderObject> _nodesNeedingPaint = <RenderObject>[];
...@@ -837,7 +841,9 @@ class PipelineOwner { ...@@ -837,7 +841,9 @@ class PipelineOwner {
/// ///
/// See [RendererBinding] for an example of how this function is used. /// See [RendererBinding] for an example of how this function is used.
void flushPaint() { void flushPaint() {
profile(() { Timeline.startSync('Paint', arguments: timelineWhitelistArguments); }); if (!kReleaseMode) {
Timeline.startSync('Paint', arguments: timelineWhitelistArguments);
}
assert(() { assert(() {
_debugDoingPaint = true; _debugDoingPaint = true;
return true; return true;
...@@ -862,7 +868,9 @@ class PipelineOwner { ...@@ -862,7 +868,9 @@ class PipelineOwner {
_debugDoingPaint = false; _debugDoingPaint = false;
return true; return true;
}()); }());
profile(() { Timeline.finishSync(); }); if (!kReleaseMode) {
Timeline.finishSync();
}
} }
} }
...@@ -937,7 +945,9 @@ class PipelineOwner { ...@@ -937,7 +945,9 @@ class PipelineOwner {
void flushSemantics() { void flushSemantics() {
if (_semanticsOwner == null) if (_semanticsOwner == null)
return; return;
profile(() { Timeline.startSync('Semantics'); }); if (!kReleaseMode) {
Timeline.startSync('Semantics');
}
assert(_semanticsOwner != null); assert(_semanticsOwner != null);
assert(() { _debugDoingSemantics = true; return true; }()); assert(() { _debugDoingSemantics = true; return true; }());
try { try {
...@@ -952,7 +962,9 @@ class PipelineOwner { ...@@ -952,7 +962,9 @@ class PipelineOwner {
} finally { } finally {
assert(_nodesNeedingSemantics.isEmpty); assert(_nodesNeedingSemantics.isEmpty);
assert(() { _debugDoingSemantics = false; return true; }()); assert(() { _debugDoingSemantics = false; return true; }());
profile(() { Timeline.finishSync(); }); if (!kReleaseMode) {
Timeline.finishSync();
}
} }
} }
} }
......
...@@ -890,11 +890,11 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -890,11 +890,11 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
if (rawTimeStamp != null) if (rawTimeStamp != null)
_lastRawTimeStamp = rawTimeStamp; _lastRawTimeStamp = rawTimeStamp;
profile(() { if (!kReleaseMode) {
_profileFrameNumber += 1; _profileFrameNumber += 1;
_profileFrameStopwatch.reset(); _profileFrameStopwatch.reset();
_profileFrameStopwatch.start(); _profileFrameStopwatch.start();
}); }
assert(() { assert(() {
if (debugPrintBeginFrameBanner || debugPrintEndFrameBanner) { if (debugPrintBeginFrameBanner || debugPrintEndFrameBanner) {
...@@ -957,10 +957,10 @@ mixin SchedulerBinding on BindingBase, ServicesBinding { ...@@ -957,10 +957,10 @@ mixin SchedulerBinding on BindingBase, ServicesBinding {
} finally { } finally {
_schedulerPhase = SchedulerPhase.idle; _schedulerPhase = SchedulerPhase.idle;
Timeline.finishSync(); // end the Frame Timeline.finishSync(); // end the Frame
profile(() { if (!kReleaseMode) {
_profileFrameStopwatch.stop(); _profileFrameStopwatch.stop();
_profileFramePostEvent(); _profileFramePostEvent();
}); }
assert(() { assert(() {
if (debugPrintEndFrameBanner) if (debugPrintEndFrameBanner)
debugPrint('▀' * _debugBanner.length); debugPrint('▀' * _debugBanner.length);
......
...@@ -270,7 +270,7 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -270,7 +270,7 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
void initServiceExtensions() { void initServiceExtensions() {
super.initServiceExtensions(); super.initServiceExtensions();
profile(() { if (!kReleaseMode) {
registerSignalServiceExtension( registerSignalServiceExtension(
name: 'debugDumpApp', name: 'debugDumpApp',
callback: () { callback: () {
...@@ -302,7 +302,7 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -302,7 +302,7 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
}; };
}, },
); );
}); }
assert(() { assert(() {
registerBoolServiceExtension( registerBoolServiceExtension(
...@@ -566,10 +566,10 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -566,10 +566,10 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
/// This is used by [WidgetsApp] to avoid reporting frames that aren't useful /// This is used by [WidgetsApp] to avoid reporting frames that aren't useful
/// during startup as the "first frame". /// during startup as the "first frame".
void deferFirstFrameReport() { void deferFirstFrameReport() {
profile(() { if (!kReleaseMode) {
assert(_deferFirstFrameReportCount >= 0); assert(_deferFirstFrameReportCount >= 0);
_deferFirstFrameReportCount += 1; _deferFirstFrameReportCount += 1;
}); }
} }
/// When called after [deferFirstFrameReport]: tell the framework to report /// When called after [deferFirstFrameReport]: tell the framework to report
...@@ -581,10 +581,10 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -581,10 +581,10 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
/// This is used by [WidgetsApp] to report when the first useful frame is /// This is used by [WidgetsApp] to report when the first useful frame is
/// painted. /// painted.
void allowFirstFrameReport() { void allowFirstFrameReport() {
profile(() { if (!kReleaseMode) {
assert(_deferFirstFrameReportCount >= 1); assert(_deferFirstFrameReportCount >= 1);
_deferFirstFrameReportCount -= 1; _deferFirstFrameReportCount -= 1;
}); }
} }
void _handleBuildScheduled() { void _handleBuildScheduled() {
...@@ -706,13 +706,13 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB ...@@ -706,13 +706,13 @@ mixin WidgetsBinding on BindingBase, SchedulerBinding, GestureBinding, RendererB
return true; return true;
}()); }());
} }
profile(() { if (!kReleaseMode) {
if (_needToReportFirstFrame && _reportFirstFrame) { if (_needToReportFirstFrame && _reportFirstFrame) {
developer.Timeline.instantSync('Widgets completed first useful frame'); developer.Timeline.instantSync('Widgets completed first useful frame');
developer.postEvent('Flutter.FirstFrame', <String, dynamic>{}); developer.postEvent('Flutter.FirstFrame', <String, dynamic>{});
_needToReportFirstFrame = false; _needToReportFirstFrame = false;
} }
}); }
} }
/// The [Element] that is at the root of the hierarchy (and which wraps the /// The [Element] that is at the root of the hierarchy (and which wraps the
......
...@@ -10,7 +10,7 @@ void main() { ...@@ -10,7 +10,7 @@ void main() {
// that the code in the `profile` closure is omitted in release mode. // that the code in the `profile` closure is omitted in release mode.
test('profile invokes its closure in debug or profile mode', () { test('profile invokes its closure in debug or profile mode', () {
int count = 0; int count = 0;
profile(() { profile(() { // ignore: deprecated_member_use_from_same_package
count++; count++;
}); });
// We run our tests in debug mode, so kReleaseMode will always evaluate to // We run our tests in debug mode, so kReleaseMode will always evaluate to
......
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