roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.06k stars 213 forks source link

Print thread ID in log messages #290

Closed gavv closed 4 years ago

gavv commented 4 years ago

Problem

It would be convenient to include integral thread identifier in log messages.

Currently messages look like this:

13:36:34.803 [dbg] roc_sndio: initializing pulseaudio backend

and with thread ID they should look like:

13:36:48.977 [7843] [dbg] roc_sndio: initializing pulseaudio backend

This thread ID can be used to distinguish threads, and, at least on Linux, to find these threads in ps/top and to send signals to them.

Solution

We can use syscall(SYS_gettid) on Linux and pthread_getthreadid_np() on OSX and (in future) on BSD. Both function are non-portable.

Steps:

dshil commented 4 years ago

@gavv, what about using uv_thread_self()?

gavv commented 4 years ago

@dshil it's portable, but, just like pthread_self(), it returns an opaque handle that is not an integral type. It can't be printed, or used to find the thread in ps/top, or used to to send a signal to the thread.

gavv commented 4 years ago

Assigned to @RohanK99.