diff --git a/engine/src/flutter/lib/ui/ui_dart_state.h b/engine/src/flutter/lib/ui/ui_dart_state.h index 6d4094a47f..dea3e9b650 100644 --- a/engine/src/flutter/lib/ui/ui_dart_state.h +++ b/engine/src/flutter/lib/ui/ui_dart_state.h @@ -31,6 +31,8 @@ class UIDartState : public tonic::DartState { Dart_Port main_port() const { return main_port_; } + void set_debug_name(const std::string name) { debug_name_ = name; } + const std::string& debug_name() const { return debug_name_; } const std::string& logger_prefix() const { return logger_prefix_; } diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index fa0431b311..2c4f283214 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -714,6 +714,16 @@ class Window { /// semantics update cannot be used further. void updateSemantics(SemanticsUpdate update) native 'Window_updateSemantics'; + /// Set the debug name associated with this window's root isolate. + /// + /// Normally debug names are automatically generated from the Dart port, entry + /// point, and source file. For example: `main.dart$main-1234`. + /// + /// This can be combined with flutter tools `--isolate-filter` flag to debug + /// specific root isolates. For example: `flutter attach --isolate-filter=[name]`. + /// Note that this does not rename any child isolates of the root. + void setIsolateDebugName(String name) native 'Window_setIsolateDebugName'; + /// Sends a message to a platform-specific plugin. /// /// The `name` parameter determines which plugin receives the message. The diff --git a/engine/src/flutter/lib/ui/window/window.cc b/engine/src/flutter/lib/ui/window/window.cc index ce4626afa7..356ab771e3 100644 --- a/engine/src/flutter/lib/ui/window/window.cc +++ b/engine/src/flutter/lib/ui/window/window.cc @@ -54,6 +54,17 @@ void UpdateSemantics(Dart_NativeArguments args) { UIDartState::Current()->window()->client()->UpdateSemantics(update); } +void SetIsolateDebugName(Dart_NativeArguments args) { + Dart_Handle exception = nullptr; + const std::string name = + tonic::DartConverter::FromArguments(args, 1, exception); + if (exception) { + Dart_ThrowException(exception); + return; + } + UIDartState::Current()->window()->client()->SetIsolateDebugName(name); +} + Dart_Handle SendPlatformMessage(Dart_Handle window, const std::string& name, Dart_Handle callback, @@ -306,6 +317,7 @@ void Window::RegisterNatives(tonic::DartLibraryNatives* natives) { {"Window_respondToPlatformMessage", _RespondToPlatformMessage, 3, true}, {"Window_render", Render, 2, true}, {"Window_updateSemantics", UpdateSemantics, 2, true}, + {"Window_setIsolateDebugName", SetIsolateDebugName, 2, true}, }); } diff --git a/engine/src/flutter/lib/ui/window/window.h b/engine/src/flutter/lib/ui/window/window.h index bc1e3ba267..05ef8ef97a 100644 --- a/engine/src/flutter/lib/ui/window/window.h +++ b/engine/src/flutter/lib/ui/window/window.h @@ -43,6 +43,7 @@ class WindowClient { virtual void Render(Scene* scene) = 0; virtual void UpdateSemantics(SemanticsUpdate* update) = 0; virtual void HandlePlatformMessage(fml::RefPtr message) = 0; + virtual void SetIsolateDebugName(const std::string isolateName) = 0; virtual FontCollection& GetFontCollection() = 0; protected: diff --git a/engine/src/flutter/runtime/runtime_controller.cc b/engine/src/flutter/runtime/runtime_controller.cc index 92fb962437..956a6a6a86 100644 --- a/engine/src/flutter/runtime/runtime_controller.cc +++ b/engine/src/flutter/runtime/runtime_controller.cc @@ -264,6 +264,14 @@ void RuntimeController::HandlePlatformMessage( client_.HandlePlatformMessage(std::move(message)); } +void RuntimeController::SetIsolateDebugName(const std::string name) { + std::shared_ptr root_isolate = root_isolate_.lock(); + if (!root_isolate) { + return; + } + root_isolate->set_debug_name(name); +} + FontCollection& RuntimeController::GetFontCollection() { return client_.GetFontCollection(); } diff --git a/engine/src/flutter/runtime/runtime_controller.h b/engine/src/flutter/runtime/runtime_controller.h index 532499cb51..ac1bfca1f9 100644 --- a/engine/src/flutter/runtime/runtime_controller.h +++ b/engine/src/flutter/runtime/runtime_controller.h @@ -150,6 +150,9 @@ class RuntimeController final : public WindowClient { // |blink::WindowClient| void HandlePlatformMessage(fml::RefPtr message) override; + // |blink::WindowClient| + void SetIsolateDebugName(const std::string name) override; + // |blink::WindowClient| FontCollection& GetFontCollection() override;