Add procname to lttng_ust_statedump information
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 28 Jun 2019 21:28:15 +0000 (17:28 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 1 Nov 2019 20:43:43 +0000 (16:43 -0400)
Adding the process procname to the statedump allows users to disable
procname context in scenario for which the data and serialization overhead
of the procname process is problematic. Users can stitch information in
post-processing based on other contexts (pid).

Users can skip this statedump via the
LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP env variable.

Note that the procname statedump value is the procname seen at
application start (lttng_ust_init). Subsequent calls to pthread_setname_np
or equivalent have no effect on this value.

Since we cannot use the current thread name due to the
lttng_pthread_setname_np call in ust_listener_thread, we store the
process name inside the sock_info struct before the call to
lttng_pthread_setname_np. This data structure is already present as the
"owner" object in the statedump mechanism. During the statedump, we fetch
the procname from the "owner" object.

Use LTTNG_HIDDEN to reduce visibility of lttng_ust_sockinfo_get_procname.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
doc/man/lttng-ust.3.txt
include/helper.h
liblttng-ust/lttng-tracer-core.h
liblttng-ust/lttng-ust-comm.c
liblttng-ust/lttng-ust-statedump-provider.h
liblttng-ust/lttng-ust-statedump.c

index 2534612a7ecb9ea4d866ea237f80d2437665cb9a..507aaca5e0ac070328eff4cdee587f1181240015 100644 (file)
@@ -952,6 +952,20 @@ Fields:
 |Debug link file name.
 |===
 
+`lttng_ust_statedump:procname`::
+    The process procname at process start.
++
+Fields:
++
+[options="header"]
+|===
+|Field name |Description
+
+|`procname`
+|The process name.
+
+|===
+
 
 [[ust-lib]]
 Shared library load/unload tracking
@@ -1395,6 +1409,10 @@ Default: {lttng_ust_register_timeout}.
     If set, prevents `liblttng-ust` from performing a base address state
     dump (see the <<state-dump,LTTng-UST state dump>> section above).
 
+`LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP`::
+    If set, prevents `liblttng-ust` from performing a procname state
+    dump (see the <<state-dump,LTTng-UST state dump>> section above).
+
 
 include::common-footer.txt[]
 
index 9873feadd85b020556c1cd1e4f45925094b1fdd1..a187b0e7327b2af0f3d39f1160182ad514317303 100644 (file)
@@ -55,4 +55,15 @@ void *zmalloc(size_t len)
 #define LTTNG_UST_CALLER_IP()          __builtin_return_address(0)
 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
 
+/*
+ * LTTNG_HIDDEN: set the hidden attribute for internal functions
+ * On Windows, symbols are local unless explicitly exported,
+ * see https://gcc.gnu.org/wiki/Visibility
+ */
+#if defined(_WIN32) || defined(__CYGWIN__)
+#define LTTNG_HIDDEN
+#else
+#define LTTNG_HIDDEN __attribute__((visibility("hidden")))
+#endif
+
 #endif /* _LTTNG_UST_HELPER_H */
index 52315a8de001227fecd02ae50749581b9a16edf9..bd837237590201f89b2fcd3eaa6363964037e1c1 100644 (file)
@@ -29,6 +29,7 @@
 #include <lttng/bug.h>
 #include <lttng/ringbuffer-config.h>
 #include <usterr-signal-safe.h>
+#include <helper.h>
 
 /*
  * The longuest possible namespace proc path is with the cgroup ns
@@ -61,6 +62,9 @@ const char *lttng_ust_obj_get_name(int id);
 
 int lttng_get_notify_socket(void *owner);
 
+LTTNG_HIDDEN
+char* lttng_ust_sockinfo_get_procname(void *owner);
+
 void lttng_ust_sockinfo_session_enabled(void *owner);
 
 void lttng_ust_malloc_wrapper_init(void);
index 79f0f28ad124195cfb9d24bd25b776aaa7d4b721..9d0c010d502079a164e453cb67778f3a547cc2d1 100644 (file)
@@ -263,6 +263,8 @@ struct sock_info {
        /* Keep track of lazy state dump not performed yet. */
        int statedump_pending;
        int initial_statedump_done;
+       /* Keep procname for statedump */
+       char procname[LTTNG_UST_PROCNAME_LEN];
 };
 
 /* Socket from app (connect) to session daemon (listen) for communication */
