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:04:02 +0000 (12:04 -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();
        /* 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);
 
 
        DBG("Context UST %d added to channel %s", uctx->ctx.ctx, uchan->name);
 
index c80d5e772de8c48e913b5399f23be7af785241c5..8363ae2954912482900e2aa5f3eeeeb4cd7bd26f 100644 (file)
@@ -289,6 +289,8 @@ struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *chan)
 
        /* Init node */
        lttng_ht_node_init_str(&luc->node, luc->name);
 
        /* 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);
        /* Alloc hash tables */
        luc->events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING);
        luc->ctx = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
@@ -463,6 +465,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);
 
        uctx->ctx.ctx = utype;
        lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx);
+       CDS_INIT_LIST_HEAD(&uctx->list);
 
        return uctx;
 
 
        return uctx;
 
@@ -491,11 +494,16 @@ static void destroy_contexts(struct lttng_ht *ht)
        int ret;
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
        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) {
 
        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);
                ret = lttng_ht_del(ht, &iter);
                if (!ret) {
                        call_rcu(&node->head, destroy_context_rcu);
index f4244fdefae8196a2dadfc092e844dc90a626f05..1c37b3f0f1bb977a49429f31f2ce9f47a7f74e2b 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 ltt_ust_context {
        struct lttng_ust_context ctx;
        struct lttng_ht_node_ulong node;
+       struct cds_list_head list;
 };
 
 /* UST event */
 };
 
 /* 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;
        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;
        struct lttng_ht *events;
        struct lttng_ht_node_str node;
        uint64_t tracefile_size;
index 9fe54835b656c69844599e3b0bd7b51f69db482f..5c4dc5ae85837ca24bbcef8cbb950fe0269e8376 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) {
 
        /* 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);
                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);
        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) {
 
        /* Copy attributes */
        if (attr) {
@@ -916,6 +918,8 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx)
                goto error;
        }
 
                goto error;
        }
 
+       CDS_INIT_LIST_HEAD(&ua_ctx->list);
+
        if (uctx) {
                memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx));
        }
        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;
 
        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;
                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);
                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 */
        }
 
        /* Copy all events from ltt ust channel to ust app channel */
@@ -1795,6 +1800,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);
 
        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) {
 
        ret = create_ust_channel_context(ua_chan, ua_ctx, app);
        if (ret < 0) {
@@ -4052,7 +4058,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;
 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;
        struct ust_app *app;
        struct ust_app_session *ua_sess = NULL;
        struct ust_app_channel *ua_chan;
@@ -4124,8 +4130,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;
                        ret = create_ust_channel_context(ua_chan, ua_ctx, app);
                        if (ret < 0) {
                                goto error_unlock;
index 11202ecaea5845a4ae8f354c7218a0a8d4a9b68c..a08cfd28928bdfbdfcaf3a01d2de65cc314608fb 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 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 {
 };
 
 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;
        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 lttng_ht *ctx;
+       struct cds_list_head ctx_list;
+
        struct lttng_ht *events;
        uint64_t tracefile_size;
        uint64_t tracefile_count;
        struct lttng_ht *events;
        uint64_t tracefile_size;
        uint64_t tracefile_count;
index fad85b50aa5c263fa108f0faae44fa9936e4ed20..6286ed8a0a1838e49c4592e5770e02c4ab7f16df 100644 (file)
@@ -480,7 +480,7 @@ int cmd_add_context(int argc, const char **argv)
                                ret = CMD_ERROR;
                                goto end;
                        } else {
                                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:
                        }
                        break;
                case OPT_USERSPACE:
This page took 0.030206 seconds and 4 git commands to generate.