Cleanup: flt.lttng-utils.debug-info: coding style
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-mapping.c
index cb73727bf2669ab674c07b4c7ae3e207e8c20fdb..6ee0dbefc917197db7d695ab2e530297de7d5998 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_COMP_LOG_SELF_COMP (ir_maps->self_comp)
 #define BT_LOG_OUTPUT_LEVEL (ir_maps->log_level)
 #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-MAPPING"
-#include "logging/log.h"
+#include "logging/comp-logging.h"
 
 #include <stdbool.h>
 
@@ -48,7 +49,7 @@ bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps,
        int ret;
        bt_trace_class *out_trace_class;
 
-       BT_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_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);
@@ -56,21 +57,21 @@ bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps,
        /* Create the ouput trace class. */
        out_trace_class = bt_trace_class_create(ir_maps->self_comp);
        if (!out_trace_class) {
-               BT_LOGE_STR("Error create 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->log_level, ir_maps->self_comp);
        if (ret) {
-               BT_LOGE_STR("Error copy content to output trace class");
+               BT_COMP_LOGE_STR("Error copy content to output trace class");
                out_trace_class = NULL;
                goto end;
        }
 
-       BT_LOGD("Created new mapped trace class: in-tc-addr=%p, out-tc-addr=%p",
-                       in_trace_class, out_trace_class);
+       BT_COMP_LOGD("Created new mapped trace class: in-tc-addr=%p, out-tc-addr=%p",
+               in_trace_class, out_trace_class);
 
 end:
        return out_trace_class;
@@ -84,13 +85,13 @@ bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps,
        const bt_trace_class *in_trace_class;
        struct trace_ir_metadata_maps *metadata_maps;
 
-       BT_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace);
+       BT_COMP_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace);
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_trace);
 
        in_trace_class = bt_trace_borrow_class_const(in_trace);
        metadata_maps = borrow_metadata_maps_from_input_trace_class(ir_maps,
-                       in_trace_class);
+               in_trace_class);
 
        if (!metadata_maps->output_trace_class) {
                metadata_maps->output_trace_class =
@@ -103,15 +104,16 @@ bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps,
 
        out_trace = bt_trace_create(metadata_maps->output_trace_class);
        if (!out_trace) {
-               BT_LOGE_STR("Error create output trace");
+               BT_COMP_LOGE_STR("Error create output trace");
                goto end;
        }
 
        /* If not, create a new one and add it to the mapping. */
-       copy_trace_content(in_trace, out_trace, ir_maps->log_level);
+       copy_trace_content(in_trace, out_trace, ir_maps->log_level,
+               ir_maps->self_comp);
 
-       BT_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
-                       in_trace, out_trace);
+       BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
+               in_trace, out_trace);
 end:
        return out_trace;
 }
@@ -124,7 +126,7 @@ bt_stream_class *borrow_mapped_stream_class(struct trace_ir_metadata_maps *md_ma
        BT_ASSERT(in_stream_class);
 
        return g_hash_table_lookup(md_maps->stream_class_map,
-                       (gpointer) in_stream_class);
+               (gpointer) in_stream_class);
 }
 
 static
@@ -135,11 +137,11 @@ bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
        bt_stream_class *out_stream_class;
        struct trace_ir_metadata_maps *md_maps;
 
-       BT_LOGD("Creating new mapped stream class: in-sc-addr=%p",
-                       in_stream_class);
+       BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p",
+               in_stream_class);
 
        md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps,
-                       in_stream_class);
+               in_stream_class);
 
        BT_ASSERT(md_maps);
        BT_ASSERT(in_stream_class);
@@ -147,27 +149,27 @@ bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
 
        /* Create an out_stream_class. */
        out_stream_class = bt_stream_class_create_with_id(
-                       md_maps->output_trace_class,
-                       bt_stream_class_get_id(in_stream_class));
+               md_maps->output_trace_class,
+               bt_stream_class_get_id(in_stream_class));
        if (!out_stream_class) {
-               BT_LOGE_STR("Error create output stream class");
+               BT_COMP_LOGE_STR("Error create output stream class");
                goto end;
        }
 
        /* If not, create a new one and add it to the mapping. */
        ret = copy_stream_class_content(ir_maps, in_stream_class,
-                       out_stream_class);
+               out_stream_class);
        if (ret) {
-               BT_LOGE_STR("Error copy content to output stream class");
+               BT_COMP_LOGE_STR("Error copy content to output stream class");
                out_stream_class = NULL;
                goto end;
        }
 
        g_hash_table_insert(md_maps->stream_class_map,
-                       (gpointer) in_stream_class, out_stream_class);
+               (gpointer) in_stream_class, out_stream_class);
 
