flt.lttng-utils.debug-info: add all SC and EC to output trace class ASAP
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 4 Oct 2019 18:19:38 +0000 (14:19 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Wed, 23 Oct 2019 01:16:17 +0000 (21:16 -0400)
The fact that we are copying metadata only when encountering the data
associated to it leads to variations in the output of a
`sink.text.details` component when changing message batch size. It is
not wrong it's simply annoying.

So to improve that, this commit makes `flt.lttng-utils.debug-info`
components copy all the metadata of the input trace class as soon as it
encounters it.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I7a58e3ed4659ee73f5b0f94da5427ac8b06d5178
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2132
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/lttng-utils/debug-info/trace-ir-mapping.c
src/plugins/lttng-utils/debug-info/trace-ir-mapping.h
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.h

index 3b694d3b6b7f41d1c4eab8f2cd3324e5760ff293..3acc1d3348ef048609fa24d52f3b0b81ae982f3c 100644 (file)
@@ -46,35 +46,43 @@ static
 bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps,
                const bt_trace_class *in_trace_class)
 {
+       struct trace_ir_metadata_maps *metadata_maps;
        int ret;
-       bt_trace_class *out_trace_class;
 
        BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class);
 
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_trace_class);
 
+       metadata_maps = borrow_metadata_maps_from_input_trace_class(ir_maps,
+               in_trace_class);
+
+       BT_ASSERT(!metadata_maps->output_trace_class);
+
        /* Create the ouput trace class. */
-       out_trace_class = bt_trace_class_create(ir_maps->self_comp);
-       if (!out_trace_class) {
+       metadata_maps->output_trace_class  =
+               bt_trace_class_create(ir_maps->self_comp);
+       if (!metadata_maps->output_trace_class) {
                BT_COMP_LOGE_STR("Error create output trace class");
                goto end;
        }
 
-       /* If not, create a new one and add it to the mapping. */
-       ret = copy_trace_class_content(in_trace_class, out_trace_class,
-               ir_maps->log_level, ir_maps->self_comp);
+       /* Copy the content over and add to the mapping. */
+       ret = copy_trace_class_content(ir_maps, in_trace_class,
+               metadata_maps->output_trace_class, ir_maps->log_level,
+               ir_maps->self_comp);
        if (ret) {
                BT_COMP_LOGE_STR("Error copy content to output trace class");
-               out_trace_class = NULL;
+               BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps->output_trace_class);
+               metadata_maps->output_trace_class = NULL;
                goto end;
        }
 
        BT_COMP_LOGD("Created new mapped trace class: in-tc-addr=%p, out-tc-addr=%p",
-               in_trace_class, out_trace_class);
+               in_trace_class, metadata_maps->output_trace_class);
 
 end:
-       return out_trace_class;
+       return metadata_maps->output_trace_class;
 }
 
 static
@@ -123,19 +131,24 @@ end:
        return out_trace;
 }
 
-static
-bt_stream_class *borrow_mapped_stream_class(struct trace_ir_metadata_maps *md_maps,
+BT_HIDDEN
+bt_stream_class *trace_ir_mapping_borrow_mapped_stream_class(
+               struct trace_ir_maps *ir_maps,
                const bt_stream_class *in_stream_class)
 {
-       BT_ASSERT_DBG(md_maps);
+       BT_ASSERT_DBG(ir_maps);
        BT_ASSERT_DBG(in_stream_class);
 
+       struct trace_ir_metadata_maps *md_maps =
+               borrow_metadata_maps_from_input_stream_class(ir_maps,
+                       in_stream_class);
        return g_hash_table_lookup(md_maps->stream_class_map,
                (gpointer) in_stream_class);
 }
 
-static
-bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
+BT_HIDDEN
+bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class(
+               struct trace_ir_maps *ir_maps,
                const bt_stream_class *in_stream_class)
 {
        struct trace_ir_metadata_maps *md_maps;
@@ -147,12 +160,13 @@ bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
 
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_stream_class);
+       BT_ASSERT(!trace_ir_mapping_borrow_mapped_stream_class(ir_maps,
+               in_stream_class));
 
        md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps,
                in_stream_class);
 
        BT_ASSERT(md_maps);
-       BT_ASSERT(!borrow_mapped_stream_class(md_maps, in_stream_class));
 
        /* Create the output stream class. */
        out_stream_class = bt_stream_class_create_with_id(
@@ -163,6 +177,10 @@ bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
                goto end;
        }
 
