From a8013ffe706ca522277f1261ed6b9448ee26e03e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Sat, 13 Feb 2021 12:13:51 -0500 Subject: [PATCH] TT#111051 set thread specific process names Change-Id: I6a5bb14c070d93b865510786f5107220b93faef1 --- daemon/aux.c | 12 +++++++++--- daemon/call.c | 2 +- daemon/main.c | 29 +++++++++++++++++------------ daemon/websocket.c | 2 +- include/aux.h | 6 +++--- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/daemon/aux.c b/daemon/aux.c index eee18854f..ce2c3b846 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -213,7 +213,7 @@ static void *thread_detach_func(void *d) { return NULL; } -static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle) { +static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle, const char *name) { pthread_attr_t att; pthread_t thr; int ret; @@ -235,11 +235,17 @@ static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread return ret; if (handle) *handle = thr; +#ifdef __GLIBC__ + if (name) + pthread_setname_np(thr, name); +#endif return 0; } -void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority) { +void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority, + const char *name) +{ struct detach_thread *dt; dt = g_slice_alloc(sizeof(*dt)); @@ -248,7 +254,7 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler dt->scheduler = scheduler; dt->priority = priority; - if (thread_create(thread_detach_func, dt, 1, NULL)) + if (thread_create(thread_detach_func, dt, 1, NULL, name)) abort(); } diff --git a/daemon/call.c b/daemon/call.c index 28d17ac6b..05b129f92 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -478,7 +478,7 @@ destroy: if (xh) thread_create_detach_prio(xmlrpc_kill_calls, xh, rtpe_config.idle_scheduling, - rtpe_config.idle_priority); + rtpe_config.idle_priority, "XMLRPC callback"); } diff --git a/daemon/main.c b/daemon/main.c index 25957e838..db0493691 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1059,39 +1059,44 @@ int main(int argc, char **argv) { ilog(LOG_INFO, "Startup complete, version %s", RTPENGINE_VERSION); - thread_create_detach(sighandler, NULL); - thread_create_detach_prio(poller_timer_loop, rtpe_poller, rtpe_config.idle_scheduling, rtpe_config.idle_priority); - thread_create_detach_prio(load_thread, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority); + thread_create_detach(sighandler, NULL, "signal handler"); + thread_create_detach_prio(poller_timer_loop, rtpe_poller, rtpe_config.idle_scheduling, + rtpe_config.idle_priority, "poller timer"); + thread_create_detach_prio(load_thread, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "load monitor"); if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) - thread_create_detach(redis_delete_async_loop, NULL); + thread_create_detach(redis_delete_async_loop, NULL, "redis async"); if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify) - thread_create_detach(redis_notify_loop, NULL); + thread_create_detach(redis_notify_loop, NULL, "redis notify"); if (!is_addr_unspecified(&rtpe_config.graphite_ep.address)) - thread_create_detach(graphite_loop, NULL); + thread_create_detach(graphite_loop, NULL, "graphite"); - thread_create_detach(ice_thread_run, NULL); + thread_create_detach(ice_thread_run, NULL, "ICE"); websocket_start(); service_notify("READY=1\n"); for (idx = 0; idx < rtpe_config.num_threads; ++idx) - thread_create_detach_prio(poller_loop, rtpe_poller, rtpe_config.scheduling, rtpe_config.priority); + thread_create_detach_prio(poller_loop, rtpe_poller, rtpe_config.scheduling, + rtpe_config.priority, "poller"); if (rtpe_config.media_num_threads < 0) rtpe_config.media_num_threads = rtpe_config.num_threads; for (idx = 0; idx < rtpe_config.media_num_threads; ++idx) { #ifdef WITH_TRANSCODING - thread_create_detach_prio(media_player_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); + thread_create_detach_prio(media_player_loop, NULL, rtpe_config.scheduling, + rtpe_config.priority, "media player"); #endif - thread_create_detach_prio(send_timer_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); + thread_create_detach_prio(send_timer_loop, NULL, rtpe_config.scheduling, + rtpe_config.priority, "send timer"); if (rtpe_config.jb_length > 0) thread_create_detach_prio(jitter_buffer_loop, NULL, rtpe_config.scheduling, - rtpe_config.priority); - thread_create_detach_prio(codec_timers_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); + rtpe_config.priority, "jitter buffer"); + thread_create_detach_prio(codec_timers_loop, NULL, rtpe_config.scheduling, + rtpe_config.priority, "codec timer"); } diff --git a/daemon/websocket.c b/daemon/websocket.c index 9da00efa8..24e726764 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -953,5 +953,5 @@ static void websocket_loop(void *p) { void websocket_start(void) { if (!websocket_context) return; - thread_create_detach_prio(websocket_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); + thread_create_detach_prio(websocket_loop, NULL, rtpe_config.scheduling, rtpe_config.priority, "websocket"); } diff --git a/include/aux.h b/include/aux.h index 0c9b7f1d9..56ed518de 100644 --- a/include/aux.h +++ b/include/aux.h @@ -278,9 +278,9 @@ taint_func(srandom, "use RAND_seed() instead"); /*** THREAD HELPERS ***/ void threads_join_all(int); -void thread_create_detach_prio(void (*)(void *), void *, const char *, int); -INLINE void thread_create_detach(void (*f)(void *), void *a) { - thread_create_detach_prio(f, a, NULL, 0); +void thread_create_detach_prio(void (*)(void *), void *, const char *, int, const char *); +INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) { + thread_create_detach_prio(f, a, NULL, 0, name); }