-       BT_LOGD("Created new mapped stream class: in-sc-addr=%p, out-sc-addr=%p",
-                       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);
 
 end:
        return out_stream_class;
@@ -197,7 +199,7 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
 
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_stream);
-       BT_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream);
+       BT_COMP_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream);
 
        in_trace = bt_stream_borrow_trace_const(in_stream);
 
@@ -217,7 +219,7 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
        out_stream_class = borrow_mapped_stream_class(md_maps, in_stream_class);
        if (!out_stream_class) {
                out_stream_class = create_new_mapped_stream_class(ir_maps,
-                               in_stream_class);
+                       in_stream_class);
                if (!out_stream_class) {
                        goto end;
                }
@@ -227,21 +229,18 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream(
        out_stream = bt_stream_create_with_id(out_stream_class,
                        d_maps->output_trace, bt_stream_get_id(in_stream));
        if (!out_stream) {
-               BT_LOGE_STR("Error creating output stream");
+               BT_COMP_LOGE_STR("Error creating output stream");
                goto end;
        }
-       /*
-        * Release our ref since the trace object will be managing the life
-        * time of the stream objects.
-        */
 
-       copy_stream_content(in_stream, out_stream, ir_maps->log_level);
+       copy_stream_content(in_stream, out_stream, ir_maps->log_level,
+               ir_maps->self_comp);
 
        g_hash_table_insert(d_maps->stream_map, (gpointer) in_stream,
-                       out_stream);
+               out_stream);
 
-       BT_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
-                       in_stream, out_stream);
+       BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
+               in_stream, out_stream);
 
 end:
        return out_stream;
@@ -265,7 +264,7 @@ bt_event_class *borrow_mapped_event_class(struct trace_ir_metadata_maps *md_maps
                const bt_event_class *in_event_class)
 {
        return g_hash_table_lookup(md_maps->event_class_map,
-                       (gpointer) in_event_class);
+               (gpointer) in_event_class);
 }
 
 BT_HIDDEN
@@ -282,14 +281,14 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
 
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_event_class);
-       BT_LOGD("Creating new mapped event class: in-ec-addr=%p",
+       BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p",
                        in_event_class);
 
        in_trace_class = bt_stream_class_borrow_trace_class_const(
-                               bt_event_class_borrow_stream_class_const(
-                                       in_event_class));
+               bt_event_class_borrow_stream_class_const(in_event_class));
 
-       md_maps = borrow_metadata_maps_from_input_trace_class(ir_maps, in_trace_class);
+       md_maps = borrow_metadata_maps_from_input_trace_class(ir_maps,
+               in_trace_class);
 
        BT_ASSERT(!borrow_mapped_event_class(md_maps, in_event_class));
 
@@ -303,26 +302,26 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
 
        /* Create an output event class. */
        out_event_class = bt_event_class_create_with_id(out_stream_class,
-                       bt_event_class_get_id(in_event_class));
+               bt_event_class_get_id(in_event_class));
        if (!out_event_class) {
-               BT_LOGE_STR("Error creating output event class");
+               BT_COMP_LOGE_STR("Error creating output event class");
                goto end;
        }
 
        /* If not, create a new one and add it to the mapping. */
        ret = copy_event_class_content(ir_maps, in_event_class,
-                       out_event_class);
+               out_event_class);
        if (ret) {
-               BT_LOGE_STR("Error copy content to output event class");
+               BT_COMP_LOGE_STR("Error copy content to output event class");
                out_event_class = NULL;
                goto end;
        }
 
        g_hash_table_insert(md_maps->event_class_map,
-                       (gpointer) in_event_class, out_event_class);
+               (gpointer) in_event_class, out_event_class);
 
-       BT_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
-                       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);
 
 end:
        return out_event_class;
@@ -338,7 +337,8 @@ bt_event_class *trace_ir_mapping_borrow_mapped_event_class(
        BT_ASSERT(ir_maps);
        BT_ASSERT(in_event_class);
 
-       md_maps = borrow_metadata_maps_from_input_event_class(ir_maps, in_event_class);
+       md_maps = borrow_metadata_maps_from_input_event_class(ir_maps,
+               in_event_class);
 
        /* Return the mapped event_class. */
        return borrow_mapped_event_class(md_maps, in_event_class);
@@ -351,8 +351,7 @@ bt_packet *borrow_mapped_packet(struct trace_ir_data_maps *d_maps,
        BT_ASSERT(d_maps);
        BT_ASSERT(in_packet);
 
-       return g_hash_table_lookup(d_maps->packet_map,
-                       (gpointer) in_packet);
+       return g_hash_table_lookup(d_maps->packet_map, (gpointer) in_packet);
 }
 
 BT_HIDDEN
@@ -366,7 +365,7 @@ bt_packet *trace_ir_mapping_create_new_mapped_packet(
        bt_packet *out_packet;
        bt_stream *out_stream;
 
-       BT_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet);
+       BT_COMP_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet);
 
        in_stream = bt_packet_borrow_stream_const(in_packet);
        in_trace = bt_stream_borrow_trace_const(in_stream);
