[engine] set platform thread name to ui. (flutter/engine#55362)

When running with merged platform and ui threads, set the dart thread name of the main thread to io.futter.ui. Also change the thread mask settings to avoid creating an unused UI thread.
This commit is contained in:
Jonah Williams 2024-09-25 15:06:37 -07:00 committed by GitHub
parent ca6c569006
commit 152dfb2fcf
3 changed files with 25 additions and 20 deletions

View File

@ -633,10 +633,16 @@ bool DartIsolate::UpdateThreadPoolNames() const {
}
if (auto task_runner = task_runners.GetPlatformTaskRunner()) {
bool is_merged_platform_ui_thread =
task_runner == task_runners.GetUITaskRunner();
std::string label;
if (is_merged_platform_ui_thread) {
label = task_runners.GetLabel() + std::string{".ui"};
} else {
label = task_runners.GetLabel() + std::string{".platform"};
}
task_runner->PostTask(
[label = task_runners.GetLabel() + std::string{".platform"}]() {
Dart_SetThreadName(label.c_str());
});
[label = std::move(label)]() { Dart_SetThreadName(label.c_str()); });
}
return true;

View File

@ -89,17 +89,17 @@ AndroidShellHolder::AndroidShellHolder(
static size_t thread_host_count = 1;
auto thread_label = std::to_string(thread_host_count++);
auto mask =
ThreadHost::Type::kUi | ThreadHost::Type::kRaster | ThreadHost::Type::kIo;
auto mask = ThreadHost::Type::kRaster | ThreadHost::Type::kIo;
if (!settings.merged_platform_ui_thread) {
mask |= ThreadHost::Type::kUi;
}
flutter::ThreadHost::ThreadHostConfig host_config(
thread_label, mask, AndroidPlatformThreadConfigSetter);
if (!settings.merged_platform_ui_thread) {
host_config.ui_config = fml::Thread::ThreadConfig(
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kUi, thread_label),
fml::Thread::ThreadPriority::kDisplay);
}
host_config.ui_config = fml::Thread::ThreadConfig(
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kUi, thread_label),
fml::Thread::ThreadPriority::kDisplay);
host_config.raster_config = fml::Thread::ThreadConfig(
flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kRaster, thread_label),

View File

@ -792,8 +792,10 @@ static flutter::ThreadHost MakeThreadHost(NSString* thread_label,
// initialized.
fml::MessageLoop::EnsureInitializedForCurrentThread();
uint32_t threadHostType = flutter::ThreadHost::Type::kUi | flutter::ThreadHost::Type::kRaster |
flutter::ThreadHost::Type::kIo;
uint32_t threadHostType = flutter::ThreadHost::Type::kRaster | flutter::ThreadHost::Type::kIo;
if (!settings.enable_impeller) {
threadHostType |= flutter::ThreadHost::Type::kUi;
}
if ([FlutterEngine isProfilerEnabled]) {
threadHostType = threadHostType | flutter::ThreadHost::Type::kProfiler;
@ -802,13 +804,10 @@ static flutter::ThreadHost MakeThreadHost(NSString* thread_label,
flutter::ThreadHost::ThreadHostConfig host_config(thread_label.UTF8String, threadHostType,
IOSPlatformThreadConfigSetter);
if (!settings.enable_impeller) {
host_config.ui_config =
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kUi, thread_label.UTF8String),
fml::Thread::ThreadPriority::kDisplay);
}
host_config.ui_config =
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kUi, thread_label.UTF8String),
fml::Thread::ThreadPriority::kDisplay);
host_config.raster_config =
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::kRaster, thread_label.UTF8String),