From mboxrd@z Thu Jan 1 00:00:00 1970 From: raphael.beamonte@gmail.com (=?UTF-8?q?Rapha=C3=ABl=20Beamonte?=) Date: Thu, 21 Apr 2016 16:50:33 -0400 Subject: [lttng-dev] [RFC PATCH 2/2] Add -ust to the name of UST threads of the application In-Reply-To: References: Message-ID: <31c78bb664fbaaa71225802d0b07cd89983e2e5f.1461270048.git.raphael.beamonte@gmail.com> Add the required functions to change the thread name of the UST threads and add the -ust string at its end. This will help to identify LTTng-UST processes when analyzing the trace of a process. Signed-off-by: Raphaƫl Beamonte --- liblttng-ust/Makefile.am | 1 + liblttng-ust/compat.h | 35 +++++++++++++++++++++++++++++++++++ liblttng-ust/lttng-ust-comm.c | 2 ++ 3 files changed, 38 insertions(+) diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index 876e9b5..8d78d63 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -13,6 +13,7 @@ liblttng_ust_tracepoint_la_SOURCES = \ error.h liblttng_ust_tracepoint_la_LIBADD = \ -lurcu-bp \ + -lpthread \ $(top_builddir)/snprintf/libustsnprintf.la liblttng_ust_tracepoint_la_LDFLAGS = -no-undefined -version-info $(LTTNG_UST_LIBRARY_VERSION) liblttng_ust_tracepoint_la_CFLAGS = -DUST_COMPONENT="liblttng_ust_tracepoint" -fno-strict-aliasing diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h index 43b2223..161b957 100644 --- a/liblttng-ust/compat.h +++ b/liblttng-ust/compat.h @@ -24,6 +24,7 @@ */ #ifdef __linux__ +#include #include #define LTTNG_UST_PROCNAME_LEN 17 @@ -34,6 +35,23 @@ void lttng_ust_getprocname(char *name) (void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0); } +static inline +void lttng_ust_setustprocname() +{ + char name[LTTNG_UST_PROCNAME_LEN]; + int limit = LTTNG_UST_PROCNAME_LEN - 4; + + lttng_ust_getprocname(name); + + if (strlen(name) >= limit) { + name[limit] = 0; + } + + sprintf(name, "%s%s", name, "-ust"); + + pthread_setname_np(pthread_self(), name); +} + #elif defined(__FreeBSD__) #include #include @@ -59,6 +77,23 @@ void lttng_ust_getprocname(char *name) strncpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1); } +static inline +void lttng_ust_setustprocname() +{ + char name[LTTNG_UST_PROCNAME_LEN]; + int limit = LTTNG_UST_PROCNAME_LEN - 4; + + lttng_ust_getprocname(name); + + if (strlen(name) >= limit) { + name[limit] = 0; + } + + sprintf(name, "%s%s", name, "-ust"); + + pthread_set_name_np(pthread_self(), name); +} + #endif #include diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index e00a22c..a85cb21 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -1295,6 +1295,8 @@ void *ust_listener_thread(void *arg) int sock, ret, prev_connect_failed = 0, has_waited = 0; long timeout; + lttng_ust_setustprocname(); + /* Restart trying to connect to the session daemon */ restart: if (prev_connect_failed) { -- 2.1.4