Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fml/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion fml/thread_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/fence_waiter_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions impeller/renderer/backend/vulkan/resource_manager_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down