Set AppStartUp UserTag from engine (flutter/engine#27646)

This commit is contained in:
Kaushik Iska
2021-07-23 16:31:02 -04:00
committed by GitHub
parent 2f1fd5959f
commit a3b9412f5c
2 changed files with 41 additions and 0 deletions

View File

@@ -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(

View File

@@ -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