Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 63630af

Browse files
committed
Truncate thread names on Linux to the maximum allowed length
Also update some Impeller thread names to fit within that limit.
1 parent 205ed68 commit 63630af

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

fml/thread.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ void SetThreadName(const std::string& name) {
108108
#if defined(FML_OS_MACOSX)
109109
pthread_setname_np(name.c_str());
110110
#elif defined(FML_OS_LINUX) || defined(FML_OS_ANDROID)
111-
pthread_setname_np(pthread_self(), name.c_str());
111+
// Linux thread names are limited to 16 characters including the terminating
112+
// null.
113+
constexpr std::string::size_type kLinuxMaxThreadNameLen = 15;
114+
pthread_setname_np(pthread_self(),
115+
name.substr(0, kLinuxMaxThreadNameLen).c_str());
112116
#elif defined(FML_OS_WIN)
113117
THREADNAME_INFO info;
114118
info.dwType = 0x1000;

fml/thread_unittests.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,22 @@ TEST(Thread, ThreadPriorityCreatedWithConfig) {
149149
thread.Join();
150150
ASSERT_TRUE(done);
151151
}
152-
#endif
152+
#endif // FLUTTER_PTHREAD_SUPPORTED
153+
154+
#if defined(FML_OS_LINUX)
155+
TEST(Thread, LinuxLongThreadNameTruncated) {
156+
const std::string name = "VeryLongThreadNameTest";
157+
fml::Thread thread(name);
158+
159+
bool done = false;
160+
thread.GetTaskRunner()->PostTask([&done, &name]() {
161+
done = true;
162+
char thread_name[16];
163+
pthread_t current_thread = pthread_self();
164+
pthread_getname_np(current_thread, thread_name, 16);
165+
ASSERT_EQ(thread_name, name.substr(0, 15));
166+
});
167+
thread.Join();
168+
ASSERT_TRUE(done);
169+
}
170+
#endif // FML_OS_LINUX

impeller/renderer/backend/vulkan/context_vk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ void ContextVK::Setup(Settings settings) {
130130
return;
131131
}
132132

133-
queue_submit_thread_ = std::make_unique<fml::Thread>("QueueSubmitThread");
133+
queue_submit_thread_ = std::make_unique<fml::Thread>("IplrVkQueueSub");
134134
queue_submit_thread_->GetTaskRunner()->PostTask([]() {
135135
// submitKHR is extremely cheap and mostly blocks on an internal fence.
136136
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);

impeller/renderer/backend/vulkan/fence_waiter_vk.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static std::vector<vk::Fence> GetFencesForWaitSet(const WaitSet& set) {
9191

9292
void FenceWaiterVK::Main() {
9393
fml::Thread::SetCurrentThreadName(
94-
fml::Thread::ThreadConfig{"io.flutter.impeller.fence_waiter"});
94+
fml::Thread::ThreadConfig{"IplrVkFenceWait"});
9595
// Since this thread mostly waits on fences, it doesn't need to be fast.
9696
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);
9797

impeller/renderer/backend/vulkan/resource_manager_vk.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ void ResourceManagerVK::Start() {
3838
//
3939
// ... so no FML_DCHECK here.
4040

41-
fml::Thread::SetCurrentThreadName(
42-
fml::Thread::ThreadConfig{"io.flutter.impeller.resource_manager"});
41+
fml::Thread::SetCurrentThreadName(fml::Thread::ThreadConfig{"IplrVkResMgr"});
4342
// While this code calls destructors it doesn't need to be particularly fast
4443
// with them, as long as it doesn't interrupt raster thread.
4544
fml::RequestAffinity(fml::CpuAffinity::kEfficiency);

0 commit comments

Comments
 (0)