Visitar URL original
Rename `debugProfilePlatformChannels` to a constant that works in release mode by jiahaog · Pull Request #134922 · flutter/flutter · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
debugProfilePlatformChannels in release mode
  • Loading branch information
jiahaog committed Sep 18, 2023
commit 8dd6d3289e36dcb19e6bb1f1a782b41478232462
3 changes: 3 additions & 0 deletions packages/flutter/lib/src/services/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ KeyDataTransitMode? debugKeyEventSimulatorTransitModeOverride;
/// The statistics include the total bytes transmitted and the average number of
/// bytes per invocation in the last quantum. "Up" means in the direction of
/// Flutter to the host platform, "down" is the host platform to flutter.
///
/// Contrary to other debugging toggles in this package, this will function even
/// when [kReleaseMode] is true.
bool debugProfilePlatformChannels = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to remove the debug prefix from the variable. Things with that prefix should be guaranteed to only run in debug builds.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My interpretation of the "debug" prefix was that it's more of a debugging toggle - I couldn't find any other variables in any of the debug.dart files in the framework that don't have the prefix. On the other hand, perhaps this is the first toggle that we want to be usable in release mode.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my understanding that anything with the debug prefix should be tree-shaken in release builds. Maybe we'll have to move it out of the debug.dart file in that case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I moved it to platform_channel.dart


/// Setting to true will cause extensive logging to occur when key events are
Expand Down
15 changes: 5 additions & 10 deletions packages/flutter/lib/src/services/platform_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ class _ProfiledBinaryMessenger implements BinaryMessenger {

Future<ByteData?>? sendWithPostfix(String channel, String postfix, ByteData? message) async {
_debugRecordUpStream(channelTypeName, '$channel$postfix', codecTypeName, message);
TimelineTask? debugTimelineTask;
if (!kReleaseMode) {
debugTimelineTask = TimelineTask()..start('Platform Channel send $channel$postfix');
}
final TimelineTask timelineTask = TimelineTask()..start('Platform Channel send $channel$postfix');
final ByteData? result;
try {
result = await proxy.send(channel, message);
} finally {
if (!kReleaseMode) {
debugTimelineTask!.finish();
}
timelineTask.finish();
}
_debugRecordDownStream(channelTypeName, '$channel$postfix', codecTypeName, result);
return result;
Expand Down Expand Up @@ -183,7 +178,7 @@ class BasicMessageChannel<T> {
/// [BackgroundIsolateBinaryMessenger.ensureInitialized].
BinaryMessenger get binaryMessenger {
final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger();
return !kReleaseMode && debugProfilePlatformChannels
return debugProfilePlatformChannels
? _debugBinaryMessengers[this] ??= _ProfiledBinaryMessenger(
// ignore: no_runtimetype_tostring
result, runtimeType.toString(), codec.runtimeType.toString())
Expand Down Expand Up @@ -272,7 +267,7 @@ class MethodChannel {
/// [BackgroundIsolateBinaryMessenger.ensureInitialized].
BinaryMessenger get binaryMessenger {
final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger();
return !kReleaseMode && debugProfilePlatformChannels
return debugProfilePlatformChannels
? _debugBinaryMessengers[this] ??= _ProfiledBinaryMessenger(
// ignore: no_runtimetype_tostring
result, runtimeType.toString(), codec.runtimeType.toString())
Expand Down Expand Up @@ -303,7 +298,7 @@ class MethodChannel {
Future<T?> _invokeMethod<T>(String method, { required bool missingOk, dynamic arguments }) async {
final ByteData input = codec.encodeMethodCall(MethodCall(method, arguments));
final ByteData? result =
!kReleaseMode && debugProfilePlatformChannels ?
debugProfilePlatformChannels ?
await (binaryMessenger as _ProfiledBinaryMessenger).sendWithPostfix(name, '#$method', input) :
await binaryMessenger.send(name, input);
if (result == null) {
Expand Down