+       /* Add it to the mapping. */
+       g_hash_table_insert(md_maps->stream_class_map,
+               (gpointer) in_stream_class, out_stream_class);
+
        /* Copy the content over to the output stream class. */
        ret = copy_stream_class_content(ir_maps, in_stream_class,
                out_stream_class);
@@ -172,10 +190,6 @@ bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
                goto end;
        }
 
-       /* Add it to the mapping. */
-       g_hash_table_insert(md_maps->stream_class_map,
-               (gpointer) in_stream_class, out_stream_class);
-
        BT_COMP_LOGD("Created new mapped stream class: in-sc-addr=%p, out-sc-addr=%p",
                in_stream_class, out_stream_class);
 
@@ -198,7 +212,6 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
                struct trace_ir_maps *ir_maps, const bt_stream *in_stream)
 {
        struct trace_ir_data_maps *d_maps;
-       struct trace_ir_metadata_maps *md_maps;
        const bt_stream_class *in_stream_class;
        const bt_trace *in_trace;
        bt_stream_class *out_stream_class;
@@ -223,12 +236,13 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
        BT_ASSERT(!borrow_mapped_stream(d_maps, in_stream));
 
        in_stream_class = bt_stream_borrow_class_const(in_stream);
-       md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class);
-       out_stream_class = borrow_mapped_stream_class(md_maps, in_stream_class);
+       out_stream_class = trace_ir_mapping_borrow_mapped_stream_class(ir_maps,
+               in_stream_class);
+
        if (!out_stream_class) {
                /* Create the output stream class for this input stream class. */
-               out_stream_class = create_new_mapped_stream_class(ir_maps,
-                       in_stream_class);
+               out_stream_class = trace_ir_mapping_create_new_mapped_stream_class(
+                       ir_maps, in_stream_class);
                if (!out_stream_class) {
                        goto end;
                }
@@ -243,14 +257,14 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
                goto end;
        }
 
-       /* Copy the content over to the output stream. */
-       copy_stream_content(in_stream, out_stream, ir_maps->log_level,
-               ir_maps->self_comp);
-
        /* Add it to the mapping. */
        g_hash_table_insert(d_maps->stream_map, (gpointer) in_stream,
                out_stream);
 
+       /* Copy the content over to the output stream. */
+       copy_stream_content(in_stream, out_stream, ir_maps->log_level,
+               ir_maps->self_comp);
+
        BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
                in_stream, out_stream);
 
@@ -308,7 +322,8 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
        BT_ASSERT(!borrow_mapped_event_class(md_maps, in_event_class));
 
        /* Get the right output stream class to add the new event class to it. */
-       out_stream_class = borrow_mapped_stream_class(md_maps, in_stream_class);
+       out_stream_class = trace_ir_mapping_borrow_mapped_stream_class(
+               ir_maps, in_stream_class);
        BT_ASSERT(out_stream_class);
 
        /* Create an output event class. */
@@ -319,6 +334,10 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
                goto end;
        }
 
+       /* Add it to the mapping. */
+       g_hash_table_insert(md_maps->event_class_map,
+                       (gpointer) in_event_class, out_event_class);
+
        /* Copy the content over to the output event class. */
        ret = copy_event_class_content(ir_maps, in_event_class,
                out_event_class);
@@ -328,10 +347,6 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
                goto end;
        }
 
-       /* Add it to the mapping. */
-       g_hash_table_insert(md_maps->event_class_map,
-               (gpointer) in_event_class, out_event_class);
-
        BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
                in_event_class, out_event_class);
 
@@ -398,14 +413,14 @@ bt_packet *trace_ir_mapping_create_new_mapped_packet(
                goto end;
        }
 
-       /* Copy the content over to the output packet. */
-       copy_packet_content(in_packet, out_packet, ir_maps->log_level,
-               ir_maps->self_comp);
-
        /* Add it to the mapping. */
        g_hash_table_insert(d_maps->packet_map,
                (gpointer) in_packet, out_packet);
 
+       /* Copy the content over to the output packet. */
+       copy_packet_content(in_packet, out_packet, ir_maps->log_level,
+               ir_maps->self_comp);
+
        BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
                in_packet, out_packet);
 
index 26d9c96e6929a0e1caba3544ba10446f4d9311e4..9e5caa9fc89721bb997b674fb0467251f4f14e71 100644 (file)
@@ -157,6 +157,16 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
 BT_HIDDEN
 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *md_maps);
 
