* [lttng-dev] [RFC PATCH 0/2] Identify UST threads by changing thread names
@ 2016-04-21 20:50 Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 1/2] Add -ust to the name of UST threads of the application Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 2/2] " Raphaël Beamonte
0 siblings, 2 replies; 3+ messages in thread
From: Raphaël Beamonte @ 2016-04-21 20:50 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1733 bytes --]
Hi,
This is an RFC patch for comments and ideas about how this should be
done. In recent work I've been doing, I found out that some UST-
instrumented userspace process was preempting itself. Looking further,
it was not the same TID, but the same process name. These processes
were LTTng-UST listener threads, but were not identified as so.
Adding a simple symbol, such as "-ust" or "-lttng" at the end of the
process name would help to identify such process directly in the
generated trace.
You'll find below two different implementations with their pros
and cons, for which the "-ust" symbol was choosen:
1/ An implementation using prctl
It works properly on Linux, but I didn't find a way to make
it work under FreeBSD, hence the empty function in FreeBSD
case (keeping the situation as it is now).
Raphaël Beamonte (1):
Add -ust to the name of UST threads of the application
liblttng-ust/compat.h | 22 ++++++++++++++++++++++
liblttng-ust/lttng-ust-comm.c | 2 ++
2 files changed, 24 insertions(+)
2/ An implementation using pthread
It works on both Linux and FreeBSD, but requires to add a
link to the pthread library in liblttng-ust Makefile.am.
Also, this approach relies on the presence of the
pthread_setname_np function, which was included in glibc
2.12, meaning it will not work with older versions (but
this should not be a problem?)
Raphaël Beamonte (1):
Add -ust to the name of UST threads of the application
liblttng-ust/Makefile.am | 1 +
liblttng-ust/compat.h | 35 +++++++++++++++++++++++++++++++++++
liblttng-ust/lttng-ust-comm.c | 2 ++
3 files changed, 38 insertions(+)
I'll wait for your comments and ideas on that subject.
Thanks,
Raphaël
--
2.1.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* [lttng-dev] [RFC PATCH 1/2] Add -ust to the name of UST threads of the application
2016-04-21 20:50 [lttng-dev] [RFC PATCH 0/2] Identify UST threads by changing thread names Raphaël Beamonte
@ 2016-04-21 20:50 ` Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 2/2] " Raphaël Beamonte
1 sibling, 0 replies; 3+ messages in thread
From: Raphaël Beamonte @ 2016-04-21 20:50 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1704 bytes --]
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>
---
liblttng-ust/compat.h | 22 ++++++++++++++++++++++
liblttng-ust/lttng-ust-comm.c | 2 ++
2 files changed, 24 insertions(+)
diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h
index 43b2223..8d5fc77 100644
--- a/liblttng-ust/compat.h
+++ b/liblttng-ust/compat.h
@@ -34,6 +34,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");
+
+ (void) prctl(PR_SET_NAME, name, 0, 0, 0);
+}
+
#elif defined(__FreeBSD__)
#include <stdlib.h>
#include <string.h>
@@ -59,6 +76,11 @@ void lttng_ust_getprocname(char *name)
strncpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1);
}
+static inline
+void lttng_ust_setustprocname()
+{
+}
+
#endif
#include <errno.h>
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
^ permalink raw reply [flat|nested] 3+ messages in thread* [lttng-dev] [RFC PATCH 2/2] Add -ust to the name of UST threads of the application
2016-04-21 20:50 [lttng-dev] [RFC PATCH 0/2] Identify UST threads by changing thread names Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 1/2] Add -ust to the name of UST threads of the application Raphaël Beamonte
@ 2016-04-21 20:50 ` Raphaël Beamonte
1 sibling, 0 replies; 3+ messages in thread
From: Raphaël Beamonte @ 2016-04-21 20:50 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2669 bytes --]
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>
---
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 <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>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-21 20:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-21 20:50 [lttng-dev] [RFC PATCH 0/2] Identify UST threads by changing thread names Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 1/2] Add -ust to the name of UST threads of the application Raphaël Beamonte
2016-04-21 20:50 ` [lttng-dev] [RFC PATCH 2/2] " Raphaël Beamonte
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox