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