Fix: use per-uid buffer registry for UID buffer snapshots
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Jul 2013 17:29:30 +0000 (13:29 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Jul 2013 18:34:01 +0000 (14:34 -0400)
Fixes empty traces when doing a snapshot after killing a single traced
application.

Reviewed-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/bin/lttng-sessiond/buffer-registry.h
src/bin/lttng-sessiond/ust-app.c

index 0bf439d78ce692938f605fde915495d2e3ef7754..c2099b6883c7ff70174431635b33080eb3e4d4b2 100644 (file)
@@ -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;
index 9863bf75d2ae610d5dbfcf317c5944ad7c314634..830b5eafeeb3328737f66cb75c7f7ef9526fb2ae 100644 (file)
@@ -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:
This page took 0.031908 seconds and 5 git commands to generate.