[lttng-dev] [PATCH] Set appropriate thread names for processes loading UST lib
André Goddard Rosa
andre.rosa at lge.com
Sun Mar 1 22:18:08 EST 2015
When a process loads the UST library, its threads are not named appropriately.
Set appropriate individual threads names so that it becomes easier to
distinguish between UST threads from those coming from the process itself.
It makes for easier understanding of profiling data (CTF on trace compass
or perf data) where cycles are accounted to individual threads, allowing
to distinguish the work accomplished by different threads.
Not tested on __FreeBSD__ environment. Could somebody confirm?
Signed-off-by: André Goddard Rosa <andre.goddard at gmail.com>
diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h
index 43b2223..657703e 100644
--- a/liblttng-ust/compat.h
+++ b/liblttng-ust/compat.h
@@ -20,7 +20,7 @@
*/
/*
- * lttng_ust_getprocname.
+ * lttng_ust_getprocname, lttng_ust_setprocname.
*/
#ifdef __linux__
@@ -34,9 +34,16 @@ void lttng_ust_getprocname(char *name)
(void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0);
}
+static inline
+void lttng_ust_setprocname(char *name)
+{
+ (void) prctl(PR_SET_NAME, (unsigned long) name, 0, 0, 0);
+}
+
#elif defined(__FreeBSD__)
#include <stdlib.h>
#include <string.h>
+#include <pthread.h>
/*
* Limit imposed by Linux UST-sessiond ABI.
@@ -59,6 +66,12 @@ void lttng_ust_getprocname(char *name)
strncpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1);
}
+static inline
+void lttng_ust_setprocname(char *name)
+{
+ (void) pthread_set_name_np(pthread_self(), name);
+}
+
#endif
#include <errno.h>
diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index 378ca21..256752b 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -1173,6 +1173,8 @@ void *ust_listener_thread(void *arg)
int sock, ret, prev_connect_failed = 0, has_waited = 0;
long timeout;
+ lttng_ust_setprocname("UST Listener");
+
/* Restart trying to connect to the session daemon */
restart:
if (prev_connect_failed) {
diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c
index aeb7f7d..675abb6 100644
--- a/libringbuffer/ring_buffer_frontend.c
+++ b/libringbuffer/ring_buffer_frontend.c
@@ -398,6 +398,8 @@ void *sig_thread(void *arg)
siginfo_t info;
int signr;
+ lttng_ust_setprocname("UST Sig");
+
/* Only self thread will receive signal mask. */
rb_setmask(&mask);
CMM_STORE_SHARED(timer_signal.tid, pthread_self());
--
2.3.0.149.gf3f4077.dirty
More information about the lttng-dev
mailing list