brpc icon indicating copy to clipboard operation
brpc copied to clipboard

bthread 使用的线程设置线程名

Open feng-y opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? (你需要的功能是否与某个问题有关?) 方便gdb && pstack 的时候找到bthread 使用线程

Describe the solution you'd like (描述你期望的解决方法) pthread_setname_np

Describe alternatives you've considered (描述你想到的折衷方案) 在TaskControl::init, TaskControl::add_works TimeThread::Start 创建线程时使用 pthread_setname_np 设置线程名

Additional context/screenshots (更多上下文/截图) 最近在查一个线程问题,bthread 因为使用了 pthread mutex 导致所有的bthread 都锁住了,pstack 也无法完整打出栈数据处理,无法快速识别出bthread 具体卡到哪了,如果为bthread 使用的线程命名,就比较方便的找出线程并用 gdb thread apply id bt 查看,线上进程有几个线程,最终花了较长时间才找到bthread 的线程并定位

feng-y avatar Sep 09 '22 15:09 feng-y

We must specify rules for the naming of threads. In my thinking, a thread' name can be "create_function + number". a example like: TaskContol::init_1 if TaskControl::init create a thread firstly. then other name just incremently. Any other greater design?


我们必须要为创建的线程指定命名规则, 我的想法是, 一个线程的别名是 创建的他的函数 + 第几个创建的, 一个例子如 TaskControl::init_1 是 TaskControl::init 创建的第一个线程. 此后依次递增. 请问这样是否是合适的或者有更好的想法吗?

fansehep avatar Oct 05 '22 06:10 fansehep

I want to work on this issue @feng-y @fansehep and I understood the feature that is required since I am a beginner can you tell me how should I start working on this issue and which files do I need to make changes in?

Divyansh200102 avatar Dec 04 '23 06:12 Divyansh200102

Worker threads and other threads has been named by #2136 .

chenBright avatar Dec 04 '23 06:12 chenBright