diff --git a/src/brpc/details/usercode_backup_pool.cpp b/src/brpc/details/usercode_backup_pool.cpp index 53a1541d32..489def454c 100644 --- a/src/brpc/details/usercode_backup_pool.cpp +++ b/src/brpc/details/usercode_backup_pool.cpp @@ -20,6 +20,7 @@ #include #include #include "butil/scoped_lock.h" +#include "butil/threading/platform_thread.h" #ifdef BAIDU_INTERNAL #include "butil/comlog_sink.h" #endif @@ -91,6 +92,7 @@ UserCodeBackupPool::UserCodeBackupPool() } static void* UserCodeRunner(void* args) { + butil::PlatformThread::SetName("brpc_user_code_runner"); static_cast(args)->UserCodeRunningLoop(); return NULL; } diff --git a/src/bthread/task_control.cpp b/src/bthread/task_control.cpp index 3b90dc7854..6706080436 100644 --- a/src/bthread/task_control.cpp +++ b/src/bthread/task_control.cpp @@ -22,6 +22,7 @@ #include "butil/scoped_lock.h" // BAIDU_SCOPED_LOCK #include "butil/errno.h" // berror #include "butil/logging.h" +#include "butil/threading/platform_thread.h" #include "butil/third_party/murmurhash3/murmurhash3.h" #include "bthread/sys_futex.h" // futex_wake_private #include "bthread/interrupt_pthread.h" @@ -68,6 +69,10 @@ void* TaskControl::worker_thread(void* arg) { LOG(ERROR) << "Fail to create TaskGroup in pthread=" << pthread_self(); return NULL; } + std::string worker_thread_name = butil::string_printf( + "brpc_worker:%d", + c->_next_worker_id.fetch_add(1, butil::memory_order_relaxed)); + butil::PlatformThread::SetName(worker_thread_name.c_str()); BT_VLOG << "Created worker=" << pthread_self() << " bthread=" << g->main_tid(); @@ -126,6 +131,7 @@ TaskControl::TaskControl() , _groups((TaskGroup**)calloc(BTHREAD_MAX_CONCURRENCY, sizeof(TaskGroup*))) , _stop(false) , _concurrency(0) + , _next_worker_id(0) , _nworkers("bthread_worker_count") , _pending_time(NULL) // Delay exposure of following two vars because they rely on TC which diff --git a/src/bthread/task_control.h b/src/bthread/task_control.h index fd40d6ce00..0a56864f2c 100644 --- a/src/bthread/task_control.h +++ b/src/bthread/task_control.h @@ -98,6 +98,7 @@ class TaskControl { bool _stop; butil::atomic _concurrency; std::vector _workers; + butil::atomic _next_worker_id; bvar::Adder _nworkers; butil::Mutex _pending_time_mutex; diff --git a/src/bthread/timer_thread.cpp b/src/bthread/timer_thread.cpp index 2c2dd9b29c..4b52b90fe6 100644 --- a/src/bthread/timer_thread.cpp +++ b/src/bthread/timer_thread.cpp @@ -23,6 +23,7 @@ #include "butil/logging.h" #include "butil/third_party/murmurhash3/murmurhash3.h" // fmix64 #include "butil/resource_pool.h" +#include "butil/threading/platform_thread.h" #include "bvar/bvar.h" #include "bthread/sys_futex.h" #include "bthread/timer_thread.h" @@ -117,6 +118,7 @@ inline bool task_greater(const TimerThread::Task* a, const TimerThread::Task* b) } void* TimerThread::run_this(void* arg) { + butil::PlatformThread::SetName("brpc_timer"); static_cast(arg)->run(); return NULL; } diff --git a/src/bvar/collector.cpp b/src/bvar/collector.cpp index c7844c1f71..d708bd52f2 100644 --- a/src/bvar/collector.cpp +++ b/src/bvar/collector.cpp @@ -20,6 +20,7 @@ #include #include #include "butil/memory/singleton_on_pthread_once.h" +#include "butil/threading/platform_thread.h" #include "bvar/bvar.h" #include "bvar/collector.h" @@ -76,11 +77,13 @@ class Collector : public bvar::Reducer { int64_t interval_us); static void* run_grab_thread(void* arg) { + butil::PlatformThread::SetName("bvar_collector_grabber"); static_cast(arg)->grab_thread(); return NULL; } static void* run_dump_thread(void* arg) { + butil::PlatformThread::SetName("bvar_collector_dumper"); static_cast(arg)->dump_thread(); return NULL; } diff --git a/src/bvar/detail/sampler.cpp b/src/bvar/detail/sampler.cpp index 1d398ba913..ea82612080 100644 --- a/src/bvar/detail/sampler.cpp +++ b/src/bvar/detail/sampler.cpp @@ -18,6 +18,7 @@ // Date: Tue Jul 28 18:14:40 CST 2015 #include +#include "butil/threading/platform_thread.h" #include "butil/time.h" #include "butil/memory/singleton_on_pthread_once.h" #include "bvar/reducer.h" @@ -108,6 +109,7 @@ class SamplerCollector : public bvar::Reducer { void run(); static void* sampling_thread(void* arg) { + butil::PlatformThread::SetName("bvar_sampler"); static_cast(arg)->run(); return NULL; } diff --git a/src/bvar/variable.cpp b/src/bvar/variable.cpp index 1f9da3a1bb..630d2af2ca 100644 --- a/src/bvar/variable.cpp +++ b/src/bvar/variable.cpp @@ -29,6 +29,7 @@ #include "butil/errno.h" // berror #include "butil/time.h" // milliseconds_from_now #include "butil/file_util.h" // butil::FilePath +#include "butil/threading/platform_thread.h" #include "bvar/gflag.h" #include "bvar/variable.h" #include "bvar/mvariable.h" @@ -728,6 +729,7 @@ static GFlag s_gflag_bvar_dump_interval("bvar_dump_interval"); static void* dumping_thread(void*) { // NOTE: this variable was declared as static <= r34381, which was // destructed when program exits and caused coredumps. + butil::PlatformThread::SetName("bvar_dumper"); const std::string command_name = read_command_name(); std::string last_filename; std::string mbvar_last_filename;