@@ -283,6 +285,7 @@ struct sock_info global_apps = {
 
        .statedump_pending = 0,
        .initial_statedump_done = 0,
+       .procname[0] = '\0'
 };
 
 /* TODO: allow global_apps_sock_path override */
@@ -300,6 +303,7 @@ struct sock_info local_apps = {
 
        .statedump_pending = 0,
        .initial_statedump_done = 0,
+       .procname[0] = '\0'
 };
 
 static int wait_poll_fallback;
@@ -438,6 +442,15 @@ int lttng_get_notify_socket(void *owner)
        return info->notify_socket;
 }
 
+
+LTTNG_HIDDEN
+char* lttng_ust_sockinfo_get_procname(void *owner)
+{
+       struct sock_info *info = owner;
+
+       return info->procname;
+}
+
 static
 void print_cmd(int cmd, int handle)
 {
@@ -467,6 +480,7 @@ int setup_global_apps(void)
        }
 
        global_apps.allowed = 1;
+       lttng_ust_getprocname(global_apps.procname);
 error:
        return ret;
 }
@@ -511,6 +525,8 @@ int setup_local_apps(void)
                ret = -EIO;
                goto end;
        }
+
+       lttng_ust_getprocname(local_apps.procname);
 end:
        return ret;
 }
index b6a6f7e5970da8f8e789593f537debcf414fd643..b0c43cf76f05bfd9ed077485ee5402d6b3c5f3e2 100644 (file)
@@ -34,6 +34,7 @@ extern "C" {
 #include <stdint.h>
 #include <unistd.h>
 #include <lttng/ust-events.h>
+#include "compat.h"
 
 #define LTTNG_UST_STATEDUMP_PROVIDER
 #include <lttng/tracepoint.h>
@@ -91,6 +92,16 @@ TRACEPOINT_EVENT(lttng_ust_statedump, debug_link,
        )
 )
 
+TRACEPOINT_EVENT(lttng_ust_statedump, procname,
+       TP_ARGS(
+               struct lttng_session *, session,
+               char *, name
+       ),
+       TP_FIELDS(
+               ctf_array_text(char, procname, name, LTTNG_UST_PROCNAME_LEN)
+       )
+)
+
 TRACEPOINT_EVENT(lttng_ust_statedump, end,
        TP_ARGS(struct lttng_session *, session),
        TP_FIELDS()
index f40b7195af4f9474d946609192423a22f8fbd76f..040223d58409bd93b2ceedb9d8d8979e463beac1 100644 (file)
@@ -35,6 +35,7 @@
 #include "lttng-ust-statedump.h"
 #include "jhash.h"
 #include "getenv.h"
+#include "compat.h"
 
 #define TRACEPOINT_DEFINE
 #include "ust_lib.h"                           /* Only define. */
@@ -246,6 +247,13 @@ void trace_debug_link_cb(struct lttng_session *session, void *priv)
                bin_data->dbg_file, bin_data->crc);
 }
 
+static
+void procname_cb(struct lttng_session *session, void *priv)
+{
+       char *procname = (char *) priv;
+       tracepoint(lttng_ust_statedump, procname, session, procname);
+}
+
 static
 void trace_start_cb(struct lttng_session *session, void *priv)
 {
@@ -593,6 +601,16 @@ int do_baddr_statedump(void *owner)
        return 0;
 }
 
+static
+int do_procname_statedump(void *owner)
+{
+       if (lttng_getenv("LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP"))
+               return 0;
+
+       trace_statedump_event(procname_cb, owner, lttng_ust_sockinfo_get_procname(owner));
+       return 0;
+}
+
 /*
  * Generate a statedump of a given traced application. A statedump is
  * delimited by start and end events. For a given (process, session)
@@ -611,6 +629,7 @@ int do_lttng_ust_statedump(void *owner)
        trace_statedump_start(owner);
        ust_unlock();
 
+       do_procname_statedump(owner);
        do_baddr_statedump(owner);
 
        ust_lock_nocheck();
This page took 0.030201 seconds and 4 git commands to generate.