diff options
author | Markos Fountoulakis <44345837+mfundul@users.noreply.github.com> | 2020-06-20 22:13:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-20 22:13:22 +0300 |
commit | 431b1c85698feb33aee2e8cf972dcdf6fb26ba46 (patch) | |
tree | d4c81546538649529e7a303dbaf2134cde2d9996 /libnetdata/threads | |
parent | ae944cd492ceeec4a466c2e976fbeea0fb18bc66 (diff) |
Add libuv thread names support to FATAL log level (#9382)
* Add support for the fatal() family of calls to detect non-netdata thread names from the OS
Diffstat (limited to 'libnetdata/threads')
-rw-r--r-- | libnetdata/threads/threads.c | 18 | ||||
-rw-r--r-- | libnetdata/threads/threads.h | 2 |
2 files changed, 19 insertions, 1 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c index 92e1678717..8a2e292439 100644 --- a/libnetdata/threads/threads.c +++ b/libnetdata/threads/threads.c @@ -18,8 +18,12 @@ typedef struct { static __thread NETDATA_THREAD *netdata_thread = NULL; +inline int netdata_thread_tag_exists(void) { + return (netdata_thread && netdata_thread->tag && *netdata_thread->tag); +} + const char *netdata_thread_tag(void) { - return ((netdata_thread && netdata_thread->tag && *netdata_thread->tag)?netdata_thread->tag:"MAIN"); + return (netdata_thread_tag_exists() ? netdata_thread->tag : "MAIN"); } // ---------------------------------------------------------------------------- @@ -151,6 +155,18 @@ void uv_thread_set_name_np(uv_thread_t ut, const char* name) { info("cannot set libuv thread name to %s. Err: %d", threadname, ret); } +void os_thread_get_current_name_np(char threadname[NETDATA_THREAD_NAME_MAX + 1]) +{ + int ret = 0; + + threadname[0] = '\0'; +#if defined(__FreeBSD__) + pthread_get_name_np(pthread_self(), threadname, NETDATA_THREAD_NAME_MAX + 1); +#elif defined(HAVE_PTHREAD_GETNAME_NP) /* Linux & macOS */ + (void)pthread_getname_np(pthread_self(), threadname, NETDATA_THREAD_NAME_MAX + 1); +#endif +} + static void *thread_start(void *ptr) { netdata_thread = (NETDATA_THREAD *)ptr; diff --git a/libnetdata/threads/threads.h b/libnetdata/threads/threads.h index b7cb0e15a0..e7d79d3283 100644 --- a/libnetdata/threads/threads.h +++ b/libnetdata/threads/threads.h @@ -22,6 +22,7 @@ typedef pthread_t netdata_thread_t; #define NETDATA_THREAD_TAG_MAX 100 extern const char *netdata_thread_tag(void); +extern int netdata_thread_tag_exists(void); extern size_t netdata_threads_init(void); extern void netdata_threads_init_after_fork(size_t stacksize); @@ -33,6 +34,7 @@ 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); +extern void os_thread_get_current_name_np(char threadname[NETDATA_THREAD_NAME_MAX + 1]); #define netdata_thread_self pthread_self #define netdata_thread_testcancel pthread_testcancel |