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>
35 /* For bt_property_availability */
36 #include <babeltrace2/property.h>
38 #include "debug-info.h"
39 #include "trace-ir-data-copy.h"
40 #include "trace-ir-mapping.h"
41 #include "trace-ir-metadata-copy.h"
44 bt_trace_class
*create_new_mapped_trace_class(struct trace_ir_maps
*ir_maps
,
45 const bt_trace_class
*in_trace_class
)
47 bt_self_component
*self_comp
= ir_maps
->self_comp
;
48 enum debug_info_trace_ir_mapping_status status
;
49 struct trace_ir_metadata_maps
*metadata_maps
;
51 BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class
);
54 BT_ASSERT(in_trace_class
);
56 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
59 BT_ASSERT(!metadata_maps
->output_trace_class
);
61 /* Create the ouput trace class. */
62 metadata_maps
->output_trace_class
=
63 bt_trace_class_create(ir_maps
->self_comp
);
64 if (!metadata_maps
->output_trace_class
) {
65 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
66 "Error create output trace class");
70 /* Copy the content over and add to the mapping. */
71 status
= copy_trace_class_content(ir_maps
, in_trace_class
,
72 metadata_maps
->output_trace_class
, ir_maps
->log_level
,
74 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
75 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
76 "Error copy content to output trace class"
77 "in-tc-addr=%p, out-tc-addr=%p", in_trace_class
,
78 metadata_maps
->output_trace_class
);
82 BT_COMP_LOGD("Created new mapped trace class: "
83 "in-tc-addr=%p, out-tc-addr=%p",
84 in_trace_class
, metadata_maps
->output_trace_class
);
88 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps
->output_trace_class
);
90 return metadata_maps
->output_trace_class
;
94 bt_trace
*create_new_mapped_trace(struct trace_ir_maps
*ir_maps
,
95 const bt_trace
*in_trace
)
97 bt_self_component
*self_comp
= ir_maps
->self_comp
;
98 enum debug_info_trace_ir_mapping_status status
;
99 struct trace_ir_metadata_maps
*metadata_maps
;
100 const bt_trace_class
*in_trace_class
;
103 BT_COMP_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace
);
107 in_trace_class
= bt_trace_borrow_class_const(in_trace
);
108 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
111 if (!metadata_maps
->output_trace_class
) {
113 * If there is no output trace class yet, create a one and add
116 metadata_maps
->output_trace_class
=
117 create_new_mapped_trace_class(ir_maps
, in_trace_class
);
118 if (!metadata_maps
->output_trace_class
) {
119 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
120 "Error create output trace class");
126 /* Create the output trace from the output trace class. */
127 out_trace
= bt_trace_create(metadata_maps
->output_trace_class
);
129 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
130 "Error create output trace");
134 /* Copy the content over to the output trace. */
135 status
= copy_trace_content(in_trace
, out_trace
, ir_maps
->log_level
,
137 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
138 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
139 "Error copy content to output trace"
140 "in-t-addr=%p, out-t-addr=%p", in_trace
, out_trace
);
144 BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
145 in_trace
, out_trace
);
149 BT_TRACE_PUT_REF_AND_RESET(out_trace
);
155 bt_stream_class
*trace_ir_mapping_borrow_mapped_stream_class(
156 struct trace_ir_maps
*ir_maps
,
157 const bt_stream_class
*in_stream_class
)
159 BT_ASSERT_DBG(ir_maps
);
160 BT_ASSERT_DBG(in_stream_class
);
162 struct trace_ir_metadata_maps
*md_maps
=
163 borrow_metadata_maps_from_input_stream_class(ir_maps
,
165 return g_hash_table_lookup(md_maps
->stream_class_map
,
166 (gpointer
) in_stream_class
);
170 bt_stream_class
*trace_ir_mapping_create_new_mapped_stream_class(
171 struct trace_ir_maps
*ir_maps
,
172 const bt_stream_class
*in_stream_class
)
174 bt_self_component
*self_comp
= ir_maps
->self_comp
;
175 enum debug_info_trace_ir_mapping_status status
;
176 struct trace_ir_metadata_maps
*md_maps
;
177 bt_stream_class
*out_stream_class
;
179 BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p",
183 BT_ASSERT(in_stream_class
);
184 BT_ASSERT(!trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
187 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
192 /* Create the output stream class. */
193 out_stream_class
= bt_stream_class_create_with_id(
194 md_maps
->output_trace_class
,
195 bt_stream_class_get_id(in_stream_class
));
196 if (!out_stream_class
) {
197 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
198 "Error create output stream class");
202 /* Add it to the mapping. The mapping now owns out_stream_class. */
203 g_hash_table_insert(md_maps
->stream_class_map
,
204 (gpointer
) in_stream_class
, out_stream_class
);
206 /* Copy the content over to the output stream class. */
207 status
= copy_stream_class_content(ir_maps
, in_stream_class
,
209 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
210 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
211 "Error copy content to output stream class: "
212 "in-sc-addr=%p, out-sc-addr=%p", in_stream_class
,
217 BT_COMP_LOGD("Created new mapped stream class: "
218 "in-sc-addr=%p, out-sc-addr=%p",
219 in_stream_class
, out_stream_class
);
223 out_stream_class
= NULL
;
225 return out_stream_class
;
229 bt_stream
*borrow_mapped_stream(struct trace_ir_data_maps
*d_maps
,
230 const bt_stream
*in_stream
)
232 BT_ASSERT_DBG(d_maps
);
233 BT_ASSERT_DBG(in_stream
);
235 return g_hash_table_lookup(d_maps
->stream_map
, (gpointer
) in_stream
);
239 bt_stream
*trace_ir_mapping_create_new_mapped_stream(
240 struct trace_ir_maps
*ir_maps
, const bt_stream
*in_stream
)
242 bt_self_component
*self_comp
= ir_maps
->self_comp
;
243 enum debug_info_trace_ir_mapping_status status
;
244 struct trace_ir_data_maps
*d_maps
;
245 const bt_stream_class
*in_stream_class
;
246 const bt_trace
*in_trace
;
247 bt_stream_class
*out_stream_class
;
248 bt_stream
*out_stream
= NULL
;
251 BT_ASSERT(in_stream
);
252 BT_COMP_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream
);
254 in_trace
= bt_stream_borrow_trace_const(in_stream
);
256 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
257 if (!d_maps
->output_trace
) {
258 /* Create the output trace for this input trace. */
259 d_maps
->output_trace
= create_new_mapped_trace(ir_maps
, in_trace
);
260 if (!d_maps
->output_trace
) {
261 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
262 "Error creating mapped trace");
267 BT_ASSERT(d_maps
->output_trace
);
268 BT_ASSERT(!borrow_mapped_stream(d_maps
, in_stream
));
270 in_stream_class
= bt_stream_borrow_class_const(in_stream
);
271 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
274 if (!out_stream_class
) {
275 /* Create the output stream class for this input stream class. */
276 out_stream_class
= trace_ir_mapping_create_new_mapped_stream_class(
277 ir_maps
, in_stream_class
);
278 if (!out_stream_class
) {
279 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
280 "Error creating mapped stream class");
284 BT_ASSERT(out_stream_class
);
286 /* Create the output stream for this input stream. */
287 out_stream
= bt_stream_create_with_id(out_stream_class
,
288 d_maps
->output_trace
, bt_stream_get_id(in_stream
));
290 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
291 "Error creating output stream");
295 /* Add it to the mapping. The mapping now owns out_stream.*/
296 g_hash_table_insert(d_maps
->stream_map
, (gpointer
) in_stream
,
299 /* Copy the content over to the output stream. */
300 status
= copy_stream_content(in_stream
, out_stream
, ir_maps
->log_level
,
302 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
303 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
304 "Error copy content to output stream: "
305 "in-s-addr=%p, out-s-addr=%p", in_stream
, out_stream
);
309 BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
310 in_stream
, out_stream
);
320 bt_stream
*trace_ir_mapping_borrow_mapped_stream(struct trace_ir_maps
*ir_maps
,
321 const bt_stream
*in_stream
)
323 struct trace_ir_data_maps
*d_maps
;
325 BT_ASSERT_DBG(ir_maps
);
326 BT_ASSERT_DBG(in_stream
);
328 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
329 /* Return the mapped stream. */
330 return borrow_mapped_stream(d_maps
, in_stream
);
334 bt_event_class
*borrow_mapped_event_class(struct trace_ir_metadata_maps
*md_maps
,
335 const bt_event_class
*in_event_class
)
337 return g_hash_table_lookup(md_maps
->event_class_map
,
338 (gpointer
) in_event_class
);
342 bt_event_class
*trace_ir_mapping_create_new_mapped_event_class(
343 struct trace_ir_maps
*ir_maps
,
344 const bt_event_class
*in_event_class
)
346 bt_self_component
*self_comp
= ir_maps
->self_comp
;
347 enum debug_info_trace_ir_mapping_status status
;
348 struct trace_ir_metadata_maps
*md_maps
;
349 const bt_stream_class
*in_stream_class
;
350 bt_stream_class
*out_stream_class
;
351 bt_event_class
*out_event_class
;
353 BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p",
357 BT_ASSERT(in_event_class
);
359 in_stream_class
= bt_event_class_borrow_stream_class_const(in_event_class
);
361 BT_ASSERT(in_stream_class
);
363 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
367 BT_ASSERT(!borrow_mapped_event_class(md_maps
, in_event_class
));
369 /* Get the right output stream class to add the new event class to it. */
370 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(
371 ir_maps
, in_stream_class
);
372 BT_ASSERT(out_stream_class
);
374 /* Create an output event class. */
375 out_event_class
= bt_event_class_create_with_id(out_stream_class
,
376 bt_event_class_get_id(in_event_class
));
377 if (!out_event_class
) {
378 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
379 "Error creating output event class");
383 /* Add it to the mapping. The mapping now owns out_event_class. */
384 g_hash_table_insert(md_maps
->event_class_map
, (gpointer
) in_event_class
,
387 /* Copy the content over to the output event class. */
388 status
= copy_event_class_content(ir_maps
, in_event_class
,
390 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
391 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
392 "Error copy content to output event class: "
393 "in-ec-addr=%p, out-ec-addr=%p", in_event_class
,
398 BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
399 in_event_class
, out_event_class
);
403 out_event_class
= NULL
;
405 return out_event_class
;
409 bt_event_class
*trace_ir_mapping_borrow_mapped_event_class(
410 struct trace_ir_maps
*ir_maps
,
411 const bt_event_class
*in_event_class
)
413 struct trace_ir_metadata_maps
*md_maps
;
415 BT_ASSERT_DBG(ir_maps
);
416 BT_ASSERT_DBG(in_event_class
);
418 md_maps
= borrow_metadata_maps_from_input_event_class(ir_maps
,
421 /* Return the mapped event_class. */
422 return borrow_mapped_event_class(md_maps
, in_event_class
);
426 bt_packet
*borrow_mapped_packet(struct trace_ir_data_maps
*d_maps
,
427 const bt_packet
*in_packet
)
429 BT_ASSERT_DBG(d_maps
);
430 BT_ASSERT_DBG(in_packet
);
432 return g_hash_table_lookup(d_maps
->packet_map
, (gpointer
) in_packet
);
436 bt_packet
*trace_ir_mapping_create_new_mapped_packet(
437 struct trace_ir_maps
*ir_maps
,
438 const bt_packet
*in_packet
)
440 bt_self_component
*self_comp
= ir_maps
->self_comp
;
441 enum debug_info_trace_ir_mapping_status status
;
442 struct trace_ir_data_maps
*d_maps
;
443 const bt_stream
*in_stream
;
444 const bt_trace
*in_trace
;
445 bt_packet
*out_packet
;
446 bt_stream
*out_stream
;
448 BT_COMP_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet
);
450 in_stream
= bt_packet_borrow_stream_const(in_packet
);
451 in_trace
= bt_stream_borrow_trace_const(in_stream
);
452 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
454 /* There should never be a mapped packet already. */
455 BT_ASSERT(!borrow_mapped_packet(d_maps
, in_packet
));
456 BT_ASSERT(in_stream
);
458 /* Get output stream corresponding to this input stream. */
459 out_stream
= borrow_mapped_stream(d_maps
, in_stream
);
460 BT_ASSERT(out_stream
);
462 /* Create the output packet. */
463 out_packet
= bt_packet_create(out_stream
);
465 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
466 "Error create output packet");
470 /* Add it to the mapping. The mapping now owns out_packet. */
471 g_hash_table_insert(d_maps
->packet_map
, (gpointer
) in_packet
,
474 /* Copy the content over to the output packet. */
475 status
= copy_packet_content(in_packet
, out_packet
, ir_maps
->log_level
,
477 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
478 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
479 "Error copy content to output packet: "
480 "in-p-addr=%p, out-p-addr=%p", in_packet
, out_packet
);
484 BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
485 in_packet
, out_packet
);
495 bt_packet
*trace_ir_mapping_borrow_mapped_packet(struct trace_ir_maps
*ir_maps
,
496 const bt_packet
*in_packet
)
498 struct trace_ir_data_maps
*d_maps
;
499 BT_ASSERT_DBG(ir_maps
);
500 BT_ASSERT_DBG(in_packet
);
502 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
504 return borrow_mapped_packet(d_maps
, in_packet
);
508 void trace_ir_mapping_remove_mapped_packet(struct trace_ir_maps
*ir_maps
,
509 const bt_packet
*in_packet
)
511 struct trace_ir_data_maps
*d_maps
;
515 BT_ASSERT(in_packet
);
517 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
519 ret
= g_hash_table_remove(d_maps
->packet_map
, in_packet
);
525 void trace_ir_mapping_remove_mapped_stream(struct trace_ir_maps
*ir_maps
,
526 const bt_stream
*in_stream
)
528 struct trace_ir_data_maps
*d_maps
;
532 BT_ASSERT(in_stream
);
534 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
536 ret
= g_hash_table_remove(d_maps
->stream_map
, in_stream
);
542 void trace_ir_metadata_maps_remove_func(const bt_trace_class
*in_trace_class
,
545 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
546 if (maps
->metadata_maps
) {
548 ret
= g_hash_table_remove(maps
->metadata_maps
,
549 (gpointer
) in_trace_class
);
555 void trace_ir_data_maps_remove_func(const bt_trace
*in_trace
, void *data
)
557 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
558 if (maps
->data_maps
) {
560 ret
= g_hash_table_remove(maps
->data_maps
, (gpointer
) in_trace
);
565 struct trace_ir_data_maps
*trace_ir_data_maps_create(struct trace_ir_maps
*ir_maps
,
566 const bt_trace
*in_trace
)
568 bt_self_component
*self_comp
= ir_maps
->self_comp
;
569 bt_trace_add_listener_status add_listener_status
;
570 struct trace_ir_data_maps
*d_maps
= g_new0(struct trace_ir_data_maps
, 1);
573 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
574 "Error allocating trace_ir_maps");
578 d_maps
->log_level
= ir_maps
->log_level
;
579 d_maps
->self_comp
= ir_maps
->self_comp
;
580 d_maps
->input_trace
= in_trace
;
582 /* Create the hashtables used to map data objects. */
583 d_maps
->stream_map
= g_hash_table_new_full(g_direct_hash
,
584 g_direct_equal
, NULL
,(GDestroyNotify
) bt_stream_put_ref
);
585 d_maps
->packet_map
= g_hash_table_new_full(g_direct_hash
,
586 g_direct_equal
, NULL
,(GDestroyNotify
) bt_packet_put_ref
);
588 add_listener_status
= bt_trace_add_destruction_listener(
589 in_trace
, trace_ir_data_maps_remove_func
,
590 ir_maps
, &d_maps
->destruction_listener_id
);
591 BT_ASSERT(add_listener_status
== BT_TRACE_ADD_LISTENER_STATUS_OK
);
597 struct trace_ir_metadata_maps
*trace_ir_metadata_maps_create(
598 struct trace_ir_maps
*ir_maps
,
599 const bt_trace_class
*in_trace_class
)
601 bt_self_component
*self_comp
= ir_maps
->self_comp
;
602 bt_trace_class_add_listener_status add_listener_status
;
603 struct trace_ir_metadata_maps
*md_maps
=
604 g_new0(struct trace_ir_metadata_maps
, 1);
607 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
608 "Error allocating trace_ir_maps");
612 md_maps
->log_level
= ir_maps
->log_level
;
613 md_maps
->self_comp
= ir_maps
->self_comp
;
614 md_maps
->input_trace_class
= in_trace_class
;
616 * Create the field class resolving context. This is needed to keep
617 * track of the field class already copied in order to do the field
618 * path resolution correctly.
620 md_maps
->fc_resolving_ctx
=
621 g_new0(struct field_class_resolving_context
, 1);
622 if (!md_maps
->fc_resolving_ctx
) {
623 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
624 "Error allocating field_class_resolving_context");
628 /* Create the hashtables used to map metadata objects. */
629 md_maps
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
630 g_direct_equal
, NULL
, (GDestroyNotify
) bt_stream_class_put_ref
);
631 md_maps
->event_class_map
= g_hash_table_new_full(g_direct_hash
,
632 g_direct_equal
, NULL
, (GDestroyNotify
) bt_event_class_put_ref
);
633 md_maps
->field_class_map
= g_hash_table_new_full(g_direct_hash
,
634 g_direct_equal
, NULL
, (GDestroyNotify
) bt_field_class_put_ref
);
635 md_maps
->clock_class_map
= g_hash_table_new_full(g_direct_hash
,
636 g_direct_equal
, NULL
, (GDestroyNotify
) bt_clock_class_put_ref
);
638 add_listener_status
= bt_trace_class_add_destruction_listener(
639 in_trace_class
, trace_ir_metadata_maps_remove_func
,
640 ir_maps
, &md_maps
->destruction_listener_id
);
641 BT_ASSERT(add_listener_status
== BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
);
648 void trace_ir_data_maps_destroy(struct trace_ir_data_maps
*maps
)
650 bt_trace_remove_listener_status status
;
656 if (maps
->packet_map
) {
657 g_hash_table_destroy(maps
->packet_map
);
660 if (maps
->stream_map
) {
661 g_hash_table_destroy(maps
->stream_map
);
664 if (maps
->output_trace
) {
665 bt_trace_put_ref(maps
->output_trace
);
668 status
= bt_trace_remove_destruction_listener(maps
->input_trace
,
669 maps
->destruction_listener_id
);
670 if (status
!= BT_TRACE_REMOVE_LISTENER_STATUS_OK
) {
671 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
673 "Trace destruction listener removal failed.");
674 bt_current_thread_clear_error();
681 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps
*maps
)
683 bt_trace_class_remove_listener_status status
;
689 if (maps
->stream_class_map
) {
690 g_hash_table_destroy(maps
->stream_class_map
);
693 if (maps
->event_class_map
) {
694 g_hash_table_destroy(maps
->event_class_map
);
697 if (maps
->field_class_map
) {
698 g_hash_table_destroy(maps
->field_class_map
);
701 if (maps
->clock_class_map
) {
702 g_hash_table_destroy(maps
->clock_class_map
);
705 g_free(maps
->fc_resolving_ctx
);
707 if (maps
->output_trace_class
) {
708 bt_trace_class_put_ref(maps
->output_trace_class
);
711 status
= bt_trace_class_remove_destruction_listener(
712 maps
->input_trace_class
, maps
->destruction_listener_id
);
713 if (status
!= BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
) {
714 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
716 "Trace destruction listener removal failed.");
717 bt_current_thread_clear_error();
723 void trace_ir_maps_clear(struct trace_ir_maps
*maps
)
725 if (maps
->data_maps
) {
726 g_hash_table_remove_all(maps
->data_maps
);
729 if (maps
->metadata_maps
) {
730 g_hash_table_remove_all(maps
->metadata_maps
);
735 void trace_ir_maps_destroy(struct trace_ir_maps
*maps
)
741 g_free(maps
->debug_info_field_class_name
);
743 if (maps
->data_maps
) {
744 g_hash_table_destroy(maps
->data_maps
);
745 maps
->data_maps
= NULL
;
748 if (maps
->metadata_maps
) {
749 g_hash_table_destroy(maps
->metadata_maps
);
750 maps
->metadata_maps
= NULL
;
757 struct trace_ir_maps
*trace_ir_maps_create(bt_self_component
*self_comp
,
758 const char *debug_info_field_name
, bt_logging_level log_level
)
760 struct trace_ir_maps
*ir_maps
= g_new0(struct trace_ir_maps
, 1);
762 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
763 "Error allocating trace_ir_maps");
767 ir_maps
->log_level
= log_level
;
768 ir_maps
->self_comp
= self_comp
;
770 /* Copy debug info field name received from the user. */
771 ir_maps
->debug_info_field_class_name
= g_strdup(debug_info_field_name
);
772 if (!ir_maps
->debug_info_field_class_name
) {
773 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
774 "Cannot copy debug info field name");
778 ir_maps
->self_comp
= self_comp
;
780 ir_maps
->data_maps
= g_hash_table_new_full(g_direct_hash
,
781 g_direct_equal
, (GDestroyNotify
) NULL
,
782 (GDestroyNotify
) trace_ir_data_maps_destroy
);
784 ir_maps
->metadata_maps
= g_hash_table_new_full(g_direct_hash
,
785 g_direct_equal
, (GDestroyNotify
) NULL
,
786 (GDestroyNotify
) trace_ir_metadata_maps_destroy
);
790 trace_ir_maps_destroy(ir_maps
);