Skip to content

Commit

Permalink
naming timer sampling and worker threads (apache#2136)
Browse files Browse the repository at this point in the history
* naming timer sampling and worker threads

* naming colloctor and varaiable

* naming usercode backup thread

---------

Co-authored-by: DongSheng He <hds@dipeak.com>
  • Loading branch information
2 people authored and Yang Liming committed Oct 31, 2023
1 parent 5349e4a commit a1a7b42
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/brpc/details/usercode_backup_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <vector>
#include <gflags/gflags.h>
#include "butil/scoped_lock.h"
#include "butil/threading/platform_thread.h"
#ifdef BAIDU_INTERNAL
#include "butil/comlog_sink.h"
#endif
Expand Down Expand Up @@ -91,6 +92,7 @@ UserCodeBackupPool::UserCodeBackupPool()
}

static void* UserCodeRunner(void* args) {
butil::PlatformThread::SetName("brpc_user_code_runner");
static_cast<UserCodeBackupPool*>(args)->UserCodeRunningLoop();
return NULL;
}
Expand Down
6 changes: 6 additions & 0 deletions src/bthread/task_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/bthread/task_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class TaskControl {
bool _stop;
butil::atomic<int> _concurrency;
std::vector<pthread_t> _workers;
butil::atomic<int> _next_worker_id;

bvar::Adder<int64_t> _nworkers;
butil::Mutex _pending_time_mutex;
Expand Down
2 changes: 2 additions & 0 deletions src/bthread/timer_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<TimerThread*>(arg)->run();
return NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions src/bvar/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <map>
#include <gflags/gflags.h>
#include "butil/memory/singleton_on_pthread_once.h"
#include "butil/threading/platform_thread.h"
#include "bvar/bvar.h"
#include "bvar/collector.h"

Expand Down Expand Up @@ -76,11 +77,13 @@ class Collector : public bvar::Reducer<Collected*, CombineCollected> {
int64_t interval_us);

static void* run_grab_thread(void* arg) {
butil::PlatformThread::SetName("bvar_collector_grabber");
static_cast<Collector*>(arg)->grab_thread();
return NULL;
}

static void* run_dump_thread(void* arg) {
butil::PlatformThread::SetName("bvar_collector_dumper");
static_cast<Collector*>(arg)->dump_thread();
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bvar/detail/sampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// Date: Tue Jul 28 18:14:40 CST 2015

#include <gflags/gflags.h>
#include "butil/threading/platform_thread.h"
#include "butil/time.h"
#include "butil/memory/singleton_on_pthread_once.h"
#include "bvar/reducer.h"
Expand Down Expand Up @@ -108,6 +109,7 @@ class SamplerCollector : public bvar::Reducer<Sampler*, CombineSampler> {
void run();

static void* sampling_thread(void* arg) {
butil::PlatformThread::SetName("bvar_sampler");
static_cast<SamplerCollector*>(arg)->run();
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bvar/variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a1a7b42

Please sign in to comment.