diff options
author | Adrien Mahieux <adrien.mahieux@gmail.com> | 2019-12-20 13:31:25 +0100 |
---|---|---|
committer | Vladimir Kobal <vlad@prokk.net> | 2019-12-20 14:31:25 +0200 |
commit | c0e1f63f4da29a03cd3b214834e90b9cc043717a (patch) | |
tree | f41f161453612fd76d4e144d8f57037e11021b67 /libnetdata/threads | |
parent | d0e424144749a9748c5de4f0888d8e8ec5647b78 (diff) |
Set standard name to non-libnetdata threads (libuv, pthread) (#7584)
* [libnetdata/threads] Add uv_thread_set_name
This is inspired from thread_set_name() but for libuv threads.
Both are based on pthread, but for uv we need to call it with the
uv_thread_t pointer, instead of being the thread that calls the
function for itself.
* [exporting] Set libuv threadname to "EXPORTING-index"
* [database/engine] Set libuv thread name to "DBENGINE"
* [daemon/command] Set libuv thread name to "DAEMON-COMMAND"
* [collectors/proc] Set pthread name to "PLUGIN[cpuidle]"
* Use new 'thread_set_name_np' name
Diffstat (limited to 'libnetdata/threads')
-rw-r--r-- | libnetdata/threads/threads.c | 27 | ||||
-rw-r--r-- | libnetdata/threads/threads.h | 3 |
2 files changed, 25 insertions, 5 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c index 3b3f30415b..c310d528bc 100644 --- a/libnetdata/threads/threads.c +++ b/libnetdata/threads/threads.c @@ -109,14 +109,13 @@ static void thread_cleanup(void *ptr) { netdata_thread = NULL; } -static void thread_set_name(NETDATA_THREAD *nt) { +static void thread_set_name_np(NETDATA_THREAD *nt) { if (nt->tag) { int ret = 0; - // Name is limited to 16 chars - char threadname[16]; - strncpyz(threadname, nt->tag, 15); + char threadname[NETDATA_THREAD_NAME_MAX+1]; + strncpyz(threadname, nt->tag, NETDATA_THREAD_NAME_MAX); #if defined(__FreeBSD__) pthread_set_name_np(pthread_self(), threadname); @@ -134,6 +133,24 @@ static void thread_set_name(NETDATA_THREAD *nt) { } } +void uv_thread_set_name_np(uv_thread_t ut, const char* name) { + int ret = 0; + + char threadname[NETDATA_THREAD_NAME_MAX+1]; + strncpyz(threadname, name, NETDATA_THREAD_NAME_MAX); + +#if defined(__FreeBSD__) + pthread_set_name_np(ut, threadname); +#elif defined(__APPLE__) + // Apple can only set its own name +#else + ret = pthread_setname_np(ut, threadname); +#endif + + if (ret) + error("cannot set libuv thread name to %s. Err: %d", threadname, ret); +} + static void *thread_start(void *ptr) { netdata_thread = (NETDATA_THREAD *)ptr; @@ -146,7 +163,7 @@ static void *thread_start(void *ptr) { if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) error("cannot set pthread cancel state to ENABLE."); - thread_set_name(ptr); + thread_set_name_np(ptr); void *ret = NULL; pthread_cleanup_push(thread_cleanup, ptr); diff --git a/libnetdata/threads/threads.h b/libnetdata/threads/threads.h index eec6ad0e31..b7cb0e15a0 100644 --- a/libnetdata/threads/threads.h +++ b/libnetdata/threads/threads.h @@ -31,6 +31,9 @@ extern int netdata_thread_cancel(netdata_thread_t thread); extern int netdata_thread_join(netdata_thread_t thread, void **retval); extern int netdata_thread_detach(pthread_t thread); +#define NETDATA_THREAD_NAME_MAX 15 +extern void uv_thread_set_name_np(uv_thread_t ut, const char* name); + #define netdata_thread_self pthread_self #define netdata_thread_testcancel pthread_testcancel |