X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ust-statedump.c;h=98b80b35fa3a343fd85d3d6d854e61fa2eadb66f;hb=2792781482a58865c7504100d8c1ba6db41193d1;hp=c8e508cdf9e9bd477f333ce79046e42625d64922;hpb=97c7c238f60194565d4839e38e712414c22494e3;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ust-statedump.c b/liblttng-ust/lttng-ust-statedump.c index c8e508cd..98b80b35 100644 --- a/liblttng-ust/lttng-ust-statedump.c +++ b/liblttng-ust/lttng-ust-statedump.c @@ -1,24 +1,11 @@ /* - * Copyright (C) 2013 Paul Woegerer - * Copyright (C) 2015 Antoine Busque - * Copyright (C) 2016 Mathieu Desnoyers + * SPDX-License-Identifier: LGPL-2.1-or-later * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2013 Paul Woegerer + * Copyright (C) 2015 Antoine Busque + * Copyright (C) 2016 Mathieu Desnoyers */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -29,11 +16,14 @@ #include #include -#include -#include +#include +#include #include "lttng-tracer-core.h" #include "lttng-ust-statedump.h" #include "jhash.h" +#include "getenv.h" +#include "compat.h" +#include "ust-events-internal.h" #define TRACEPOINT_DEFINE #include "ust_lib.h" /* Only define. */ @@ -73,7 +63,7 @@ struct lttng_ust_dl_node { #define UST_DL_STATE_TABLE_SIZE (1 << UST_DL_STATE_HASH_BITS) struct cds_hlist_head dl_state_table[UST_DL_STATE_TABLE_SIZE]; -typedef void (*tracepoint_cb)(struct lttng_session *session, void *priv); +typedef void (*tracepoint_cb)(struct lttng_ust_session *session, void *priv); static struct lttng_ust_dl_node *alloc_dl_node(const struct bin_info_data *bin_data) @@ -201,20 +191,20 @@ static void trace_statedump_event(tracepoint_cb tp_cb, void *owner, void *priv) { struct cds_list_head *sessionsp; - struct lttng_session *session; + struct lttng_ust_session_private *session_priv; - sessionsp = _lttng_get_sessions(); - cds_list_for_each_entry(session, sessionsp, node) { - if (session->owner != owner) + sessionsp = lttng_get_sessions(); + cds_list_for_each_entry(session_priv, sessionsp, node) { + if (session_priv->owner != owner) continue; - if (!session->statedump_pending) + if (!session_priv->statedump_pending) continue; - tp_cb(session, priv); + tp_cb(session_priv->pub, priv); } } static -void trace_bin_info_cb(struct lttng_session *session, void *priv) +void trace_bin_info_cb(struct lttng_ust_session *session, void *priv) { struct bin_info_data *bin_data = (struct bin_info_data *) priv; @@ -226,7 +216,7 @@ void trace_bin_info_cb(struct lttng_session *session, void *priv) } static -void trace_build_id_cb(struct lttng_session *session, void *priv) +void trace_build_id_cb(struct lttng_ust_session *session, void *priv) { struct bin_info_data *bin_data = (struct bin_info_data *) priv; @@ -236,7 +226,7 @@ void trace_build_id_cb(struct lttng_session *session, void *priv) } static -void trace_debug_link_cb(struct lttng_session *session, void *priv) +void trace_debug_link_cb(struct lttng_ust_session *session, void *priv) { struct bin_info_data *bin_data = (struct bin_info_data *) priv; @@ -246,13 +236,20 @@ void trace_debug_link_cb(struct lttng_session *session, void *priv) } static -void trace_start_cb(struct lttng_session *session, void *priv) +void procname_cb(struct lttng_ust_session *session, void *priv) +{ + char *procname = (char *) priv; + tracepoint(lttng_ust_statedump, procname, session, procname); +} + +static +void trace_start_cb(struct lttng_ust_session *session, void *priv) { tracepoint(lttng_ust_statedump, start, session); } static -void trace_end_cb(struct lttng_session *session, void *priv) +void trace_end_cb(struct lttng_ust_session *session, void *priv) { tracepoint(lttng_ust_statedump, end, session); } @@ -413,6 +410,8 @@ void iter_end(struct dl_iterate_data *data, void *ip) { unsigned int i; + if (data->cancel) + goto end; /* * Iterate on hash table. * For each marked, traced, do nothing. @@ -431,15 +430,16 @@ void iter_end(struct dl_iterate_data *data, void *ip) trace_lib_load(&e->bin_data, ip); e->traced = true; } + e->marked = false; } else { if (e->traced) trace_lib_unload(&e->bin_data, ip); remove_dl_node(e); free_dl_node(e); } - e->marked = false; } } +end: ust_unlock(); } @@ -548,9 +548,15 @@ void lttng_ust_dl_update(void *ip) { struct dl_iterate_data data; - if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP")) + if (lttng_ust_getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP")) return; + /* + * Fixup lttng-ust TLS when called from dlopen/dlclose + * instrumentation. + */ + lttng_ust_fixup_tls(); + data.exec_found = 0; data.first = true; data.cancel = false; @@ -576,13 +582,23 @@ void lttng_ust_dl_update(void *ip) static int do_baddr_statedump(void *owner) { - if (getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP")) + if (lttng_ust_getenv("LTTNG_UST_WITHOUT_BADDR_STATEDUMP")) return 0; lttng_ust_dl_update(LTTNG_UST_CALLER_IP()); ust_dl_table_statedump(owner); return 0; } +static +int do_procname_statedump(void *owner) +{ + if (lttng_ust_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) @@ -590,12 +606,23 @@ int do_baddr_statedump(void *owner) * session, statedumps from different processes may be * interleaved. The vpid context should be used to identify which * events belong to which process. + * + * Grab the ust_lock outside of the RCU read-side lock because we + * perform synchronize_rcu with the ust_lock held, which can trigger + * deadlocks otherwise. */ int do_lttng_ust_statedump(void *owner) { + ust_lock_nocheck(); trace_statedump_start(owner); + ust_unlock(); + + do_procname_statedump(owner); do_baddr_statedump(owner); + + ust_lock_nocheck(); trace_statedump_end(owner); + ust_unlock(); return 0; }