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
Prev Previous commit
Next Next commit
const
  • Loading branch information
jiahaog committed Sep 20, 2023
commit f4d5d10c2ecdc18570392dc96ced757ea2fd5ad5
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/services/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool debugAssertAllServicesVarsUnset(String reason) {
if (debugKeyEventSimulatorTransitModeOverride != null) {
throw FlutterError(reason);
}
if (profilePlatformChannels || debugPrintKeyboardEvents) {
if (debugPrintKeyboardEvents) {
throw FlutterError(reason);
}
return true;
Expand Down
8 changes: 4 additions & 4 deletions packages/flutter/lib/src/services/platform_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export 'message_codec.dart' show MessageCodec, MethodCall, MethodCodec;
/// 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.
bool profilePlatformChannels = false;
const bool kProfilePlatformChannels = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it help to make this a const bool.fromEnvironment?

I can't remember if that works well in google's build environment or not. It also may have issues on web.

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.

That could work and we could wire it up through the build rules to have something like:

flutter_application(
  profilePlatformChannels = True,
)

But I'm not sure if this is so helpful in the near term. Since we probably don't want users to turn that flag on permanently, having to patch their flutter_application is very similar to having to patch this file locally when profiling. For now I'm working on documentation to do things manually, but in the long term this can ideally be some toggle in devtools.


bool _profilePlatformChannelsIsRunning = false;
const Duration _profilePlatformChannelsRate = Duration(seconds: 1);
Expand Down Expand Up @@ -189,7 +189,7 @@ class BasicMessageChannel<T> {
/// [BackgroundIsolateBinaryMessenger.ensureInitialized].
BinaryMessenger get binaryMessenger {
final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger();
return profilePlatformChannels
return kProfilePlatformChannels
? _profiledBinaryMessengers[this] ??= _ProfiledBinaryMessenger(
// ignore: no_runtimetype_tostring
result, runtimeType.toString(), codec.runtimeType.toString())
Expand Down Expand Up @@ -278,7 +278,7 @@ class MethodChannel {
/// [BackgroundIsolateBinaryMessenger.ensureInitialized].
BinaryMessenger get binaryMessenger {
final BinaryMessenger result = _binaryMessenger ?? _findBinaryMessenger();
return profilePlatformChannels
return kProfilePlatformChannels
? _profiledBinaryMessengers[this] ??= _ProfiledBinaryMessenger(
// ignore: no_runtimetype_tostring
result, runtimeType.toString(), codec.runtimeType.toString())
Expand Down Expand Up @@ -309,7 +309,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 =
profilePlatformChannels ?
kProfilePlatformChannels ?
await (binaryMessenger as _ProfiledBinaryMessenger).sendWithPostfix(name, '#$method', input) :
await binaryMessenger.send(name, input);
if (result == null) {
Expand Down