Name threadpool threads.
authorBenoit Jacob <benoitjacob@google.com>
Thu, 16 Feb 2023 15:23:13 +0000 (15:23 +0000)
committerBenoit Jacob <benoitjacob@google.com>
Thu, 23 Feb 2023 18:11:15 +0000 (18:11 +0000)
This gives our worker threads some names that allow easily identifying them in tools such as profilers and debuggers.

Differential Revision: https://reviews.llvm.org/D144297

llvm/lib/Support/ThreadPool.cpp

index 31461e3..4eef339 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/Config/llvm-config.h"
 
 #if LLVM_ENABLE_THREADS
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
 #else
 #include "llvm/Support/raw_ostream.h"
@@ -43,6 +44,7 @@ void ThreadPool::grow(int requested) {
   while (static_cast<int>(Threads.size()) < newThreadCount) {
     int ThreadID = Threads.size();
     Threads.emplace_back([this, ThreadID] {
+      set_thread_name(formatv("llvm-worker-{0}", ThreadID));
       Strategy.apply_thread_strategy(ThreadID);
       processTasks(nullptr);
     });