@@ -384,21 +383,18 @@ bt_packet *trace_ir_mapping_create_new_mapped_packet(
        /* Create the output packet. */
        out_packet = bt_packet_create(out_stream);
        if (!out_packet) {
-               BT_LOGE_STR("Error create output packet");
+               BT_COMP_LOGE_STR("Error create output packet");
                goto end;
        }
 
-       /*
-        * Release our ref since the stream object will be managing the life
-        * time of the packet objects.
-        */
-       copy_packet_content(in_packet, out_packet, ir_maps->log_level);
+       copy_packet_content(in_packet, out_packet, ir_maps->log_level,
+               ir_maps->self_comp);
 
        g_hash_table_insert(d_maps->packet_map,
-                       (gpointer) in_packet, out_packet);
+               (gpointer) in_packet, out_packet);
 
-       BT_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
-                       in_packet, out_packet);
+       BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
+               in_packet, out_packet);
 
 end:
        return out_packet;
@@ -459,7 +455,7 @@ void trace_ir_metadata_maps_remove_func(const bt_trace_class *in_trace_class,
        if (maps->metadata_maps) {
                gboolean ret;
                ret = g_hash_table_remove(maps->metadata_maps,
-                               (gpointer) in_trace_class);
+                       (gpointer) in_trace_class);
                BT_ASSERT(ret);
        }
 }
@@ -478,14 +474,16 @@ void trace_ir_data_maps_remove_func(const bt_trace *in_trace, void *data)
 struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_maps,
                const bt_trace *in_trace)
 {
-       struct trace_ir_data_maps *d_maps =
-               g_new0(struct trace_ir_data_maps, 1);
+       struct trace_ir_data_maps *d_maps = g_new0(struct trace_ir_data_maps, 1);
+       bt_trace_add_listener_status add_listener_status;
+
        if (!d_maps) {
-               BT_LOGE_STR("Error allocating trace_ir_maps");
+               BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
                goto error;
        }
 
        d_maps->log_level = ir_maps->log_level;
+       d_maps->self_comp = ir_maps->self_comp;
        d_maps->input_trace = in_trace;
 
        /* Create the hashtables used to map data objects. */
@@ -494,8 +492,11 @@ struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_ma
        d_maps->packet_map = g_hash_table_new_full(g_direct_hash,
                        g_direct_equal, NULL,(GDestroyNotify) bt_packet_put_ref);
 
-       bt_trace_add_destruction_listener(in_trace, trace_ir_data_maps_remove_func,
-                       ir_maps, &d_maps->destruction_listener_id);
+       add_listener_status = bt_trace_add_destruction_listener(
+               in_trace, trace_ir_data_maps_remove_func,
+               ir_maps, &d_maps->destruction_listener_id);
+       BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK);
+
 error:
        return d_maps;
 }
@@ -506,12 +507,15 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
 {
        struct trace_ir_metadata_maps *md_maps =
                g_new0(struct trace_ir_metadata_maps, 1);
+       bt_trace_class_add_listener_status add_listener_status;
+
        if (!md_maps) {
-               BT_LOGE_STR("Error allocating trace_ir_maps");
+               BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
                goto error;
        }
 
        md_maps->log_level = ir_maps->log_level;
+       md_maps->self_comp = ir_maps->self_comp;
        md_maps->input_trace_class = in_trace_class;
        /*
         * Create the field class resolving context. This is needed to keep
@@ -521,23 +525,25 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
        md_maps->fc_resolving_ctx =
                g_new0(struct field_class_resolving_context, 1);
        if (!md_maps->fc_resolving_ctx) {
-               BT_LOGE_STR("Error allocating field_class_resolving_context");
+               BT_COMP_LOGE_STR("Error allocating field_class_resolving_context");
                goto error;
        }
 
        /* Create the hashtables used to map metadata objects. */
        md_maps->stream_class_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) bt_stream_class_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_stream_class_put_ref);
        md_maps->event_class_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) bt_event_class_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_event_class_put_ref);
        md_maps->field_class_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) bt_field_class_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_field_class_put_ref);
        md_maps->clock_class_map = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, NULL, (GDestroyNotify) bt_clock_class_put_ref);
