Truncate thread names on Linux to the maximum allowed length (flutter/engine#49781)

Also update some Impeller thread names to fit within that limit.
This commit is contained in:
Jason Simmons
2024-01-16 09:02:34 -08:00
committed by GitHub
parent 196bd4165f
commit 33ff97be32
5 changed files with 24 additions and 6 deletions

View File

@@ -108,7 +108,11 @@ void SetThreadName(const std::string& name) {
#if defined(FML_OS_MACOSX)
pthread_setname_np(name.c_str());
#elif defined(FML_OS_LINUX) || defined(FML_OS_ANDROID)
pthread_setname_np(pthread_self(), name.c_str());
// Linux thread names are limited to 16 characters including the terminating
// null.
constexpr std::string::size_type kLinuxMaxThreadNameLen = 15;
pthread_setname_np(pthread_self(),
name.substr(0, kLinuxMaxThreadNameLen).c_str());
#elif defined(FML_OS_WIN)
THREADNAME_INFO info;
info.dwType = 0x1000;

View File

@@ -149,4 +149,19 @@ TEST(Thread, ThreadPriorityCreatedWithConfig) {
thread.Join();
ASSERT_TRUE(done);
}
#endif
#endif // FLUTTER_PTHREAD_SUPPORTED
#if defined(FML_OS_LINUX)
TEST(Thread, LinuxLongThreadNameTruncated) {
const std::string name = "VeryLongThreadNameTest";
fml::Thread thread(name);
thread.GetTaskRunner()->PostTask([&name]() {
constexpr size_t kThreadNameLen = 16;
char thread_name[kThreadNameLen];
pthread_getname_np(pthread_self(), thread_name, kThreadNameLen);
ASSERT_EQ(thread_name, name.substr(0, kThreadNameLen - 1));
});
thread.Join();
}
#endif // FML_OS_LINUX

View File

@@ -130,7 +130,7 @@ void ContextVK::Setup(Settings settings) {
return;
}
queue_submit_thread_ = std::make_unique<fml::Thread>("QueueSubmitThread");
queue_submit_thread_ = std::make_unique<fml::Thread>("IplrVkQueueSub");
queue_submit_thread_->GetTaskRunner()->PostTask([]() {
// submitKHR is extremely cheap and mostly blocks on an internal fence.
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);

View File

@@ -91,7 +91,7 @@ static std::vector<vk::Fence> GetFencesForWaitSet(const WaitSet& set) {
void FenceWaiterVK::Main() {
fml::Thread::SetCurrentThreadName(
fml::Thread::ThreadConfig{"io.flutter.impeller.fence_waiter"});
fml::Thread::ThreadConfig{"IplrVkFenceWait"});
// Since this thread mostly waits on fences, it doesn't need to be fast.
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);

View File

@@ -38,8 +38,7 @@ void ResourceManagerVK::Start() {
//
// ... so no FML_DCHECK here.
fml::Thread::SetCurrentThreadName(
fml::Thread::ThreadConfig{"io.flutter.impeller.resource_manager"});
fml::Thread::SetCurrentThreadName(fml::Thread::ThreadConfig{"IplrVkResMgr"});
// While this code calls destructors it doesn't need to be particularly fast
// with them, as long as it doesn't interrupt raster thread.
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);