From: Jonathan Rajotte Date: Fri, 28 Jun 2019 21:28:15 +0000 (-0400) Subject: Add procname to lttng_ust_statedump information X-Git-Tag: v2.12.0-rc1~8 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=94be38e8fd2d71397f79c0a368ba95678052e32d;p=lttng-ust.git Add procname to lttng_ust_statedump information 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/man/lttng-ust.3.txt b/doc/man/lttng-ust.3.txt index 2534612a..507aaca5 100644 --- a/doc/man/lttng-ust.3.txt +++ b/doc/man/lttng-ust.3.txt @@ -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 <> section above). +`LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP`:: + If set, prevents `liblttng-ust` from performing a procname state + dump (see the <> section above). + include::common-footer.txt[] diff --git a/include/helper.h b/include/helper.h index 9873fead..a187b0e7 100644 --- a/include/helper.h +++ b/include/helper.h @@ -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 */ diff --git a/liblttng-ust/lttng-tracer-core.h b/liblttng-ust/lttng-tracer-core.h index 52315a8d..bd837237 100644 --- a/liblttng-ust/lttng-tracer-core.h +++ b/liblttng-ust/lttng-tracer-core.h @@ -29,6 +29,7 @@ #include #include #include +#include /* * 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); diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 79f0f28a..9d0c010d 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -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; } diff --git a/liblttng-ust/lttng-ust-statedump-provider.h b/liblttng-ust/lttng-ust-statedump-provider.h index b6a6f7e5..b0c43cf7 100644 --- a/liblttng-ust/lttng-ust-statedump-provider.h +++ b/liblttng-ust/lttng-ust-statedump-provider.h @@ -34,6 +34,7 @@ extern "C" { #include #include #include +#include "compat.h" #define LTTNG_UST_STATEDUMP_PROVIDER #include @@ -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() diff --git a/liblttng-ust/lttng-ust-statedump.c b/liblttng-ust/lttng-ust-statedump.c index f40b7195..040223d5 100644 --- a/liblttng-ust/lttng-ust-statedump.c +++ b/liblttng-ust/lttng-ust-statedump.c @@ -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();