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

Guard access to dart:developer with !kReleaseMode (#130627)

parent 7937b1d5
...@@ -158,9 +158,8 @@ abstract class BindingBase { ...@@ -158,9 +158,8 @@ abstract class BindingBase {
initServiceExtensions(); initServiceExtensions();
assert(_debugServiceExtensionsRegistered); assert(_debugServiceExtensionsRegistered);
developer.postEvent('Flutter.FrameworkInitialization', <String, String>{});
if (!kReleaseMode) { if (!kReleaseMode) {
developer.postEvent('Flutter.FrameworkInitialization', <String, String>{});
FlutterTimeline.finishSync(); FlutterTimeline.finishSync();
} }
} }
...@@ -657,14 +656,19 @@ abstract class BindingBase { ...@@ -657,14 +656,19 @@ abstract class BindingBase {
/// [locked]. /// [locked].
@protected @protected
Future<void> lockEvents(Future<void> Function() callback) { Future<void> lockEvents(Future<void> Function() callback) {
final developer.TimelineTask timelineTask = developer.TimelineTask()..start('Lock events'); developer.TimelineTask? debugTimelineTask;
if (!kReleaseMode) {
debugTimelineTask = developer.TimelineTask()..start('Lock events');
}
_lockCount += 1; _lockCount += 1;
final Future<void> future = callback(); final Future<void> future = callback();
future.whenComplete(() { future.whenComplete(() {
_lockCount -= 1; _lockCount -= 1;
if (!locked) { if (!locked) {
timelineTask.finish(); if (!kReleaseMode) {
debugTimelineTask!.finish();
}
try { try {
unlocked(); unlocked();
} catch (error, stack) { } catch (error, stack) {
......
...@@ -103,9 +103,9 @@ class ImageCache { ...@@ -103,9 +103,9 @@ class ImageCache {
if (value == maximumSize) { if (value == maximumSize) {
return; return;
} }
TimelineTask? timelineTask; TimelineTask? debugTimelineTask;
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask = TimelineTask()..start( debugTimelineTask = TimelineTask()..start(
'ImageCache.setMaximumSize', 'ImageCache.setMaximumSize',
arguments: <String, dynamic>{'value': value}, arguments: <String, dynamic>{'value': value},
); );
...@@ -114,10 +114,10 @@ class ImageCache { ...@@ -114,10 +114,10 @@ class ImageCache {
if (maximumSize == 0) { if (maximumSize == 0) {
clear(); clear();
} else { } else {
_checkCacheSize(timelineTask); _checkCacheSize(debugTimelineTask);
} }
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(); debugTimelineTask!.finish();
} }
} }
...@@ -142,9 +142,9 @@ class ImageCache { ...@@ -142,9 +142,9 @@ class ImageCache {
if (value == _maximumSizeBytes) { if (value == _maximumSizeBytes) {
return; return;
} }
TimelineTask? timelineTask; TimelineTask? debugTimelineTask;
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask = TimelineTask()..start( debugTimelineTask = TimelineTask()..start(
'ImageCache.setMaximumSizeBytes', 'ImageCache.setMaximumSizeBytes',
arguments: <String, dynamic>{'value': value}, arguments: <String, dynamic>{'value': value},
); );
...@@ -153,10 +153,10 @@ class ImageCache { ...@@ -153,10 +153,10 @@ class ImageCache {
if (_maximumSizeBytes == 0) { if (_maximumSizeBytes == 0) {
clear(); clear();
} else { } else {
_checkCacheSize(timelineTask); _checkCacheSize(debugTimelineTask);
} }
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(); debugTimelineTask!.finish();
} }
} }
...@@ -283,7 +283,6 @@ class ImageCache { ...@@ -283,7 +283,6 @@ class ImageCache {
/// Resizes the cache as appropriate to maintain the constraints of /// Resizes the cache as appropriate to maintain the constraints of
/// [maximumSize] and [maximumSizeBytes]. /// [maximumSize] and [maximumSizeBytes].
void _touch(Object key, _CachedImage image, TimelineTask? timelineTask) { void _touch(Object key, _CachedImage image, TimelineTask? timelineTask) {
assert(timelineTask != null);
if (image.sizeBytes != null && image.sizeBytes! <= maximumSizeBytes && maximumSize > 0) { if (image.sizeBytes != null && image.sizeBytes! <= maximumSizeBytes && maximumSize > 0) {
_currentSizeBytes += image.sizeBytes!; _currentSizeBytes += image.sizeBytes!;
_cache[key] = image; _cache[key] = image;
...@@ -324,9 +323,9 @@ class ImageCache { ...@@ -324,9 +323,9 @@ class ImageCache {
/// Images that are larger than [maximumSizeBytes] are not cached, and do not /// Images that are larger than [maximumSizeBytes] are not cached, and do not
/// cause other images in the cache to be evicted. /// cause other images in the cache to be evicted.
ImageStreamCompleter? putIfAbsent(Object key, ImageStreamCompleter Function() loader, { ImageErrorListener? onError }) { ImageStreamCompleter? putIfAbsent(Object key, ImageStreamCompleter Function() loader, { ImageErrorListener? onError }) {
TimelineTask? timelineTask; TimelineTask? debugTimelineTask;
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask = TimelineTask()..start( debugTimelineTask = TimelineTask()..start(
'ImageCache.putIfAbsent', 'ImageCache.putIfAbsent',
arguments: <String, dynamic>{ arguments: <String, dynamic>{
'key': key.toString(), 'key': key.toString(),
...@@ -337,7 +336,7 @@ class ImageCache { ...@@ -337,7 +336,7 @@ class ImageCache {
// Nothing needs to be done because the image hasn't loaded yet. // Nothing needs to be done because the image hasn't loaded yet.
if (result != null) { if (result != null) {
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(arguments: <String, dynamic>{'result': 'pending'}); debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'pending'});
} }
return result; return result;
} }
...@@ -348,7 +347,7 @@ class ImageCache { ...@@ -348,7 +347,7 @@ class ImageCache {
final _CachedImage? image = _cache.remove(key); final _CachedImage? image = _cache.remove(key);
if (image != null) { if (image != null) {
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'}); debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'});
} }
// The image might have been keptAlive but had no listeners (so not live). // The image might have been keptAlive but had no listeners (so not live).
// Make sure the cache starts tracking it as live again. // Make sure the cache starts tracking it as live again.
...@@ -369,10 +368,10 @@ class ImageCache { ...@@ -369,10 +368,10 @@ class ImageCache {
liveImage.completer, liveImage.completer,
sizeBytes: liveImage.sizeBytes, sizeBytes: liveImage.sizeBytes,
), ),
timelineTask, debugTimelineTask,
); );
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'}); debugTimelineTask!.finish(arguments: <String, dynamic>{'result': 'keepAlive'});
} }
return liveImage.completer; return liveImage.completer;
} }
...@@ -382,7 +381,7 @@ class ImageCache { ...@@ -382,7 +381,7 @@ class ImageCache {
_trackLiveImage(key, result, null); _trackLiveImage(key, result, null);
} catch (error, stackTrace) { } catch (error, stackTrace) {
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.finish(arguments: <String, dynamic>{ debugTimelineTask!.finish(arguments: <String, dynamic>{
'result': 'error', 'result': 'error',
'error': error.toString(), 'error': error.toString(),
'stackTrace': stackTrace.toString(), 'stackTrace': stackTrace.toString(),
...@@ -397,7 +396,7 @@ class ImageCache { ...@@ -397,7 +396,7 @@ class ImageCache {
} }
if (!kReleaseMode) { if (!kReleaseMode) {
timelineTask!.start('listener'); debugTimelineTask!.start('listener');
} }
// A multi-frame provider may call the listener more than once. We need do make // A multi-frame provider may call the listener more than once. We need do make
// sure that some cleanup works won't run multiple times, such as finishing the // sure that some cleanup works won't run multiple times, such as finishing the
...@@ -424,7 +423,7 @@ class ImageCache { ...@@ -424,7 +423,7 @@ class ImageCache {
// Only touch if the cache was enabled when resolve was initially called. // Only touch if the cache was enabled when resolve was initially called.
if (trackPendingImage) { if (trackPendingImage) {
_touch(key, image, timelineTask); _touch(key, image, debugTimelineTask);
} else { } else {
image.dispose(); image.dispose();
} }
...@@ -434,7 +433,7 @@ class ImageCache { ...@@ -434,7 +433,7 @@ class ImageCache {
pendingImage.removeListener(); pendingImage.removeListener();
} }
if (!kReleaseMode && !listenedOnce) { if (!kReleaseMode && !listenedOnce) {
timelineTask! debugTimelineTask!
..finish(arguments: <String, dynamic>{ ..finish(arguments: <String, dynamic>{
'syncCall': syncCall, 'syncCall': syncCall,
'sizeInBytes': sizeBytes, 'sizeInBytes': sizeBytes,
......
...@@ -88,14 +88,18 @@ abstract class ShaderWarmUp { ...@@ -88,14 +88,18 @@ abstract class ShaderWarmUp {
final ui.Picture picture = recorder.endRecording(); final ui.Picture picture = recorder.endRecording();
assert(debugCaptureShaderWarmUpPicture(picture)); assert(debugCaptureShaderWarmUpPicture(picture));
if (!kIsWeb || isCanvasKit) { // Picture.toImage is not yet implemented on the web. if (!kIsWeb || isCanvasKit) { // Picture.toImage is not yet implemented on the web.
final TimelineTask shaderWarmUpTask = TimelineTask(); TimelineTask? debugShaderWarmUpTask;
shaderWarmUpTask.start('Warm-up shader'); if (!kReleaseMode) {
debugShaderWarmUpTask = TimelineTask()..start('Warm-up shader');
}
try { try {
final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil()); final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil());
assert(debugCaptureShaderWarmUpImage(image)); assert(debugCaptureShaderWarmUpImage(image));
image.dispose(); image.dispose();
} finally { } finally {
shaderWarmUpTask.finish(); if (!kReleaseMode) {
debugShaderWarmUpTask!.finish();
}
} }
} }
picture.dispose(); picture.dispose();
......
...@@ -14,7 +14,6 @@ import 'debug.dart'; ...@@ -14,7 +14,6 @@ import 'debug.dart';
import 'priority.dart'; import 'priority.dart';
import 'service_extensions.dart'; import 'service_extensions.dart';
export 'dart:developer' show Flow;
export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback; export 'dart:ui' show AppLifecycleState, FrameTiming, TimingsCallback;
export 'priority.dart' show Priority; export 'priority.dart' show Priority;
...@@ -940,7 +939,10 @@ mixin SchedulerBinding on BindingBase { ...@@ -940,7 +939,10 @@ mixin SchedulerBinding on BindingBase {
} }
_warmUpFrame = true; _warmUpFrame = true;
final TimelineTask timelineTask = TimelineTask()..start('Warm-up frame'); TimelineTask? debugTimelineTask;
if (!kReleaseMode) {
debugTimelineTask = TimelineTask()..start('Warm-up frame');
}
final bool hadScheduledFrame = _hasScheduledFrame; final bool hadScheduledFrame = _hasScheduledFrame;
// We use timers here to ensure that microtasks flush in between. // We use timers here to ensure that microtasks flush in between.
Timer.run(() { Timer.run(() {
...@@ -969,7 +971,9 @@ mixin SchedulerBinding on BindingBase { ...@@ -969,7 +971,9 @@ mixin SchedulerBinding on BindingBase {
// scheduled frame has finished. // scheduled frame has finished.
lockEvents(() async { lockEvents(() async {
await endOfFrame; await endOfFrame;
timelineTask.finish(); if (!kReleaseMode) {
debugTimelineTask!.finish();
}
}); });
} }
......
...@@ -39,14 +39,18 @@ class _ProfiledBinaryMessenger implements BinaryMessenger { ...@@ -39,14 +39,18 @@ class _ProfiledBinaryMessenger implements BinaryMessenger {
} }
Future<ByteData?>? sendWithPostfix(String channel, String postfix, ByteData? message) async { Future<ByteData?>? sendWithPostfix(String channel, String postfix, ByteData? message) async {
final TimelineTask task = TimelineTask();
_debugRecordUpStream(channelTypeName, '$channel$postfix', codecTypeName, message); _debugRecordUpStream(channelTypeName, '$channel$postfix', codecTypeName, message);
task.start('Platform Channel send $channel$postfix'); TimelineTask? debugTimelineTask;
if (!kReleaseMode) {
debugTimelineTask = TimelineTask()..start('Platform Channel send $channel$postfix');
}
final ByteData? result; final ByteData? result;
try { try {
result = await proxy.send(channel, message); result = await proxy.send(channel, message);
} finally { } finally {
task.finish(); if (!kReleaseMode) {
debugTimelineTask!.finish();
}
} }
_debugRecordDownStream(channelTypeName, '$channel$postfix', codecTypeName, result); _debugRecordDownStream(channelTypeName, '$channel$postfix', codecTypeName, result);
return result; return result;
......
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