2 * Babeltrace - Mapping of IR metadata and data object between input and output
5 * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
6 * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com>
7 * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #define BT_COMP_LOG_SELF_COMP (ir_maps->self_comp)
29 #define BT_LOG_OUTPUT_LEVEL (ir_maps->log_level)
30 #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-MAPPING"
31 #include "logging/comp-logging.h"
33 #include "common/assert.h"
34 #include <babeltrace2/babeltrace.h>
36 #include "debug-info.h"
37 #include "trace-ir-data-copy.h"
38 #include "trace-ir-mapping.h"
39 #include "trace-ir-metadata-copy.h"
42 bt_trace_class
*create_new_mapped_trace_class(struct trace_ir_maps
*ir_maps
,
43 const bt_trace_class
*in_trace_class
)
45 bt_self_component
*self_comp
= ir_maps
->self_comp
;
46 enum debug_info_trace_ir_mapping_status status
;
47 struct trace_ir_metadata_maps
*metadata_maps
;
49 BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class
);
52 BT_ASSERT(in_trace_class
);
54 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
57 BT_ASSERT(!metadata_maps
->output_trace_class
);
59 /* Create the ouput trace class. */
60 metadata_maps
->output_trace_class
=
61 bt_trace_class_create(ir_maps
->self_comp
);
62 if (!metadata_maps
->output_trace_class
) {
63 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
64 "Error create output trace class");
68 /* Copy the content over and add to the mapping. */
69 status
= copy_trace_class_content(ir_maps
, in_trace_class
,
70 metadata_maps
->output_trace_class
, ir_maps
->log_level
,
72 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
73 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
74 "Error copy content to output trace class"
75 "in-tc-addr=%p, out-tc-addr=%p", in_trace_class
,
76 metadata_maps
->output_trace_class
);
80 BT_COMP_LOGD("Created new mapped trace class: "
81 "in-tc-addr=%p, out-tc-addr=%p",
82 in_trace_class
, metadata_maps
->output_trace_class
);
86 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps
->output_trace_class
);
88 return metadata_maps
->output_trace_class
;
92 bt_trace
*create_new_mapped_trace(struct trace_ir_maps
*ir_maps
,
93 const bt_trace
*in_trace
)
95 bt_self_component
*self_comp
= ir_maps
->self_comp
;
96 enum debug_info_trace_ir_mapping_status status
;
97 struct trace_ir_metadata_maps
*metadata_maps
;
98 const bt_trace_class
*in_trace_class
;
101 BT_COMP_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace
);
105 in_trace_class
= bt_trace_borrow_class_const(in_trace
);
106 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
109 if (!metadata_maps
->output_trace_class
) {
111 * If there is no output trace class yet, create a one and add
114 metadata_maps
->output_trace_class
=
115 create_new_mapped_trace_class(ir_maps
, in_trace_class
);
116 if (!metadata_maps
->output_trace_class
) {
117 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
118 "Error create output trace class");
124 /* Create the output trace from the output trace class. */
125 out_trace
= bt_trace_create(metadata_maps
->output_trace_class
);
127 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
128 "Error create output trace");
132 /* Copy the content over to the output trace. */
133 status
= copy_trace_content(in_trace
, out_trace
, ir_maps
->log_level
,
135 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
136 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
137 "Error copy content to output trace"
138 "in-t-addr=%p, out-t-addr=%p", in_trace
, out_trace
);
142 BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
143 in_trace
, out_trace
);
147 BT_TRACE_PUT_REF_AND_RESET(out_trace
);
153 bt_stream_class
*trace_ir_mapping_borrow_mapped_stream_class(
154 struct trace_ir_maps
*ir_maps
,
155 const bt_stream_class
*in_stream_class
)
157 BT_ASSERT_DBG(ir_maps
);
158 BT_ASSERT_DBG(in_stream_class
);
160 struct trace_ir_metadata_maps
*md_maps
=
161 borrow_metadata_maps_from_input_stream_class(ir_maps
,
163 return g_hash_table_lookup(md_maps
->stream_class_map
,
164 (gpointer
) in_stream_class
);
168 bt_stream_class
*trace_ir_mapping_create_new_mapped_stream_class(
169 struct trace_ir_maps
*ir_maps
,
170 const bt_stream_class
*in_stream_class
)
172 bt_self_component
*self_comp
= ir_maps
->self_comp
;
173 enum debug_info_trace_ir_mapping_status status
;
174 struct trace_ir_metadata_maps
*md_maps
;
175 bt_stream_class
*out_stream_class
;
177 BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p",
181 BT_ASSERT(in_stream_class
);
182 BT_ASSERT(!trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
185 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
190 /* Create the output stream class. */
191 out_stream_class
= bt_stream_class_create_with_id(
192 md_maps
->output_trace_class
,
193 bt_stream_class_get_id(in_stream_class
));
194 if (!out_stream_class
) {
195 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
196 "Error create output stream class");
200 /* Add it to the mapping. The mapping now owns out_stream_class. */
201 g_hash_table_insert(md_maps
->stream_class_map
,
202 (gpointer
) in_stream_class
, out_stream_class
);
204 /* Copy the content over to the output stream class. */
205 status
= copy_stream_class_content(ir_maps
, in_stream_class
,
207 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
208 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
209 "Error copy content to output stream class: "
210 "in-sc-addr=%p, out-sc-addr=%p", in_stream_class
,
215 BT_COMP_LOGD("Created new mapped stream class: "
216 "in-sc-addr=%p, out-sc-addr=%p",
217 in_stream_class
, out_stream_class
);
221 out_stream_class
= NULL
;
223 return out_stream_class
;
227 bt_stream
*borrow_mapped_stream(struct trace_ir_data_maps
*d_maps
,
228 const bt_stream
*in_stream
)
230 BT_ASSERT_DBG(d_maps
);
231 BT_ASSERT_DBG(in_stream
);
233 return g_hash_table_lookup(d_maps
->stream_map
, (gpointer
) in_stream
);
237 bt_stream
*trace_ir_mapping_create_new_mapped_stream(
238 struct trace_ir_maps
*ir_maps
, const bt_stream
*in_stream
)
240 bt_self_component
*self_comp
= ir_maps
->self_comp
;
241 enum debug_info_trace_ir_mapping_status status
;
242 struct trace_ir_data_maps
*d_maps
;
243 const bt_stream_class
*in_stream_class
;
244 const bt_trace
*in_trace
;
245 bt_stream_class
*out_stream_class
;
246 bt_stream
*out_stream
= NULL
;
249 BT_ASSERT(in_stream
);
250 BT_COMP_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream
);
252 in_trace
= bt_stream_borrow_trace_const(in_stream
);
254 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
255 if (!d_maps
->output_trace
) {
256 /* Create the output trace for this input trace. */
257 d_maps
->output_trace
= create_new_mapped_trace(ir_maps
, in_trace
);
258 if (!d_maps
->output_trace
) {
259 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
260 "Error creating mapped trace");
265 BT_ASSERT(d_maps
->output_trace
);
266 BT_ASSERT(!borrow_mapped_stream(d_maps
, in_stream
));
268 in_stream_class
= bt_stream_borrow_class_const(in_stream
);
269 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
272 if (!out_stream_class
) {
273 /* Create the output stream class for this input stream class. */
274 out_stream_class
= trace_ir_mapping_create_new_mapped_stream_class(
275 ir_maps
, in_stream_class
);
276 if (!out_stream_class
) {
277 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
278 "Error creating mapped stream class");
282 BT_ASSERT(out_stream_class
);
284 /* Create the output stream for this input stream. */
285 out_stream
= bt_stream_create_with_id(out_stream_class
,
286 d_maps
->output_trace
, bt_stream_get_id(in_stream
));
288 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
289 "Error creating output stream");
293 /* Add it to the mapping. The mapping now owns out_stream.*/
294 g_hash_table_insert(d_maps
->stream_map
, (gpointer
) in_stream
,
297 /* Copy the content over to the output stream. */
298 status
= copy_stream_content(in_stream
, out_stream
, ir_maps
->log_level
,
300 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
301 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
302 "Error copy content to output stream: "
303 "in-s-addr=%p, out-s-addr=%p", in_stream
, out_stream
);
307 BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
308 in_stream
, out_stream
);
318 bt_stream
*trace_ir_mapping_borrow_mapped_stream(struct trace_ir_maps
*ir_maps
,
319 const bt_stream
*in_stream
)
321 struct trace_ir_data_maps
*d_maps
;
323 BT_ASSERT_DBG(ir_maps
);
324 BT_ASSERT_DBG(in_stream
);
326 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
327 /* Return the mapped stream. */
328 return borrow_mapped_stream(d_maps
, in_stream
);
332 bt_event_class
*borrow_mapped_event_class(struct trace_ir_metadata_maps
*md_maps
,
333 const bt_event_class
*in_event_class
)
335 return g_hash_table_lookup(md_maps
->event_class_map
,
336 (gpointer
) in_event_class
);
340 bt_event_class
*trace_ir_mapping_create_new_mapped_event_class(
341 struct trace_ir_maps
*ir_maps
,
342 const bt_event_class
*in_event_class
)
344 bt_self_component
*self_comp
= ir_maps
->self_comp
;
345 enum debug_info_trace_ir_mapping_status status
;
346 struct trace_ir_metadata_maps
*md_maps
;
347 const bt_stream_class
*in_stream_class
;
348 bt_stream_class
*out_stream_class
;
349 bt_event_class
*out_event_class
;
351 BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p",
355 BT_ASSERT(in_event_class
);
357 in_stream_class
= bt_event_class_borrow_stream_class_const(in_event_class
);
359 BT_ASSERT(in_stream_class
);
361 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
365 BT_ASSERT(!borrow_mapped_event_class(md_maps
, in_event_class
));
367 /* Get the right output stream class to add the new event class to it. */
368 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(
369 ir_maps
, in_stream_class
);
370 BT_ASSERT(out_stream_class
);
372 /* Create an output event class. */
373 out_event_class
= bt_event_class_create_with_id(out_stream_class
,
374 bt_event_class_get_id(in_event_class
));
375 if (!out_event_class
) {
376 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
377 "Error creating output event class");
381 /* Add it to the mapping. The mapping now owns out_event_class. */
382 g_hash_table_insert(md_maps
->event_class_map
, (gpointer
) in_event_class
,
385 /* Copy the content over to the output event class. */
386 status
= copy_event_class_content(ir_maps
, in_event_class
,
388 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
389 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
390 "Error copy content to output event class: "
391 "in-ec-addr=%p, out-ec-addr=%p", in_event_class
,
396 BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
397 in_event_class
, out_event_class
);
401 out_event_class
= NULL
;
403 return out_event_class
;
407 bt_event_class
*trace_ir_mapping_borrow_mapped_event_class(
408 struct trace_ir_maps
*ir_maps
,
409 const bt_event_class
*in_event_class
)
411 struct trace_ir_metadata_maps
*md_maps
;
413 BT_ASSERT_DBG(ir_maps
);
414 BT_ASSERT_DBG(in_event_class
);
416 md_maps
= borrow_metadata_maps_from_input_event_class(ir_maps
,
419 /* Return the mapped event_class. */
420 return borrow_mapped_event_class(md_maps
, in_event_class
);
424 bt_packet
*borrow_mapped_packet(struct trace_ir_data_maps
*d_maps
,
425 const bt_packet
*in_packet
)
427 BT_ASSERT_DBG(d_maps
);
428 BT_ASSERT_DBG(in_packet
);
430 return g_hash_table_lookup(d_maps
->packet_map
, (gpointer
) in_packet
);
434 bt_packet
*trace_ir_mapping_create_new_mapped_packet(
435 struct trace_ir_maps
*ir_maps
,
436 const bt_packet
*in_packet
)
438 bt_self_component
*self_comp
= ir_maps
->self_comp
;
439 enum debug_info_trace_ir_mapping_status status
;
440 struct trace_ir_data_maps
*d_maps
;
441 const bt_stream
*in_stream
;
442 const bt_trace
*in_trace
;
443 bt_packet
*out_packet
;
444 bt_stream
*out_stream
;
446 BT_COMP_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet
);
448 in_stream
= bt_packet_borrow_stream_const(in_packet
);
449 in_trace
= bt_stream_borrow_trace_const(in_stream
);
450 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
452 /* There should never be a mapped packet already. */
453 BT_ASSERT(!borrow_mapped_packet(d_maps
, in_packet
));
454 BT_ASSERT(in_stream
);
456 /* Get output stream corresponding to this input stream. */
457 out_stream
= borrow_mapped_stream(d_maps
, in_stream
);
458 BT_ASSERT(out_stream
);
460 /* Create the output packet. */
461 out_packet
= bt_packet_create(out_stream
);
463 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
464 "Error create output packet");
468 /* Add it to the mapping. The mapping now owns out_packet. */
469 g_hash_table_insert(d_maps
->packet_map
, (gpointer
) in_packet
,
472 /* Copy the content over to the output packet. */
473 status
= copy_packet_content(in_packet
, out_packet
, ir_maps
->log_level
,
475 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
476 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
477 "Error copy content to output packet: "
478 "in-p-addr=%p, out-p-addr=%p", in_packet
, out_packet
);
482 BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
483 in_packet
, out_packet
);
493 bt_packet
*trace_ir_mapping_borrow_mapped_packet(struct trace_ir_maps
*ir_maps
,
494 const bt_packet
*in_packet
)
496 struct trace_ir_data_maps
*d_maps
;
497 BT_ASSERT_DBG(ir_maps
);
498 BT_ASSERT_DBG(in_packet
);
500 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
502 return borrow_mapped_packet(d_maps
, in_packet
);
506 void trace_ir_mapping_remove_mapped_packet(struct trace_ir_maps
*ir_maps
,
507 const bt_packet
*in_packet
)
509 struct trace_ir_data_maps
*d_maps
;
513 BT_ASSERT(in_packet
);
515 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
517 ret
= g_hash_table_remove(d_maps
->packet_map
, in_packet
);
523 void trace_ir_mapping_remove_mapped_stream(struct trace_ir_maps
*ir_maps
,
524 const bt_stream
*in_stream
)
526 struct trace_ir_data_maps
*d_maps
;
530 BT_ASSERT(in_stream
);
532 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
534 ret
= g_hash_table_remove(d_maps
->stream_map
, in_stream
);
540 void trace_ir_metadata_maps_remove_func(const bt_trace_class
*in_trace_class
,
543 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
544 if (maps
->metadata_maps
) {
546 ret
= g_hash_table_remove(maps
->metadata_maps
,
547 (gpointer
) in_trace_class
);
553 void trace_ir_data_maps_remove_func(const bt_trace
*in_trace
, void *data
)
555 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
556 if (maps
->data_maps
) {
558 ret
= g_hash_table_remove(maps
->data_maps
, (gpointer
) in_trace
);
563 struct trace_ir_data_maps
*trace_ir_data_maps_create(struct trace_ir_maps
*ir_maps
,
564 const bt_trace
*in_trace
)
566 bt_self_component
*self_comp
= ir_maps
->self_comp
;
567 bt_trace_add_listener_status add_listener_status
;
568 struct trace_ir_data_maps
*d_maps
= g_new0(struct trace_ir_data_maps
, 1);
571 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
572 "Error allocating trace_ir_maps");
576 d_maps
->log_level
= ir_maps
->log_level
;
577 d_maps
->self_comp
= ir_maps
->self_comp
;
578 d_maps
->input_trace
= in_trace
;
580 /* Create the hashtables used to map data objects. */
581 d_maps
->stream_map
= g_hash_table_new_full(g_direct_hash
,
582 g_direct_equal
, NULL
,(GDestroyNotify
) bt_stream_put_ref
);
583 d_maps
->packet_map
= g_hash_table_new_full(g_direct_hash
,
584 g_direct_equal
, NULL
,(GDestroyNotify
) bt_packet_put_ref
);
586 add_listener_status
= bt_trace_add_destruction_listener(
587 in_trace
, trace_ir_data_maps_remove_func
,
588 ir_maps
, &d_maps
->destruction_listener_id
);
589 BT_ASSERT(add_listener_status
== BT_TRACE_ADD_LISTENER_STATUS_OK
);
595 struct trace_ir_metadata_maps
*trace_ir_metadata_maps_create(
596 struct trace_ir_maps
*ir_maps
,
597 const bt_trace_class
*in_trace_class
)
599 bt_self_component
*self_comp
= ir_maps
->self_comp
;
600 bt_trace_class_add_listener_status add_listener_status
;
601 struct trace_ir_metadata_maps
*md_maps
=
602 g_new0(struct trace_ir_metadata_maps
, 1);
605 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
606 "Error allocating trace_ir_maps");
610 md_maps
->log_level
= ir_maps
->log_level
;
611 md_maps
->self_comp
= ir_maps
->self_comp
;
612 md_maps
->input_trace_class
= in_trace_class
;
614 * Create the field class resolving context. This is needed to keep
615 * track of the field class already copied in order to do the field
616 * path resolution correctly.
618 md_maps
->fc_resolving_ctx
=
619 g_new0(struct field_class_resolving_context
, 1);
620 if (!md_maps
->fc_resolving_ctx
) {
621 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
622 "Error allocating field_class_resolving_context");
626 /* Create the hashtables used to map metadata objects. */
627 md_maps
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
628 g_direct_equal
, NULL
, (GDestroyNotify
) bt_stream_class_put_ref
);
629 md_maps
->event_class_map
= g_hash_table_new_full(g_direct_hash
,
630 g_direct_equal
, NULL
, (GDestroyNotify
) bt_event_class_put_ref
);
631 md_maps
->field_class_map
= g_hash_table_new_full(g_direct_hash
,
632 g_direct_equal
, NULL
, (GDestroyNotify
) bt_field_class_put_ref
);
633 md_maps
->clock_class_map
= g_hash_table_new_full(g_direct_hash
,
634 g_direct_equal
, NULL
, (GDestroyNotify
) bt_clock_class_put_ref
);
636 add_listener_status
= bt_trace_class_add_destruction_listener(
637 in_trace_class
, trace_ir_metadata_maps_remove_func
,
638 ir_maps
, &md_maps
->destruction_listener_id
);
639 BT_ASSERT(add_listener_status
== BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
);
646 void trace_ir_data_maps_destroy(struct trace_ir_data_maps
*maps
)
648 bt_trace_remove_listener_status status
;
654 if (maps
->packet_map
) {
655 g_hash_table_destroy(maps
->packet_map
);
658 if (maps
->stream_map
) {
659 g_hash_table_destroy(maps
->stream_map
);
662 if (maps
->output_trace
) {
663 bt_trace_put_ref(maps
->output_trace
);
666 status
= bt_trace_remove_destruction_listener(maps
->input_trace
,
667 maps
->destruction_listener_id
);
668 if (status
!= BT_TRACE_REMOVE_LISTENER_STATUS_OK
) {
669 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
671 "Trace destruction listener removal failed.");
672 bt_current_thread_clear_error();
679 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps
*maps
)
681 bt_trace_class_remove_listener_status status
;
687 if (maps
->stream_class_map
) {
688 g_hash_table_destroy(maps
->stream_class_map
);
691 if (maps
->event_class_map
) {
692 g_hash_table_destroy(maps
->event_class_map
);
695 if (maps
->field_class_map
) {
696 g_hash_table_destroy(maps
->field_class_map
);
699 if (maps
->clock_class_map
) {
700 g_hash_table_destroy(maps
->clock_class_map
);
703 g_free(maps
->fc_resolving_ctx
);
705 if (maps
->output_trace_class
) {
706 bt_trace_class_put_ref(maps
->output_trace_class
);
709 status
= bt_trace_class_remove_destruction_listener(
710 maps
->input_trace_class
, maps
->destruction_listener_id
);
711 if (status
!= BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
) {
712 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
714 "Trace destruction listener removal failed.");
715 bt_current_thread_clear_error();
721 void trace_ir_maps_clear(struct trace_ir_maps
*maps
)
723 if (maps
->data_maps
) {
724 g_hash_table_remove_all(maps
->data_maps
);
727 if (maps
->metadata_maps
) {
728 g_hash_table_remove_all(maps
->metadata_maps
);
733 void trace_ir_maps_destroy(struct trace_ir_maps
*maps
)
739 g_free(maps
->debug_info_field_class_name
);
741 if (maps
->data_maps
) {
742 g_hash_table_destroy(maps
->data_maps
);
743 maps
->data_maps
= NULL
;
746 if (maps
->metadata_maps
) {
747 g_hash_table_destroy(maps
->metadata_maps
);
748 maps
->metadata_maps
= NULL
;
755 struct trace_ir_maps
*trace_ir_maps_create(bt_self_component
*self_comp
,
756 const char *debug_info_field_name
, bt_logging_level log_level
)
758 struct trace_ir_maps
*ir_maps
= g_new0(struct trace_ir_maps
, 1);
760 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
761 "Error allocating trace_ir_maps");
765 ir_maps
->log_level
= log_level
;
766 ir_maps
->self_comp
= self_comp
;
768 /* Copy debug info field name received from the user. */
769 ir_maps
->debug_info_field_class_name
= g_strdup(debug_info_field_name
);
770 if (!ir_maps
->debug_info_field_class_name
) {
771 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
772 "Cannot copy debug info field name");
776 ir_maps
->self_comp
= self_comp
;
778 ir_maps
->data_maps
= g_hash_table_new_full(g_direct_hash
,
779 g_direct_equal
, (GDestroyNotify
) NULL
,
780 (GDestroyNotify
) trace_ir_data_maps_destroy
);
782 ir_maps
->metadata_maps
= g_hash_table_new_full(g_direct_hash
,
783 g_direct_equal
, (GDestroyNotify
) NULL
,
784 (GDestroyNotify
) trace_ir_metadata_maps_destroy
);
788 trace_ir_maps_destroy(ir_maps
);