+               g_direct_equal, NULL, (GDestroyNotify) bt_clock_class_put_ref);
+
+       add_listener_status = bt_trace_class_add_destruction_listener(
+               in_trace_class, trace_ir_metadata_maps_remove_func,
+               ir_maps, &md_maps->destruction_listener_id);
+       BT_ASSERT(add_listener_status == BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK);
 
-       bt_trace_class_add_destruction_listener(in_trace_class,
-                       trace_ir_metadata_maps_remove_func,
-                       ir_maps, &md_maps->destruction_listener_id);
 error:
        return md_maps;
 }
@@ -545,7 +551,8 @@ error:
 BT_HIDDEN
 void trace_ir_data_maps_destroy(struct trace_ir_data_maps *maps)
 {
-       bt_trace_status status;
+       bt_trace_remove_listener_status status;
+
        if (!maps) {
                return;
        }
@@ -563,11 +570,12 @@ void trace_ir_data_maps_destroy(struct trace_ir_data_maps *maps)
        }
 
        status = bt_trace_remove_destruction_listener(maps->input_trace,
-                       maps->destruction_listener_id);
-       if (status != BT_TRACE_STATUS_OK) {
-               BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
-                       BT_LOG_TAG,
+               maps->destruction_listener_id);
+       if (status != BT_TRACE_REMOVE_LISTENER_STATUS_OK) {
+               BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
+                       maps->self_comp,
                        "Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(maps);
@@ -576,7 +584,8 @@ void trace_ir_data_maps_destroy(struct trace_ir_data_maps *maps)
 BT_HIDDEN
 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *maps)
 {
-       bt_trace_class_status status;
+       bt_trace_class_remove_listener_status status;
+
        if (!maps) {
                return;
        }
@@ -597,19 +606,19 @@ void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *maps)
                g_hash_table_destroy(maps->clock_class_map);
        }
 
-       if (maps->fc_resolving_ctx) {
-               g_free(maps->fc_resolving_ctx);
-       }
+       g_free(maps->fc_resolving_ctx);
 
        if (maps->output_trace_class) {
                bt_trace_class_put_ref(maps->output_trace_class);
        }
 
-       status = bt_trace_class_remove_destruction_listener(maps->input_trace_class,
-                       maps->destruction_listener_id);
-       if (status != BT_TRACE_CLASS_STATUS_OK) {
-               BT_LOG_WRITE_CUR_LVL(BT_LOG_DEBUG, maps->log_level, BT_LOG_TAG,
+       status = bt_trace_class_remove_destruction_listener(
+               maps->input_trace_class, maps->destruction_listener_id);
+       if (status != BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK) {
+               BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
+                       maps->self_comp,
                        "Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(maps);
@@ -633,9 +642,7 @@ void trace_ir_maps_destroy(struct trace_ir_maps *maps)
                return;
        }
 
-       if (maps->debug_info_field_class_name) {
-               g_free(maps->debug_info_field_class_name);
-       }
+       g_free(maps->debug_info_field_class_name);
 
        if (maps->data_maps) {
                g_hash_table_destroy(maps->data_maps);
@@ -657,30 +664,31 @@ struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp,
        struct trace_ir_maps *ir_maps =
                g_new0(struct trace_ir_maps, 1);
        if (!ir_maps) {
-               BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG,
+               BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
                        "Error allocating trace_ir_maps");
                goto error;
        }
 
        ir_maps->log_level = log_level;
+       ir_maps->self_comp = self_comp;
 
        /* Copy debug info field name received from the user. */
        ir_maps->debug_info_field_class_name =
                g_strdup(debug_info_field_name);
        if (!ir_maps->debug_info_field_class_name) {
-               BT_LOGE_STR("Cannot copy debug info field name");
+               BT_COMP_LOGE_STR("Cannot copy debug info field name");
                goto error;
        }
 
        ir_maps->self_comp = self_comp;
 
        ir_maps->data_maps = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, (GDestroyNotify) NULL,
-                       (GDestroyNotify) trace_ir_data_maps_destroy);
+               g_direct_equal, (GDestroyNotify) NULL,
+               (GDestroyNotify) trace_ir_data_maps_destroy);
 
        ir_maps->metadata_maps = g_hash_table_new_full(g_direct_hash,
-                       g_direct_equal, (GDestroyNotify) NULL,
-                       (GDestroyNotify) trace_ir_metadata_maps_destroy);
+               g_direct_equal, (GDestroyNotify) NULL,
+               (GDestroyNotify) trace_ir_metadata_maps_destroy);
 
        goto end;
 error:
This page took 0.03098 seconds and 4 git commands to generate.