From 8c924c7bfb12055ac5f87960501c888efb24c82e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 16 Jul 2013 13:29:30 -0400 Subject: [PATCH] Fix: use per-uid buffer registry for UID buffer snapshots Fixes empty traces when doing a snapshot after killing a single traced application. Reviewed-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- src/bin/lttng-sessiond/buffer-registry.h | 2 + src/bin/lttng-sessiond/ust-app.c | 165 ++++++++++++++++------- 2 files changed, 118 insertions(+), 49 deletions(-) diff --git a/src/bin/lttng-sessiond/buffer-registry.h b/src/bin/lttng-sessiond/buffer-registry.h index 0bf439d78..c2099b688 100644 --- a/src/bin/lttng-sessiond/buffer-registry.h +++ b/src/bin/lttng-sessiond/buffer-registry.h @@ -49,6 +49,8 @@ struct buffer_reg_channel { pthread_mutex_t stream_list_lock; /* Node for hash table usage. */ struct lttng_ht_node_u64 node; + /* Size of subbuffers in this channel. */ + size_t subbuf_size; union { /* Original object data that MUST be copied over. */ struct lttng_ust_object_data *ust; diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 9863bf75d..830b5eafe 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -2134,6 +2134,7 @@ static int create_buffer_reg_channel(struct buffer_reg_session *reg_sess, } assert(reg_chan); reg_chan->consumer_key = ua_chan->key; + reg_chan->subbuf_size = ua_chan->attr.subbuf_size; /* Create and add a channel registry to session. */ ret = ust_registry_channel_add(reg_sess->reg.ust, @@ -4892,69 +4893,135 @@ int ust_app_snapshot_record(struct ltt_ust_session *usess, max_stream_size = output->max_size / nb_streams; } - cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) { - struct consumer_socket *socket; - struct lttng_ht_iter chan_iter; - struct ust_app_channel *ua_chan; - struct ust_app_session *ua_sess; - struct ust_registry_session *registry; + switch (usess->buffer_type) { + case LTTNG_BUFFER_PER_UID: + { + struct buffer_reg_uid *reg; - ua_sess = lookup_session_by_app(usess, app); - if (!ua_sess) { - /* Session not associated with this app. */ - continue; - } + cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) { + struct buffer_reg_channel *reg_chan; + struct consumer_socket *socket; - /* Get the right consumer socket for the application. */ - socket = consumer_find_socket_by_bitness(app->bits_per_long, - output->consumer); - if (!socket) { - ret = -EINVAL; - goto error; - } + /* Get consumer socket to use to push the metadata.*/ + socket = consumer_find_socket_by_bitness(reg->bits_per_long, + usess->consumer); + if (!socket) { + ret = -EINVAL; + goto error; + } - /* Add the UST default trace dir to path. */ - memset(pathname, 0, sizeof(pathname)); - ret = snprintf(pathname, sizeof(pathname), DEFAULT_UST_TRACE_DIR "/%s", - ua_sess->path); - if (ret < 0) { - PERROR("snprintf snapshot path"); - goto error; + memset(pathname, 0, sizeof(pathname)); + ret = snprintf(pathname, sizeof(pathname), + DEFAULT_UST_TRACE_DIR "/" DEFAULT_UST_TRACE_UID_PATH, + reg->uid, reg->bits_per_long); + if (ret < 0) { + PERROR("snprintf snapshot path"); + goto error; + } + + /* Add the UST default trace dir to path. */ + cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter, + reg_chan, node.node) { + + /* + * Make sure the maximum stream size is not lower than the + * subbuffer size or else it's an error since we won't be able to + * snapshot anything. + */ + if (max_stream_size && + reg_chan->subbuf_size > max_stream_size) { + ret = -EINVAL; + DBG3("UST app snapshot record maximum stream size %" PRIu64 + " is smaller than subbuffer size of %" PRIu64, + max_stream_size, reg_chan->subbuf_size); + goto error; + } + ret = consumer_snapshot_channel(socket, reg_chan->consumer_key, output, 0, + usess->uid, usess->gid, pathname, wait, + max_stream_size); + if (ret < 0) { + goto error; + } + } + ret = consumer_snapshot_channel(socket, reg->registry->reg.ust->metadata_key, output, + 1, usess->uid, usess->gid, pathname, wait, + max_stream_size); + if (ret < 0) { + goto error; + } } + break; + } + case LTTNG_BUFFER_PER_PID: + { + cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) { + struct consumer_socket *socket; + struct lttng_ht_iter chan_iter; + struct ust_app_channel *ua_chan; + struct ust_app_session *ua_sess; + struct ust_registry_session *registry; - cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, - ua_chan, node.node) { - /* - * Make sure the maximum stream size is not lower than the - * subbuffer size or else it's an error since we won't be able to - * snapshot anything. - */ - if (max_stream_size && - ua_chan->attr.subbuf_size > max_stream_size) { + ua_sess = lookup_session_by_app(usess, app); + if (!ua_sess) { + /* Session not associated with this app. */ + continue; + } + + /* Get the right consumer socket for the application. */ + socket = consumer_find_socket_by_bitness(app->bits_per_long, + output->consumer); + if (!socket) { ret = -EINVAL; - DBG3("UST app snapshot record maximum stream size %" PRIu64 - " is smaller than subbuffer size of %" PRIu64, - max_stream_size, ua_chan->attr.subbuf_size); goto error; } - ret = consumer_snapshot_channel(socket, ua_chan->key, output, 0, - ua_sess->euid, ua_sess->egid, pathname, wait, - max_stream_size); + /* Add the UST default trace dir to path. */ + memset(pathname, 0, sizeof(pathname)); + ret = snprintf(pathname, sizeof(pathname), DEFAULT_UST_TRACE_DIR "/%s", + ua_sess->path); if (ret < 0) { + PERROR("snprintf snapshot path"); goto error; } - } - registry = get_session_registry(ua_sess); - assert(registry); - ret = consumer_snapshot_channel(socket, registry->metadata_key, output, - 1, ua_sess->euid, ua_sess->egid, pathname, wait, - max_stream_size); - if (ret < 0) { - goto error; - } + cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter, + ua_chan, node.node) { + /* + * Make sure the maximum stream size is not lower than the + * subbuffer size or else it's an error since we won't be able to + * snapshot anything. + */ + if (max_stream_size && + ua_chan->attr.subbuf_size > max_stream_size) { + ret = -EINVAL; + DBG3("UST app snapshot record maximum stream size %" PRIu64 + " is smaller than subbuffer size of %" PRIu64, + max_stream_size, ua_chan->attr.subbuf_size); + goto error; + } + + ret = consumer_snapshot_channel(socket, ua_chan->key, output, 0, + ua_sess->euid, ua_sess->egid, pathname, wait, + max_stream_size); + if (ret < 0) { + goto error; + } + } + registry = get_session_registry(ua_sess); + assert(registry); + ret = consumer_snapshot_channel(socket, registry->metadata_key, output, + 1, ua_sess->euid, ua_sess->egid, pathname, wait, + max_stream_size); + if (ret < 0) { + goto error; + } + } + break; + } + default: + assert(0); + break; } error: -- 2.34.1