Skip to contentSkip to conversation

Add -ust to the name of UST threads of the application

RFC PATCH Sebastien Boisvert 2 participants 2 messages Jun 2, 2016 – Jun 3, 2016 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 101 lines

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 <raphael.beamonte at gmail.com <https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev>>
---
 liblttng-ust/Makefile.am      |  1 +
 liblttng-ust/compat.h         | 35 +++++++++++++++++++++++++++++++++++
 liblttng-ust/lttng-ust-comm.c |  2 ++
 3 files changed, 38 insertions(+)
liblttng-ust/Makefile.am +1 -0
index 876e9b5..8d78d63 100644
@@ -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
liblttng-ust/compat.h +35 -0
index 43b2223..161b957 100644
@@ -24,6 +24,7 @@
  */
 #ifdef __linux__
 
+#include <pthread.h>
 #include <sys/prctl.h>
 
 #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 <stdlib.h>
 #include <string.h>
@@ -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 <errno.h>
liblttng-ust/lttng-ust-comm.c +2 -0
index e00a22c..a85cb21 100644
@@ -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) {
Signature · 1 line
2.1.4

Hi Raphaël,

Since the only difference between the Linux hunk and the FreeBSD hunk is *one* line, you should simplify this patch.

Z1$ diff -u linux-hunk freebsd-hunk

freebsd-hunk renamed from linux-hunk +1 -1
@@ -12,6 +12,6 @@
 +
 +	sprintf(name, "%s%s", name, "-ust");
 +
-+	pthread_setname_np(pthread_self(), name);
++	pthread_set_name_np(pthread_self(), name);
 +}
 +
\ No newline at end of file

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

2016-06-02 9:06 GMT-04:00 Sebastien Boisvert <[email protected]>:

Quoted 112 lines
Quoted 99 lines

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 <raphael.beamonte at gmail.com <https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev>>
---
 liblttng-ust/Makefile.am      |  1 +
 liblttng-ust/compat.h         | 35 +++++++++++++++++++++++++++++++++++
 liblttng-ust/lttng-ust-comm.c |  2 ++
 3 files changed, 38 insertions(+)
liblttng-ust/Makefile.am +1 -0
index 876e9b5..8d78d63 100644
@@ -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
liblttng-ust/compat.h +35 -0
index 43b2223..161b957 100644
@@ -24,6 +24,7 @@
  */
 #ifdef __linux__
 
+#include <pthread.h>
 #include <sys/prctl.h>
 
 #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 <stdlib.h>
 #include <string.h>
@@ -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 <errno.h>
liblttng-ust/lttng-ust-comm.c +2 -1
index e00a22c..a85cb21 100644
@@ -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) {
--
Quoted 2 lines

2.1.4

Hi Raphaël,

Since the only difference between the Linux hunk and the FreeBSD hunk is *one* line, you should simplify this patch.

Z1$ diff -u linux-hunk freebsd-hunk

freebsd-hunk 2016-06-02 09:02:38.863865110 -0400 line 17

Quoted 8 lines
freebsd-hunk 2016-06-02 09:02:38.863865110 -0400 renamed from linux-hunk 2016-06-02 09:02:14.790865459 -0400 +1 -1
@@ -12,6 +12,6 @@
 +
 +      sprintf(name, "%s%s", name, "-ust");
 +
-+      pthread_setname_np(pthread_self(), name);
++      pthread_set_name_np(pthread_self(), name);
 +}
 +
\ No newline at end of file

Hi Sebastien,

Right. Should have used a define! Will do.

Raphaël
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev