summaryrefslogtreecommitdiffstats
path: root/libnetdata/threads
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-04-20 20:49:06 +0300
committerGitHub <noreply@github.com>2023-04-20 20:49:06 +0300
commitc3d70ffcb43b62c95d71334ed49ad345ddf4360d (patch)
tree1f6645b504eae7801c8867d3af4d614135aa7602 /libnetdata/threads
parent5b676d5f912fc27a126ff4ff6ba5b35da9cf930c (diff)
WEBRTC for communication between agents and browsers (#14874)
* initial webrtc setup * missing files * rewrite of webrtc integration * initialization and cleanup of webrtc connections * make it compile without libdatachannel * add missing webrtc_initialize() function when webrtc is not enabled * make c++17 optional * add build/m4/ax_compiler_vendor.m4 * add ax_cxx_compile_stdcxx.m4 * added new m4 files to makefile.am * id all webrtc connections * show warning when webrtc is disabled * fixed message * moved all webrtc error checking inside webrtc.cpp * working webrtc connection establishment and cleanup * remove obsolete code * rewrote webrtc code in C to remove dependency for c++17 * fixed left-over reference * detect binary and text messages * minor fix * naming of webrtc threads * added webrtc configuration * fix for thread_get_name_np() * smaller web_client memory footprint * universal web clients cache * free web clients every 100 uses * webrtc is now enabled by default only when compiled with internal checks * webrtc responses to /api/ requests, including LZ4 compression * fix for binary and text messages * web_client_cache is now global * unification of the internal web server API, for web requests, aclk request, webrtc requests * more cleanup and unification of web client timings * fixed compiler warnings * update sent and received bytes * eliminated of almost all big buffers in web client * registry now uses the new json generation * cookies are now an array; fixed redirects * fix redirects, again * write cookies directly to the header buffer, eliminating the need for cookie structures in web client * reset the has_cookies flag * gathered all web client cleanup to one function * fixes redirects * added summary.globals in /api/v2/data response * ars to arc in /api/v2/data * properly handle host impersonation * set the context of mem.numa_nodes
Diffstat (limited to 'libnetdata/threads')
-rw-r--r--libnetdata/threads/threads.c59
-rw-r--r--libnetdata/threads/threads.h2
2 files changed, 60 insertions, 1 deletions
diff --git a/libnetdata/threads/threads.c b/libnetdata/threads/threads.c
index 16de45fd14..c4026a7331 100644
--- a/libnetdata/threads/threads.c
+++ b/libnetdata/threads/threads.c
@@ -21,8 +21,63 @@ inline int netdata_thread_tag_exists(void) {
return (netdata_thread && netdata_thread->tag && *netdata_thread->tag);
}
+static const char *thread_name_get(bool recheck) {
+ static __thread char threadname[NETDATA_THREAD_NAME_MAX + 1] = "";
+
+ if(netdata_thread_tag_exists())
+ strncpyz(threadname, netdata_thread->tag, NETDATA_THREAD_NAME_MAX + 1);
+ else {
+ if(!recheck && threadname[0])
+ return threadname;
+
+#if defined(__FreeBSD__)
+ pthread_get_name_np(pthread_self(), threadname, NETDATA_THREAD_NAME_MAX + 1);
+ if(strcmp(threadname, "netdata") == 0)
+ strncpyz(threadname, "MAIN", NETDATA_THREAD_NAME_MAX + 1);
+#elif defined(__APPLE__)
+ strncpyz(threadname, "MAIN", NETDATA_THREAD_NAME_MAX + 1);
+#elif defined(HAVE_PTHREAD_GETNAME_NP)
+ pthread_getname_np(pthread_self(), threadname, NETDATA_THREAD_NAME_MAX + 1);
+ if(strcmp(threadname, "netdata") == 0)
+ strncpyz(threadname, "MAIN", NETDATA_THREAD_NAME_MAX + 1);
+#else
+ strncpyz(threadname, "MAIN", NETDATA_THREAD_NAME_MAX + 1);
+#endif
+ }
+
+ return threadname;
+}
+
const char *netdata_thread_tag(void) {
- return (netdata_thread_tag_exists() ? netdata_thread->tag : "MAIN");
+ return thread_name_get(false);
+}
+
+static size_t webrtc_id = 0;
+static __thread bool webrtc_name_set = false;
+void webrtc_set_thread_name(void) {
+ if(!netdata_thread && !webrtc_name_set) {
+ webrtc_name_set = true;
+ char threadname[NETDATA_THREAD_NAME_MAX + 1];
+
+#if defined(__FreeBSD__)
+ snprintfz(threadname, NETDATA_THREAD_NAME_MAX, "WEBRTC[%zu]", __atomic_fetch_add(&webrtc_id, 1, __ATOMIC_RELAXED));
+ pthread_set_name_np(pthread_self(), threadname);
+#elif defined(__APPLE__)
+ snprintfz(threadname, NETDATA_THREAD_NAME_MAX, "WEBRTC[%zu]", __atomic_fetch_add(&webrtc_id, 1, __ATOMIC_RELAXED));
+ pthread_setname_np(threadname);
+#elif defined(HAVE_PTHREAD_GETNAME_NP)
+ pthread_getname_np(pthread_self(), threadname, NETDATA_THREAD_NAME_MAX+1);
+ if(strcmp(threadname, "netdata") == 0) {
+ snprintfz(threadname, NETDATA_THREAD_NAME_MAX, "WEBRTC[%zu]", __atomic_fetch_add(&webrtc_id, 1, __ATOMIC_RELAXED));
+ pthread_setname_np(pthread_self(), threadname);
+ }
+#else
+ snprintfz(threadname, NETDATA_THREAD_NAME_MAX, "WEBRTC[%zu]", __atomic_fetch_add(&webrtc_id, 1, __ATOMIC_RELAXED));
+ pthread_setname_np(pthread_self(), threadname);
+#endif
+
+ thread_name_get(true);
+ }
}
// ----------------------------------------------------------------------------
@@ -173,6 +228,8 @@ void uv_thread_set_name_np(uv_thread_t ut, const char* name) {
ret = pthread_setname_np(ut, threadname);
#endif
+ thread_name_get(true);
+
if (ret)
info("cannot set libuv thread name to %s. Err: %d", threadname, ret);
}
diff --git a/libnetdata/threads/threads.h b/libnetdata/threads/threads.h
index ccc18aff0a..ad31b88161 100644
--- a/libnetdata/threads/threads.h
+++ b/libnetdata/threads/threads.h
@@ -43,6 +43,8 @@ int netdata_thread_detach(pthread_t thread);
void uv_thread_set_name_np(uv_thread_t ut, const char* name);
void os_thread_get_current_name_np(char threadname[NETDATA_THREAD_NAME_MAX + 1]);
+void webrtc_set_thread_name(void);
+
#define netdata_thread_self pthread_self
#define netdata_thread_testcancel pthread_testcancel