<font size=2 face="sans-serif">I guess I missed something in the discussion
- is this going to be active all the time, or can I disable it somehow?</font>
<br>
<br><font size=2 face="sans-serif">Maybe a command-line switch to turn
this off?</font>
<br>
<br><font size=2 face="sans-serif">For me this is overhead that I don't
need and don't want.</font>
<br>
<br><font size=2 face="sans-serif">Thanks,</font>
<br>
<br><font size=2 color=#000080 face="sans-serif">Amit Margalit</font>
<br><font size=2 color=#808000 face="sans-serif">IBM XIV </font><font size=2 face="sans-serif">-
<i>Storage Reinvented</i></font>
<br><font size=2 face="sans-serif">XIV-NAS Development Team</font>
<br><font size=2 face="sans-serif">Tel. 03</font><font size=2 face="Arial">-689-7774</font>
<br><font size=2 face="Arial">Fax. 03-689-7230</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:
</font><font size=1 face="sans-serif">Mathieu Desnoyers <mathieu.desnoyers@efficios.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:
</font><font size=1 face="sans-serif">Paul Woegerer <paul_woegerer@mentor.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:
</font><font size=1 face="sans-serif">lttng-dev@lists.lttng.org</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:
</font><font size=1 face="sans-serif">11/14/2013 09:30 PM</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:
</font><font size=1 face="sans-serif">Re: [lttng-dev]
[PATCH v3 2/2] Implement base-address-state tracing</font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>----- Original Message -----<br>
> From: "Paul Woegerer" <paul_woegerer@mentor.com><br>
> To: lttng-dev@lists.lttng.org, "mathieu desnoyers" <mathieu.desnoyers@efficios.com><br>
> Sent: Thursday, November 14, 2013 1:39:49 PM<br>
> Subject: [PATCH v3 2/2] Implement base-address-state tracing<br>
> <br>
> Dump the base-address state (executable and shared objects) into session<br>
> on session-enable (per-session events).<br>
<br>
Merged, thanks !<br>
<br>
Mathieu<br>
<br>
> <br>
> Signed-off-by: Paul Woegerer <paul_woegerer@mentor.com><br>
> ---<br>
> include/lttng/ust-tracepoint-event.h | 14 +++++++<br>
> liblttng-ust-baddr/Makefile.am
| 4 +-<br>
> liblttng-ust-baddr/lttng-ust-baddr.c | 72<br>
> ++++++++++++++++++++++++++++++++<br>
> liblttng-ust-baddr/ust_baddr_statedump.c | 21 ++++++++++<br>
> liblttng-ust-baddr/ust_baddr_statedump.h | 60 ++++++++++++++++++++++++++<br>
> liblttng-ust/lttng-events.c
| 2 +<br>
> liblttng-ust/lttng-tracer-core.h
| 3 ++<br>
> liblttng-ust/lttng-ust-comm.c
| 60 ++++++++++++++++++++++++++<br>
> 8 files changed, 235 insertions(+), 1 deletion(-)<br>
> create mode 100644 liblttng-ust-baddr/ust_baddr_statedump.c<br>
> create mode 100644 liblttng-ust-baddr/ust_baddr_statedump.h<br>
> <br>
> diff --git a/include/lttng/ust-tracepoint-event.h<br>
> b/include/lttng/ust-tracepoint-event.h<br>
> index bb3a05d..be58030 100644<br>
> --- a/include/lttng/ust-tracepoint-event.h<br>
> +++ b/include/lttng/ust-tracepoint-event.h<br>
> @@ -480,6 +480,18 @@ size_t<br>
> __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args))
\<br>
> #define TP_FIELDS(...) __VA_ARGS__<br>
> <br>
> /*<br>
> + * For state dump, check that "session" argument (mandatory)
matches the<br>
> + * session this event belongs to. Ensures that we write state dump
data only<br>
> + * into the started session, not into all sessions.<br>
> + */<br>
> +#undef _TP_SESSION_CHECK<br>
> +#ifdef TP_SESSION_CHECK<br>
> +#define _TP_SESSION_CHECK(session, csession) (session == csession)<br>
> +#else /* TP_SESSION_CHECK */<br>
> +#define _TP_SESSION_CHECK(session, csession) 1<br>
> +#endif /* TP_SESSION_CHECK */<br>
> +<br>
> +/*<br>
> * Using twice size for filter stack data to hold size and pointer
for<br>
> * each field (worse case). For integers, max size required
is 64-bit.<br>
> * Same for double-precision floats. Those fit within<br>
> @@ -506,6 +518,8 @@ void<br>
> __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))
\<br>
>
\<br>
>
if (0)
\<br>
>
(void)
__dynamic_len_idx;
/* don't warn if unused */ \<br>
> +
if (!_TP_SESSION_CHECK(session, __chan->session))
\<br>
> +
return;
\<br>
>
if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active)))
\<br>
>
return;
\<br>
>
if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled)))
\<br>
> diff --git a/liblttng-ust-baddr/Makefile.am b/liblttng-ust-baddr/Makefile.am<br>
> index afa9489..0d3cf28 100644<br>
> --- a/liblttng-ust-baddr/Makefile.am<br>
> +++ b/liblttng-ust-baddr/Makefile.am<br>
> @@ -5,7 +5,9 @@ lib_LTLIBRARIES = liblttng-ust-baddr.la<br>
> liblttng_ust_baddr_la_SOURCES = \<br>
>
lttng-ust-baddr.c \<br>
>
ust_baddr.c \<br>
> -
ust_baddr.h<br>
> +
ust_baddr.h \<br>
> +
ust_baddr_statedump.c \<br>
> +
ust_baddr_statedump.h<br>
> liblttng_ust_baddr_la_LIBADD = \<br>
>
-L$(top_builddir)/liblttng-ust/.libs \<br>
>
-llttng-ust<br>
> diff --git a/liblttng-ust-baddr/lttng-ust-baddr.c<br>
> b/liblttng-ust-baddr/lttng-ust-baddr.c<br>
> index f24a171..a856965 100644<br>
> --- a/liblttng-ust-baddr/lttng-ust-baddr.c<br>
> +++ b/liblttng-ust-baddr/lttng-ust-baddr.c<br>
> @@ -34,6 +34,7 @@<br>
> <br>
> #define TRACEPOINT_DEFINE<br>
> #include "ust_baddr.h"<br>
> +#include "ust_baddr_statedump.h"<br>
> <br>
> int<br>
> lttng_ust_push_baddr(void *so_base, const char *so_name)<br>
> @@ -62,3 +63,74 @@ lttng_ust_pop_baddr(void *so_base)<br>
>
tracepoint(ust_baddr, pop, so_base);<br>
>
return 0;<br>
> }<br>
> +<br>
> +static int<br>
> +extract_soinfo_events(struct dl_phdr_info *info, size_t size, void
*data)<br>
> +{<br>
> +
int j;<br>
> +
int num_loadable_segment = 0;<br>
> +<br>
> +
for (j = 0; j < info->dlpi_phnum; j++) {<br>
> +
char
resolved_path[PATH_MAX];<br>
> +
struct
stat sostat;<br>
> +
void
*base_addr_ptr;<br>
> +<br>
> +
if
(info->dlpi_phdr[j].p_type != PT_LOAD)<br>
> +
continue;<br>
> +<br>
> +
/*
Calculate virtual memory address of the loadable segment */<br>
> +
base_addr_ptr
= (void *) info->dlpi_addr<br>
> +
+ info->dlpi_phdr[j].p_vaddr;<br>
> +<br>
> +
num_loadable_segment
+= 1;<br>
> +
if
((info->dlpi_name == NULL || info->dlpi_name[0] == 0)<br>
> +
&&
num_loadable_segment == 1) {<br>
> +
/*<br>
> +
* If the iterated element is the executable itself we<br>
> +
* have to use Dl_info to determine its full path<br>
> +
*/<br>
> +
Dl_info dl_info = { 0 };<br>
> +
if (!dladdr(base_addr_ptr, &dl_info))<br>
> +
return
0;<br>
> +
if (!realpath(dl_info.dli_fname, resolved_path))<br>
> +
return
0;<br>
> +
}
else {<br>
> +
/*<br>
> +
* For regular dl_phdr_info entries we have to check if<br>
> +
* the path to the shared object really exists<br>
> +
*/<br>
> +
if (!realpath(info->dlpi_name, resolved_path)) {<br>
> +
/*
Found vDSO, put the 'path' into brackets */<br>
> +
snprintf(resolved_path,
PATH_MAX - 1, "[%s]",<br>
> +
info->dlpi_name);<br>
> +
}<br>
> +
}<br>
> +<br>
> +
if
(stat(resolved_path, &sostat)) {<br>
> +
sostat.st_size = 0;<br>
> +
sostat.st_mtime = -1;<br>
> +
}<br>
> +<br>
> +
tracepoint(ust_baddr_statedump,
soinfo,<br>
> +
(struct
lttng_session *) data, base_addr_ptr,<br>
> +
resolved_path,
sostat.st_size, sostat.st_mtime);<br>
> +<br>
> +
/*<br>
> +
* We are only interested in the base address (lowest virtual<br>
> +
* address associated with the memory image), skip the rest<br>
> +
*/<br>
> +
break;<br>
> +
}<br>
> +
return 0;<br>
> +}<br>
> +<br>
> +int<br>
> +lttng_ust_baddr_statedump(struct lttng_session *session)<br>
> +{<br>
> +
/*<br>
> +
* Iterate through the list of currently loaded shared objects and<br>
> +
* generate events for loadable segments using extract_soinfo_events<br>
> +
*/<br>
> +
dl_iterate_phdr(extract_soinfo_events, session);<br>
> +
return 0;<br>
> +}<br>
> diff --git a/liblttng-ust-baddr/ust_baddr_statedump.c<br>
> b/liblttng-ust-baddr/ust_baddr_statedump.c<br>
> new file mode 100644<br>
> index 0000000..75f74ca<br>
> --- /dev/null<br>
> +++ b/liblttng-ust-baddr/ust_baddr_statedump.c<br>
> @@ -0,0 +1,21 @@<br>
> +/*<br>
> + * Copyright (C) 2013 Paul Woegerer <paul_woegerer@mentor.com><br>
> + *<br>
> + * This library is free software; you can redistribute it and/or<br>
> + * modify it under the terms of the GNU Lesser General Public<br>
> + * License as published by the Free Software Foundation; either<br>
> + * version 2.1 of the License, or (at your option) any later version.<br>
> + *<br>
> + * This library is distributed in the hope that it will be useful,<br>
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU<br>
> + * Lesser General Public License for more details.<br>
> + *<br>
> + * You should have received a copy of the GNU Lesser General Public<br>
> + * License along with this library; if not, write to the Free Software<br>
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301<br>
> USA<br>
> + */<br>
> +<br>
> +#define TRACEPOINT_CREATE_PROBES<br>
> +#define TP_SESSION_CHECK<br>
> +#include "ust_baddr_statedump.h"<br>
> diff --git a/liblttng-ust-baddr/ust_baddr_statedump.h<br>
> b/liblttng-ust-baddr/ust_baddr_statedump.h<br>
> new file mode 100644<br>
> index 0000000..77a9af4<br>
> --- /dev/null<br>
> +++ b/liblttng-ust-baddr/ust_baddr_statedump.h<br>
> @@ -0,0 +1,60 @@<br>
> +#undef TRACEPOINT_PROVIDER<br>
> +#define TRACEPOINT_PROVIDER ust_baddr_statedump<br>
> +<br>
> +#if !defined(_TRACEPOINT_UST_BADDR_STATEDUMP_H) ||<br>
> defined(TRACEPOINT_HEADER_MULTI_READ)<br>
> +#define _TRACEPOINT_UST_BADDR_STATEDUMP_H<br>
> +<br>
> +#ifdef __cplusplus<br>
> +extern "C" {<br>
> +#endif<br>
> +<br>
> +/*<br>
> + * Copyright (C) 2013 Paul Woegerer <paul_woegerer@mentor.com><br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining
a<br>
> copy<br>
> + * of this software and associated documentation files (the "Software"),
to<br>
> deal<br>
> + * in the Software without restriction, including without limitation
the<br>
> rights<br>
> + * to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell<br>
> + * copies of the Software, and to permit persons to whom the Software
is<br>
> + * furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be
included<br>
> in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS<br>
> OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL<br>
> THE<br>
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING<br>
> FROM,<br>
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN<br>
> THE<br>
> + * SOFTWARE.<br>
> + */<br>
> +<br>
> +#include <stdint.h><br>
> +#include <unistd.h><br>
> +#include <lttng/ust-events.h><br>
> +<br>
> +#define LTTNG_UST_BADDR_STATEDUMP_PROVIDER<br>
> +#include <lttng/tracepoint.h><br>
> +<br>
> +TRACEPOINT_EVENT(ust_baddr_statedump, soinfo,<br>
> +
TP_ARGS(struct lttng_session *, session, void *, baddr, const char*,<br>
> sopath, int64_t, size, int64_t, mtime),<br>
> +
TP_FIELDS(<br>
> +
ctf_integer_hex(void
*, baddr, baddr)<br>
> +
ctf_string(sopath,
sopath)<br>
> +
ctf_integer(int64_t,
size, size)<br>
> +
ctf_integer(int64_t,
mtime, mtime)<br>
> +
)<br>
> +)<br>
> +<br>
> +#endif /* _TRACEPOINT_UST_BADDR_STATEDUMP_H */<br>
> +<br>
> +#undef TRACEPOINT_INCLUDE<br>
> +#define TRACEPOINT_INCLUDE "./ust_baddr_statedump.h"<br>
> +<br>
> +/* This part must be outside ifdef protection */<br>
> +#include <lttng/tracepoint-event.h><br>
> +<br>
> +#ifdef __cplusplus<br>
> +}<br>
> +#endif<br>
> diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c<br>
> index 26601a6..21e3639 100644<br>
> --- a/liblttng-ust/lttng-events.c<br>
> +++ b/liblttng-ust/lttng-events.c<br>
> @@ -293,6 +293,8 @@ int lttng_session_enable(struct lttng_session
*session)<br>
>
/* Set atomically the state to "active" */<br>
>
CMM_ACCESS_ONCE(session->active) = 1;<br>
>
CMM_ACCESS_ONCE(session->been_active) = 1;<br>
> +<br>
> +
lttng_ust_sockinfo_session_enabled(session->owner, session);<br>
> end:<br>
>
return ret;<br>
> }<br>
> diff --git a/liblttng-ust/lttng-tracer-core.h<br>
> b/liblttng-ust/lttng-tracer-core.h<br>
> index f643a7e..e7f549e 100644<br>
> --- a/liblttng-ust/lttng-tracer-core.h<br>
> +++ b/liblttng-ust/lttng-tracer-core.h<br>
> @@ -45,4 +45,7 @@ const char *lttng_ust_obj_get_name(int id);<br>
> <br>
> int lttng_get_notify_socket(void *owner);<br>
> <br>
> +void lttng_ust_sockinfo_session_enabled(void *owner,<br>
> +
struct
lttng_session *session_enabled);<br>
> +<br>
> #endif /* _LTTNG_TRACER_CORE_H */<br>
> diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c<br>
> index a6e4ba3..6ef3006 100644<br>
> --- a/liblttng-ust/lttng-ust-comm.c<br>
> +++ b/liblttng-ust/lttng-ust-comm.c<br>
> @@ -34,6 +34,7 @@<br>
> #include <time.h><br>
> #include <assert.h><br>
> #include <signal.h><br>
> +#include <dlfcn.h><br>
> #include <urcu/uatomic.h><br>
> #include <urcu/futex.h><br>
> #include <urcu/compiler.h><br>
> @@ -106,6 +107,7 @@ struct sock_info {<br>
> <br>
>
char wait_shm_path[PATH_MAX];<br>
>
char *wait_shm_mmap;<br>
> +
struct lttng_session *session_enabled;<br>
> };<br>
> <br>
> /* Socket from app (connect) to session daemon (listen) for
communication */<br>
> @@ -122,6 +124,8 @@ struct sock_info global_apps = {<br>
>
.notify_socket = -1,<br>
> <br>
>
.wait_shm_path = "/" LTTNG_UST_WAIT_FILENAME,<br>
> +<br>
> +
.session_enabled = NULL,<br>
> };<br>
> <br>
> /* TODO: allow global_apps_sock_path override */<br>
> @@ -135,6 +139,8 @@ struct sock_info local_apps = {<br>
> <br>
>
.socket = -1,<br>
>
.notify_socket = -1,<br>
> +<br>
> +
.session_enabled = NULL,<br>
> };<br>
> <br>
> static int wait_poll_fallback;<br>
> @@ -176,6 +182,7 @@ static const char *cmd_name_mapping[] = {<br>
> <br>
> static const char *str_timeout;<br>
> static int got_timeout_env;<br>
> +static void *ust_baddr_handle;<br>
> <br>
> extern void lttng_ring_buffer_client_overwrite_init(void);<br>
> extern void lttng_ring_buffer_client_overwrite_rt_init(void);<br>
> @@ -235,6 +242,39 @@ void print_cmd(int cmd, int handle)<br>
> }<br>
> <br>
> static<br>
> +void *lttng_ust_baddr_handle(void)<br>
> +{<br>
> +
if (!ust_baddr_handle) {<br>
> +
ust_baddr_handle
= dlopen(<br>
> +
"liblttng-ust-baddr.so.0", RTLD_NOW | RTLD_GLOBAL);<br>
> +
if
(ust_baddr_handle == NULL)<br>
> +
ERR("%s", dlerror());<br>
> +
}<br>
> +
return ust_baddr_handle;<br>
> +}<br>
> +<br>
> +static<br>
> +int lttng_ust_baddr_statedump(struct lttng_session *session)<br>
> +{<br>
> +
static<br>
> +
int (*lttng_ust_baddr_init_fn)(struct lttng_session *);<br>
> +<br>
> +
if (!lttng_ust_baddr_init_fn) {<br>
> +
void
*baddr_handle = lttng_ust_baddr_handle();<br>
> +
if
(baddr_handle) {<br>
> +
lttng_ust_baddr_init_fn = dlsym(baddr_handle,<br>
> +
"lttng_ust_baddr_statedump");<br>
> +
if (lttng_ust_baddr_init_fn == NULL)<br>
> +
ERR("%s",
dlerror());<br>
> +
}<br>
> +
if
(!lttng_ust_baddr_init_fn)<br>
> +
return -1;<br>
> +
}<br>
> +<br>
> +
return lttng_ust_baddr_init_fn(session);<br>
> +}<br>
> +<br>
> +static<br>
> int setup_local_apps(void)<br>
> {<br>
>
const char *home_dir;<br>
> @@ -1143,6 +1183,13 @@ restart:<br>
>
ret = handle_message(sock_info, sock, &lum);<br>
>
if (ret) {<br>
>
ERR("Error
handling message for %s socket", sock_info->name);<br>
> +
} else {<br>
> +
struct
lttng_session *session =<br>
> +
sock_info->session_enabled;<br>
> +
if
(session) {<br>
> +
sock_info->session_enabled = NULL;<br>
> +
lttng_ust_baddr_statedump(session);<br>
> +
}<br>
>
}<br>
>
continue;<br>
>
default:<br>
> @@ -1379,6 +1426,12 @@ void __attribute__((destructor)) lttng_ust_exit(void)<br>
>
* cleanup the threads if there are stalled in a syscall.<br>
>
*/<br>
>
lttng_ust_cleanup(1);<br>
> +<br>
> +
if (ust_baddr_handle) {<br>
> +
int
ret = dlclose(ust_baddr_handle);<br>
> +
if
(ret)<br>
> +
ERR("%s", dlerror());<br>
> +
}<br>
> }<br>
> <br>
> /*<br>
> @@ -1456,3 +1509,10 @@ void ust_after_fork_child(sigset_t *restore_sigset)<br>
>
ust_after_fork_common(restore_sigset);<br>
>
lttng_ust_init();<br>
> }<br>
> +<br>
> +void lttng_ust_sockinfo_session_enabled(void *owner,<br>
> +
struct
lttng_session *session_enabled)<br>
> +{<br>
> +
struct sock_info *sock_info = owner;<br>
> +
sock_info->session_enabled = session_enabled;<br>
> +}<br>
> --<br>
> 1.8.4.2<br>
> <br>
> <br>
<br>
-- <br>
Mathieu Desnoyers<br>
EfficiOS Inc.<br>
</font></tt><a href=http://www.efficios.com/><tt><font size=2>http://www.efficios.com</font></tt></a><tt><font size=2><br>
<br>
_______________________________________________<br>
lttng-dev mailing list<br>
lttng-dev@lists.lttng.org<br>
</font></tt><a href="http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev"><tt><font size=2>http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</font></tt></a><tt><font size=2><br>
<br>
</font></tt>
<br>