Fix: add UST context in the same order the user enabled them
authorDavid Goulet <dgoulet@efficios.com>
Wed, 21 Aug 2013 16:04:02 +0000 (12:04 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 21 Aug 2013 16:11:40 +0000 (12:11 -0400)
This is to avoid having different field order in different traces for
the same contexts enabled in the same order by the user.

Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-sessiond/context.c
src/bin/lttng-sessiond/trace-ust.c
src/bin/lttng-sessiond/trace-ust.h
src/bin/lttng-sessiond/ust-app.c
src/bin/lttng-sessiond/ust-app.h
src/bin/lttng/commands/add_context.c

index b55254b4e398d0bfd55604c5fb8353dd3ba7f43a..6aacbad0ea1c96ad3375739ca908f765f1ba4370 100644 (file)
@@ -132,6 +132,7 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain,
        /* Add ltt UST context node to ltt UST channel */
        lttng_ht_add_unique_ulong(uchan->ctx, &uctx->node);
        rcu_read_unlock();
+       cds_list_add_tail(&uctx->list, &uchan->ctx_list);
 
        DBG("Context UST %d added to channel %s", uctx->ctx.ctx, uchan->name);
 
index 65fe84b7d37617a17d3d4a68130d2138158f1a8d..ff72c74c1068d977e9aa6f421615494e8e0a07bd 100644 (file)
@@ -274,6 +274,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
 
        /* Init node */
        lttng_ht_node_init_str(&luc->node, luc->name);
+       CDS_INIT_LIST_HEAD(&luc->ctx_list);
+
        /* Alloc hash tables */
        luc->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
        luc->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
@@ -445,6 +447,7 @@ struct ltt_ust_context *trace_ust_create_context(
 
        uctx->ctx.ctx = utype;
        lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx);
+       CDS_INIT_LIST_HEAD(&uctx->list);
 
        return uctx;
 
@@ -473,11 +476,16 @@ static void destroy_contexts(struct lttng_ht *ht)
        int ret;
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
+       struct ltt_ust_context *ctx;
 
        assert(ht);
 
        rcu_read_lock();
        cds_lfht_for_each_entry(ht->ht, &iter.iter, node, node) {
+               /* Remove from ordered list. */
+               ctx = caa_container_of(node, struct ltt_ust_context, node);
+               cds_list_del(&ctx->list);
+               /* Remove from channel's hash table. */
                ret = lttng_ht_del(ht, &iter);
                if (!ret) {
                        call_rcu(&node->head, destroy_context_rcu);
index f5df1332cccd4a9cc13db3ebb459eb3405e0aab2..fbed52a663949e3fcd265d25224a2e5bf85de11d 100644 (file)
@@ -39,6 +39,7 @@ struct ltt_ust_ht_key {
 struct ltt_ust_context {
        struct lttng_ust_context ctx;
        struct lttng_ht_node_ulong node;
+       struct cds_list_head list;
 };
 
 /* UST event */
@@ -56,6 +57,7 @@ struct ltt_ust_channel {
        char name[LTTNG_UST_SYM_NAME_LEN];
        struct lttng_ust_channel_attr attr;
        struct lttng_ht *ctx;
+       struct cds_list_head ctx_list;
        struct lttng_ht *events;
        struct lttng_ht_node_str node;
        uint64_t tracefile_size;
index e5e45b43e4e2f74c8bdc0aadac59d056e5042bb7..47cd71f9dbefd1eb9f8450592b453b0225ff07d3 100644 (file)
@@ -364,6 +364,7 @@ void delete_ust_app_channel(int sock, struct ust_app_channel *ua_chan,
 
        /* Wipe context */
        cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter.iter, ua_ctx, node.node) {
+               cds_list_del(&ua_ctx->list);
                ret = lttng_ht_del(ua_chan->ctx, &iter);
                assert(!ret);
                delete_ust_app_ctx(sock, ua_ctx);
@@ -825,6 +826,7 @@ struct ust_app_channel *alloc_ust_app_channel(char *name,
        lttng_ht_node_init_str(&ua_chan->node, ua_chan->name);
 
        CDS_INIT_LIST_HEAD(&ua_chan->streams.head);
+       CDS_INIT_LIST_HEAD(&ua_chan->ctx_list);
 
        /* Copy attributes */
        if (attr) {
@@ -916,6 +918,8 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx)
                goto error;
        }
 
+       CDS_INIT_LIST_HEAD(&ua_ctx->list);
+
        if (uctx) {
                memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx));
        }
@@ -1395,7 +1399,7 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
        ua_chan->enabled = uchan->enabled;
        ua_chan->tracing_channel_id = uchan->id;
 
-       cds_lfht_for_each_entry(uchan->ctx->ht, &iter.iter, uctx, node.node) {
+       cds_list_for_each_entry(uctx, &uchan->ctx_list, list) {
                ua_ctx = alloc_ust_app_ctx(&uctx->ctx);
                if (ua_ctx == NULL) {
                        continue;
@@ -1403,6 +1407,7 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan,
                lttng_ht_node_init_ulong(&ua_ctx->node,
                                (unsigned long) ua_ctx->ctx.ctx);
                lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node);
+               cds_list_add_tail(&ua_ctx->list, &ua_chan->ctx_list);
        }
 
        /* Copy all events from ltt ust channel to ust app channel */
@@ -1794,6 +1799,7 @@ int create_ust_app_channel_context(struct ust_app_session *ua_sess,
 
        lttng_ht_node_init_ulong(&ua_ctx->node, (unsigned long) ua_ctx->ctx.ctx);
        lttng_ht_add_unique_ulong(ua_chan->ctx, &ua_ctx->node);
+       cds_list_add_tail(&ua_ctx->list, &ua_chan->ctx_list);
 
        ret = create_ust_channel_context(ua_chan, ua_ctx, app);
        if (ret < 0) {
@@ -4050,7 +4056,7 @@ int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
 void ust_app_global_update(struct ltt_ust_session *usess, int sock)
 {
        int ret = 0;
-       struct lttng_ht_iter iter, uiter, iter_ctx;
+       struct lttng_ht_iter iter, uiter;
        struct ust_app *app;
        struct ust_app_session *ua_sess = NULL;
        struct ust_app_channel *ua_chan;
@@ -4122,8 +4128,11 @@ void ust_app_global_update(struct ltt_ust_session *usess, int sock)
                        }
                }
 
-               cds_lfht_for_each_entry(ua_chan->ctx->ht, &iter_ctx.iter, ua_ctx,
-                               node.node) {
+               /*
+                * Add context using the list so they are enabled in the same order the
+                * user added them.
+                */
+               cds_list_for_each_entry(ua_ctx, &ua_chan->ctx_list, list) {
                        ret = create_ust_channel_context(ua_chan, ua_ctx, app);
                        if (ret < 0) {
                                goto error_unlock;
index c533fbf24ecc147c5c951dab33a6aeaf0841887d..92ac9c4e1e4af29af2f387cb82d50338fdb9bfcd 100644 (file)
@@ -102,6 +102,7 @@ struct ust_app_ctx {
        struct lttng_ust_context ctx;
        struct lttng_ust_object_data *obj;
        struct lttng_ht_node_ulong node;
+       struct cds_list_head list;
 };
 
 struct ust_app_event {
@@ -141,7 +142,14 @@ struct ust_app_channel {
        struct ust_app_stream_list streams;
        /* Session pointer that owns this object. */
        struct ust_app_session *session;
+       /*
+        * Contexts are kept in a hash table for fast lookup and in an ordered list
+        * so we are able to enable them on the tracer side in the same order the
+        * user added them.
+        */
        struct lttng_ht *ctx;
+       struct cds_list_head ctx_list;
+
        struct lttng_ht *events;
        uint64_t tracefile_size;
        uint64_t tracefile_count;
index 4904d2772b5181bb835d928595671b456b38f562..9113a237ba4cdd48754356d9546a8c139e810cb9 100644 (file)
@@ -478,7 +478,7 @@ int cmd_add_context(int argc, const char **argv)
                                ret = CMD_ERROR;
                                goto end;
                        } else {
-                               cds_list_add(&type->list, &ctx_type_list.head);
+                               cds_list_add_tail(&type->list, &ctx_type_list.head);
                        }
                        break;
                case OPT_USERSPACE:
This page took 0.03449 seconds and 4 git commands to generate.