+BT_HIDDEN
+bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class(
+               struct trace_ir_maps *ir_maps,
+               const bt_stream_class *in_stream_class);
+
+BT_HIDDEN
+bt_stream_class *trace_ir_mapping_borrow_mapped_stream_class(
+               struct trace_ir_maps *ir_maps,
+               const bt_stream_class *in_stream_class);
+
 BT_HIDDEN
 bt_stream *trace_ir_mapping_create_new_mapped_stream(
                struct trace_ir_maps *ir_maps,
index e1aa3cad09e6973cd1385ac2f57752d6c7ab9b50..4f14cd6c4473f8b5d57f1aa195e4e7aaa9e76581 100644 (file)
 #include "utils.h"
 
 BT_HIDDEN
-int copy_trace_class_content(const bt_trace_class *in_trace_class,
-               bt_trace_class *out_trace_class, bt_logging_level log_level,
-               bt_self_component *self_comp)
+int copy_trace_class_content(struct trace_ir_maps *ir_maps,
+               const bt_trace_class *in_trace_class, bt_trace_class *out_trace_class,
+               bt_logging_level log_level, bt_self_component *self_comp)
 {
+       uint64_t sc_number, sc_idx;
        BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p",
                in_trace_class, out_trace_class);
 
@@ -56,6 +57,27 @@ int copy_trace_class_content(const bt_trace_class *in_trace_class,
        /* Use the same stream class ids as in the origin trace class. */
        bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class,
                BT_FALSE);
+
+       /* Copy stream classes contained in the trace class. */
+       sc_number = bt_trace_class_get_stream_class_count(in_trace_class);
+       for (sc_idx = 0; sc_idx < sc_number; sc_idx++) {
+               bt_stream_class *out_stream_class;
+               const bt_stream_class *in_stream_class =
+                       bt_trace_class_borrow_stream_class_by_index_const(
+                               in_trace_class, sc_idx);
+
+               out_stream_class = trace_ir_mapping_borrow_mapped_stream_class(
+                       ir_maps, in_stream_class);
+               if (!out_stream_class) {
+                       /*
+                        * We don't need the new stream_class yet. We simply
+                        * want to create it and keep it in the map.
+                        */
+                       (void) trace_ir_mapping_create_new_mapped_stream_class(
+                               ir_maps, in_stream_class);
+               }
+       }
+
        BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p",
                in_trace_class, out_trace_class);
        return 0;
@@ -192,6 +214,7 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps,
        const bt_field_class *in_packet_context_fc, *in_common_context_fc;
        bt_field_class *out_packet_context_fc, *out_common_context_fc;
        const char *in_name;
+       uint64_t ec_number, ec_idx;
        bt_logging_level log_level = ir_maps->log_level;
        bt_self_component *self_comp = ir_maps->self_comp;
        int ret = 0;
@@ -324,6 +347,25 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps,
                }
        }
 
+       /* Copy event classes contained in the stream class. */
+       ec_number = bt_stream_class_get_event_class_count(in_stream_class);
+       for (ec_idx = 0; ec_idx < ec_number; ec_idx++) {
+               bt_event_class *out_event_class;
+               const bt_event_class *in_event_class =
+                       bt_stream_class_borrow_event_class_by_id_const(
+                               in_stream_class, ec_idx);
+               out_event_class = trace_ir_mapping_borrow_mapped_event_class(
+                       ir_maps, in_event_class);
+               if (!out_event_class) {
+                       /*
+                        * We don't need the new event_class yet. We simply
+                        * want to create it and keep it in the map.
+                        */
+                       (void) trace_ir_mapping_create_new_mapped_event_class(
+                               ir_maps, in_event_class);
+               }
+       }
+
        BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p",
                in_stream_class, out_stream_class);
 error:
index f08d071910e0f2284e6a129a0d53c83f3cde4aa1..0a70c3c9eca4a5e17943308704946b355f9dde2a 100644 (file)
@@ -32,7 +32,8 @@
 #include "trace-ir-mapping.h"
 
 BT_HIDDEN
-int copy_trace_class_content(const bt_trace_class *in_trace_class,
+int copy_trace_class_content(struct trace_ir_maps *trace_ir_maps,
+               const bt_trace_class *in_trace_class,
                bt_trace_class *out_trace_class,
                bt_logging_level log_level,
                bt_self_component *self_comp);
This page took 0.030744 seconds and 4 git commands to generate.