Fix: ustcomm: application name uses the '-ust'-suffixed thread name
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 14 May 2021 23:13:32 +0000 (19:13 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 15 May 2021 01:28:31 +0000 (21:28 -0400)
During the 2.13 development cycle, the compatibility pthread_setname_np
compatibility layer was fixed (see 0db3d6ee). Unfortunately, this had a
detrimental effect.

Upon the registration of an application to the session daemon, its name
is sent as part of the 'struct lttng_ust_ctl_reg_msg' registration
message. The application name is sampled using lttng_pthread_getname_np
during the preparation of the message.

However, when the listener thread is launched, its name is changed
early-on to add a '-ust' suffix (see 01f0e40c). This suffixed name is
sampled and sent to the session daemon. Since, until recently, the
pthread_setname_np had no effect on most configurations, this had no
consequence.

I noticed that this has a ripple-effect in the generation of some
path names. For instance, in per-pid mode, snapshots end-up with the
following hierarchy:

/home/jgalar/lttng-traces
└── Mercury
    └── florence_jacques-20210514-162630
        └── snapshot-0-20210514-162726-1
            └── ust
                └── pid
                    └── hello-ust-332607-20210514-162538
                        ├── lol_0
                        ├── lol_1
                        ├── lol_10
                        ├── lol_11
                        ├── lol_2
                        ├── lol_3
                        ├── lol_4
                        ├── lol_5
                        ├── lol_6
                        ├── lol_7
                        ├── lol_8
                        ├── lol_9
                        └── metadata

Notice how the 'hello' application presents itself with the '-ust'
prefix. For such a short application name, it doesn't really matter
much beyond repeating the 'ust' unnecessarily. However, longer
application names quickly become less readable as we lose four of
the 16 precious allowed characters for a process name.

The procname sampled during the execution of the constructors is
reused. My understanding is that the procname stored in the sock_info
is already used for the 'procname' context.

The resulting hierarchy becomes:

/home/jgalar/lttng-traces
└── Mercury
    └── sylvie_rouillard-20210514-193524
        └── snapshot-0-20210514-193553-0
            └── ust
                └── pid
                    └── hello-466576-20210514-193514
                        ├── lol_0
                        ├── lol_1
                        ├── lol_10
                        ├── lol_11
                        ├── lol_2
                        ├── lol_3
                        ├── lol_4
                        ├── lol_5
                        ├── lol_6
                        ├── lol_7
                        ├── lol_8
                        ├── lol_9
                        └── metadata

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ibd6f4763c96ea5fb680f55e5cc3d250baca175b0

src/common/ustcomm.c
src/common/ustcomm.h
src/lib/lttng-ust/lttng-ust-comm.c

index 6e6b8f3e564e8a5823a98d16b382f44fa0a1bf53..319e84ac923530d790de9afd22ba595849399e31 100644 (file)
@@ -803,7 +803,8 @@ int ustcomm_send_reg_msg(int sock,
                uint32_t uint16_t_alignment,
                uint32_t uint32_t_alignment,
                uint32_t uint64_t_alignment,
-               uint32_t long_alignment)
+               uint32_t long_alignment,
+               const char *procname)
 {
        ssize_t len;
        struct lttng_ust_ctl_reg_msg reg_msg;
@@ -822,7 +823,8 @@ int ustcomm_send_reg_msg(int sock,
        reg_msg.uint64_t_alignment = uint64_t_alignment;
        reg_msg.long_alignment = long_alignment;
        reg_msg.socket_type = type;
-       lttng_pthread_getname_np(reg_msg.name, LTTNG_UST_ABI_PROCNAME_LEN);
+       memset(reg_msg.name, 0, sizeof(reg_msg.name));
+       strncpy(reg_msg.name, procname, sizeof(reg_msg.name) - 1);
        memset(reg_msg.padding, 0, sizeof(reg_msg.padding));
 
        len = ustcomm_send_unix_sock(sock, &reg_msg, sizeof(reg_msg));
index 99a3abc19813130bed4090d6c3a222b2935efe4e..734757c3a65acfde66072152119adee4e364775f 100644 (file)
@@ -275,7 +275,8 @@ int ustcomm_send_reg_msg(int sock,
                uint32_t uint16_t_alignment,
                uint32_t uint32_t_alignment,
                uint32_t uint64_t_alignment,
-               uint32_t long_alignment)
+               uint32_t long_alignment,
+               const char *procname)
        __attribute__((visibility("hidden")));
 
 /*
index f180c3bc8277874ddd673954b1e3bf8467b7e95a..2c902dc2737e922204628293e806306fa08e174a 100644 (file)
@@ -620,7 +620,8 @@ void get_allow_blocking(void)
 }
 
 static
-int register_to_sessiond(int socket, enum lttng_ust_ctl_socket_type type)
+int register_to_sessiond(int socket, enum lttng_ust_ctl_socket_type type,
+               const char *procname)
 {
        return ustcomm_send_reg_msg(socket,
                type,
@@ -629,7 +630,8 @@ int register_to_sessiond(int socket, enum lttng_ust_ctl_socket_type type)
                lttng_ust_rb_alignof(uint16_t) * CHAR_BIT,
                lttng_ust_rb_alignof(uint32_t) * CHAR_BIT,
                lttng_ust_rb_alignof(uint64_t) * CHAR_BIT,
-               lttng_ust_rb_alignof(unsigned long) * CHAR_BIT);
+               lttng_ust_rb_alignof(unsigned long) * CHAR_BIT,
+               procname);
 }
 
 static
@@ -1911,7 +1913,8 @@ restart:
                sock_info->root_handle = ret;
        }
 
-       ret = register_to_sessiond(sock_info->socket, LTTNG_UST_CTL_SOCKET_CMD);
+       ret = register_to_sessiond(sock_info->socket, LTTNG_UST_CTL_SOCKET_CMD,
+               sock_info->procname);
        if (ret < 0) {
                ERR("Error registering to %s ust cmd socket",
                        sock_info->name);
@@ -2004,7 +2007,7 @@ restart:
        }
 
        ret = register_to_sessiond(sock_info->notify_socket,
-                       LTTNG_UST_CTL_SOCKET_NOTIFY);
+                       LTTNG_UST_CTL_SOCKET_NOTIFY, sock_info->procname);
        if (ret < 0) {
                ERR("Error registering to %s ust notify socket",
                        sock_info->name);
This page took 0.028185 seconds and 4 git commands to generate.