diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 916ce6e72a..ace6f46b18 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -361,6 +361,14 @@ bool DartIsolate::Initialize(Dart_Isolate dart_isolate) { tonic::DartIsolateScope scope(isolate()); + // For the root isolate set the "AppStartUp" as soon as the root isolate + // has been initialized. This is to ensure that all the timeline events + // that have the set user-tag will be listed user AppStartUp. + if (IsRootIsolate()) { + tonic::DartApiScope api_scope; + Dart_SetCurrentUserTag(Dart_NewUserTag("AppStartUp")); + } + SetMessageHandlingTaskRunner(GetTaskRunners().GetUITaskRunner()); if (tonic::LogIfError( diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index a9812957be..453f30c3f3 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -2862,5 +2862,38 @@ TEST_F(ShellTest, CanCreateShellsWithMetalBackend) { DestroyShell(std::move(shell)); } +TEST_F(ShellTest, UserTagSetOnStartup) { + ASSERT_FALSE(DartVMRef::IsInstanceRunning()); + // Make sure the shell launch does not kick off the creation of the VM + // instance by already creating one upfront. + auto vm_settings = CreateSettingsForFixture(); + auto vm_ref = DartVMRef::Create(vm_settings); + ASSERT_TRUE(DartVMRef::IsInstanceRunning()); + + auto settings = vm_settings; + fml::AutoResetWaitableEvent isolate_create_latch; + + // ensure that "AppStartUpTag" is set during isolate creation. + settings.root_isolate_create_callback = [&](const DartIsolate& isolate) { + Dart_Handle current_tag = Dart_GetCurrentUserTag(); + Dart_Handle startup_tag = Dart_NewUserTag("AppStartUp"); + EXPECT_TRUE(Dart_IdentityEquals(current_tag, startup_tag)); + + isolate_create_latch.Signal(); + }; + + auto shell = CreateShell(settings); + ASSERT_TRUE(ValidateShell(shell.get())); + + auto configuration = RunConfiguration::InferFromSettings(settings); + ASSERT_TRUE(configuration.IsValid()); + + RunEngine(shell.get(), std::move(configuration)); + ASSERT_TRUE(DartVMRef::IsInstanceRunning()); + + DestroyShell(std::move(shell)); + isolate_create_latch.Wait(); +} + } // namespace testing } // namespace flutter