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"
35 #include "common/assert.h"
36 #include <babeltrace2/babeltrace.h>
37 /* For bt_property_availability */
38 #include <babeltrace2/property.h>
40 #include "debug-info.h"
41 #include "trace-ir-data-copy.h"
42 #include "trace-ir-mapping.h"
43 #include "trace-ir-metadata-copy.h"
46 bt_trace_class
*create_new_mapped_trace_class(struct trace_ir_maps
*ir_maps
,
47 const bt_trace_class
*in_trace_class
)
49 bt_self_component
*self_comp
= ir_maps
->self_comp
;
50 enum debug_info_trace_ir_mapping_status status
;
51 struct trace_ir_metadata_maps
*metadata_maps
;
53 BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class
);
56 BT_ASSERT(in_trace_class
);
58 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
61 BT_ASSERT(!metadata_maps
->output_trace_class
);
63 /* Create the ouput trace class. */
64 metadata_maps
->output_trace_class
=
65 bt_trace_class_create(ir_maps
->self_comp
);
66 if (!metadata_maps
->output_trace_class
) {
67 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
68 "Error create output trace class");
72 /* Copy the content over and add to the mapping. */
73 status
= copy_trace_class_content(ir_maps
, in_trace_class
,
74 metadata_maps
->output_trace_class
, ir_maps
->log_level
,
76 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
77 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
78 "Error copy content to output trace class"
79 "in-tc-addr=%p, out-tc-addr=%p", in_trace_class
,
80 metadata_maps
->output_trace_class
);
84 BT_COMP_LOGD("Created new mapped trace class: "
85 "in-tc-addr=%p, out-tc-addr=%p",
86 in_trace_class
, metadata_maps
->output_trace_class
);
90 BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps
->output_trace_class
);
92 return metadata_maps
->output_trace_class
;
96 bt_trace
*create_new_mapped_trace(struct trace_ir_maps
*ir_maps
,
97 const bt_trace
*in_trace
)
99 bt_self_component
*self_comp
= ir_maps
->self_comp
;
100 enum debug_info_trace_ir_mapping_status status
;
101 struct trace_ir_metadata_maps
*metadata_maps
;
102 const bt_trace_class
*in_trace_class
;
105 BT_COMP_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace
);
109 in_trace_class
= bt_trace_borrow_class_const(in_trace
);
110 metadata_maps
= borrow_metadata_maps_from_input_trace_class(ir_maps
,
113 if (!metadata_maps
->output_trace_class
) {
115 * If there is no output trace class yet, create a one and add
118 metadata_maps
->output_trace_class
=
119 create_new_mapped_trace_class(ir_maps
, in_trace_class
);
120 if (!metadata_maps
->output_trace_class
) {
121 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
122 "Error create output trace class");
128 /* Create the output trace from the output trace class. */
129 out_trace
= bt_trace_create(metadata_maps
->output_trace_class
);
131 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
132 "Error create output trace");
136 /* Copy the content over to the output trace. */
137 status
= copy_trace_content(in_trace
, out_trace
, ir_maps
->log_level
,
139 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
140 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
141 "Error copy content to output trace"
142 "in-t-addr=%p, out-t-addr=%p", in_trace
, out_trace
);
146 BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
147 in_trace
, out_trace
);
151 BT_TRACE_PUT_REF_AND_RESET(out_trace
);
157 bt_stream_class
*trace_ir_mapping_borrow_mapped_stream_class(
158 struct trace_ir_maps
*ir_maps
,
159 const bt_stream_class
*in_stream_class
)
161 BT_ASSERT_DBG(ir_maps
);
162 BT_ASSERT_DBG(in_stream_class
);
164 struct trace_ir_metadata_maps
*md_maps
=
165 borrow_metadata_maps_from_input_stream_class(ir_maps
,
167 return g_hash_table_lookup(md_maps
->stream_class_map
,
168 (gpointer
) in_stream_class
);
172 bt_stream_class
*trace_ir_mapping_create_new_mapped_stream_class(
173 struct trace_ir_maps
*ir_maps
,
174 const bt_stream_class
*in_stream_class
)
176 bt_self_component
*self_comp
= ir_maps
->self_comp
;
177 enum debug_info_trace_ir_mapping_status status
;
178 struct trace_ir_metadata_maps
*md_maps
;
179 bt_stream_class
*out_stream_class
;
181 BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p",
185 BT_ASSERT(in_stream_class
);
186 BT_ASSERT(!trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
189 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
194 /* Create the output stream class. */
195 out_stream_class
= bt_stream_class_create_with_id(
196 md_maps
->output_trace_class
,
197 bt_stream_class_get_id(in_stream_class
));
198 if (!out_stream_class
) {
199 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
200 "Error create output stream class");
204 /* Add it to the mapping. The mapping now owns out_stream_class. */
205 g_hash_table_insert(md_maps
->stream_class_map
,
206 (gpointer
) in_stream_class
, out_stream_class
);
208 /* Copy the content over to the output stream class. */
209 status
= copy_stream_class_content(ir_maps
, in_stream_class
,
211 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
212 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
213 "Error copy content to output stream class: "
214 "in-sc-addr=%p, out-sc-addr=%p", in_stream_class
,
219 BT_COMP_LOGD("Created new mapped stream class: "
220 "in-sc-addr=%p, out-sc-addr=%p",
221 in_stream_class
, out_stream_class
);
225 out_stream_class
= NULL
;
227 return out_stream_class
;
231 bt_stream
*borrow_mapped_stream(struct trace_ir_data_maps
*d_maps
,
232 const bt_stream
*in_stream
)
234 BT_ASSERT_DBG(d_maps
);
235 BT_ASSERT_DBG(in_stream
);
237 return g_hash_table_lookup(d_maps
->stream_map
, (gpointer
) in_stream
);
241 bt_stream
*trace_ir_mapping_create_new_mapped_stream(
242 struct trace_ir_maps
*ir_maps
, const bt_stream
*in_stream
)
244 bt_self_component
*self_comp
= ir_maps
->self_comp
;
245 enum debug_info_trace_ir_mapping_status status
;
246 struct trace_ir_data_maps
*d_maps
;
247 const bt_stream_class
*in_stream_class
;
248 const bt_trace
*in_trace
;
249 bt_stream_class
*out_stream_class
;
250 bt_stream
*out_stream
= NULL
;
253 BT_ASSERT(in_stream
);
254 BT_COMP_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream
);
256 in_trace
= bt_stream_borrow_trace_const(in_stream
);
258 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
259 if (!d_maps
->output_trace
) {
260 /* Create the output trace for this input trace. */
261 d_maps
->output_trace
= create_new_mapped_trace(ir_maps
, in_trace
);
262 if (!d_maps
->output_trace
) {
263 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
264 "Error creating mapped trace");
269 BT_ASSERT(d_maps
->output_trace
);
270 BT_ASSERT(!borrow_mapped_stream(d_maps
, in_stream
));
272 in_stream_class
= bt_stream_borrow_class_const(in_stream
);
273 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(ir_maps
,
276 if (!out_stream_class
) {
277 /* Create the output stream class for this input stream class. */
278 out_stream_class
= trace_ir_mapping_create_new_mapped_stream_class(
279 ir_maps
, in_stream_class
);
280 if (!out_stream_class
) {
281 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
282 "Error creating mapped stream class");
286 BT_ASSERT(out_stream_class
);
288 /* Create the output stream for this input stream. */
289 out_stream
= bt_stream_create_with_id(out_stream_class
,
290 d_maps
->output_trace
, bt_stream_get_id(in_stream
));
292 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
293 "Error creating output stream");
297 /* Add it to the mapping. The mapping now owns out_stream.*/
298 g_hash_table_insert(d_maps
->stream_map
, (gpointer
) in_stream
,
301 /* Copy the content over to the output stream. */
302 status
= copy_stream_content(in_stream
, out_stream
, ir_maps
->log_level
,
304 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
305 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
306 "Error copy content to output stream: "
307 "in-s-addr=%p, out-s-addr=%p", in_stream
, out_stream
);
311 BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
312 in_stream
, out_stream
);
322 bt_stream
*trace_ir_mapping_borrow_mapped_stream(struct trace_ir_maps
*ir_maps
,
323 const bt_stream
*in_stream
)
325 struct trace_ir_data_maps
*d_maps
;
327 BT_ASSERT_DBG(ir_maps
);
328 BT_ASSERT_DBG(in_stream
);
330 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
331 /* Return the mapped stream. */
332 return borrow_mapped_stream(d_maps
, in_stream
);
336 bt_event_class
*borrow_mapped_event_class(struct trace_ir_metadata_maps
*md_maps
,
337 const bt_event_class
*in_event_class
)
339 return g_hash_table_lookup(md_maps
->event_class_map
,
340 (gpointer
) in_event_class
);
344 bt_event_class
*trace_ir_mapping_create_new_mapped_event_class(
345 struct trace_ir_maps
*ir_maps
,
346 const bt_event_class
*in_event_class
)
348 bt_self_component
*self_comp
= ir_maps
->self_comp
;
349 enum debug_info_trace_ir_mapping_status status
;
350 struct trace_ir_metadata_maps
*md_maps
;
351 const bt_stream_class
*in_stream_class
;
352 bt_stream_class
*out_stream_class
;
353 bt_event_class
*out_event_class
;
355 BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p",
359 BT_ASSERT(in_event_class
);
361 in_stream_class
= bt_event_class_borrow_stream_class_const(in_event_class
);
363 BT_ASSERT(in_stream_class
);
365 md_maps
= borrow_metadata_maps_from_input_stream_class(ir_maps
,
369 BT_ASSERT(!borrow_mapped_event_class(md_maps
, in_event_class
));
371 /* Get the right output stream class to add the new event class to it. */
372 out_stream_class
= trace_ir_mapping_borrow_mapped_stream_class(
373 ir_maps
, in_stream_class
);
374 BT_ASSERT(out_stream_class
);
376 /* Create an output event class. */
377 out_event_class
= bt_event_class_create_with_id(out_stream_class
,
378 bt_event_class_get_id(in_event_class
));
379 if (!out_event_class
) {
380 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
381 "Error creating output event class");
385 /* Add it to the mapping. The mapping now owns out_event_class. */
386 g_hash_table_insert(md_maps
->event_class_map
, (gpointer
) in_event_class
,
389 /* Copy the content over to the output event class. */
390 status
= copy_event_class_content(ir_maps
, in_event_class
,
392 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
393 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
394 "Error copy content to output event class: "
395 "in-ec-addr=%p, out-ec-addr=%p", in_event_class
,
400 BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
401 in_event_class
, out_event_class
);
405 out_event_class
= NULL
;
407 return out_event_class
;
411 bt_event_class
*trace_ir_mapping_borrow_mapped_event_class(
412 struct trace_ir_maps
*ir_maps
,
413 const bt_event_class
*in_event_class
)
415 struct trace_ir_metadata_maps
*md_maps
;
417 BT_ASSERT_DBG(ir_maps
);
418 BT_ASSERT_DBG(in_event_class
);
420 md_maps
= borrow_metadata_maps_from_input_event_class(ir_maps
,
423 /* Return the mapped event_class. */
424 return borrow_mapped_event_class(md_maps
, in_event_class
);
428 bt_packet
*borrow_mapped_packet(struct trace_ir_data_maps
*d_maps
,
429 const bt_packet
*in_packet
)
431 BT_ASSERT_DBG(d_maps
);
432 BT_ASSERT_DBG(in_packet
);
434 return g_hash_table_lookup(d_maps
->packet_map
, (gpointer
) in_packet
);
438 bt_packet
*trace_ir_mapping_create_new_mapped_packet(
439 struct trace_ir_maps
*ir_maps
,
440 const bt_packet
*in_packet
)
442 bt_self_component
*self_comp
= ir_maps
->self_comp
;
443 enum debug_info_trace_ir_mapping_status status
;
444 struct trace_ir_data_maps
*d_maps
;
445 const bt_stream
*in_stream
;
446 const bt_trace
*in_trace
;
447 bt_packet
*out_packet
;
448 bt_stream
*out_stream
;
450 BT_COMP_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet
);
452 in_stream
= bt_packet_borrow_stream_const(in_packet
);
453 in_trace
= bt_stream_borrow_trace_const(in_stream
);
454 d_maps
= borrow_data_maps_from_input_trace(ir_maps
, in_trace
);
456 /* There should never be a mapped packet already. */
457 BT_ASSERT(!borrow_mapped_packet(d_maps
, in_packet
));
458 BT_ASSERT(in_stream
);
460 /* Get output stream corresponding to this input stream. */
461 out_stream
= borrow_mapped_stream(d_maps
, in_stream
);
462 BT_ASSERT(out_stream
);
464 /* Create the output packet. */
465 out_packet
= bt_packet_create(out_stream
);
467 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
468 "Error create output packet");
472 /* Add it to the mapping. The mapping now owns out_packet. */
473 g_hash_table_insert(d_maps
->packet_map
, (gpointer
) in_packet
,
476 /* Copy the content over to the output packet. */
477 status
= copy_packet_content(in_packet
, out_packet
, ir_maps
->log_level
,
479 if (status
!= DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK
) {
480 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
481 "Error copy content to output packet: "
482 "in-p-addr=%p, out-p-addr=%p", in_packet
, out_packet
);
486 BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
487 in_packet
, out_packet
);
497 bt_packet
*trace_ir_mapping_borrow_mapped_packet(struct trace_ir_maps
*ir_maps
,
498 const bt_packet
*in_packet
)
500 struct trace_ir_data_maps
*d_maps
;
501 BT_ASSERT_DBG(ir_maps
);
502 BT_ASSERT_DBG(in_packet
);
504 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
506 return borrow_mapped_packet(d_maps
, in_packet
);
510 void trace_ir_mapping_remove_mapped_packet(struct trace_ir_maps
*ir_maps
,
511 const bt_packet
*in_packet
)
513 struct trace_ir_data_maps
*d_maps
;
517 BT_ASSERT(in_packet
);
519 d_maps
= borrow_data_maps_from_input_packet(ir_maps
, in_packet
);
521 ret
= g_hash_table_remove(d_maps
->packet_map
, in_packet
);
527 void trace_ir_mapping_remove_mapped_stream(struct trace_ir_maps
*ir_maps
,
528 const bt_stream
*in_stream
)
530 struct trace_ir_data_maps
*d_maps
;
534 BT_ASSERT(in_stream
);
536 d_maps
= borrow_data_maps_from_input_stream(ir_maps
, in_stream
);
538 ret
= g_hash_table_remove(d_maps
->stream_map
, in_stream
);
544 void trace_ir_metadata_maps_remove_func(const bt_trace_class
*in_trace_class
,
547 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
548 if (maps
->metadata_maps
) {
550 ret
= g_hash_table_remove(maps
->metadata_maps
,
551 (gpointer
) in_trace_class
);
557 void trace_ir_data_maps_remove_func(const bt_trace
*in_trace
, void *data
)
559 struct trace_ir_maps
*maps
= (struct trace_ir_maps
*) data
;
560 if (maps
->data_maps
) {
562 ret
= g_hash_table_remove(maps
->data_maps
, (gpointer
) in_trace
);
567 struct trace_ir_data_maps
*trace_ir_data_maps_create(struct trace_ir_maps
*ir_maps
,
568 const bt_trace
*in_trace
)
570 bt_self_component
*self_comp
= ir_maps
->self_comp
;
571 bt_trace_add_listener_status add_listener_status
;
572 struct trace_ir_data_maps
*d_maps
= g_new0(struct trace_ir_data_maps
, 1);
575 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
576 "Error allocating trace_ir_maps");
580 d_maps
->log_level
= ir_maps
->log_level
;
581 d_maps
->self_comp
= ir_maps
->self_comp
;
582 d_maps
->input_trace
= in_trace
;
584 /* Create the hashtables used to map data objects. */
585 d_maps
->stream_map
= g_hash_table_new_full(g_direct_hash
,
586 g_direct_equal
, NULL
,(GDestroyNotify
) bt_stream_put_ref
);
587 d_maps
->packet_map
= g_hash_table_new_full(g_direct_hash
,
588 g_direct_equal
, NULL
,(GDestroyNotify
) bt_packet_put_ref
);
590 add_listener_status
= bt_trace_add_destruction_listener(
591 in_trace
, trace_ir_data_maps_remove_func
,
592 ir_maps
, &d_maps
->destruction_listener_id
);
593 BT_ASSERT(add_listener_status
== BT_TRACE_ADD_LISTENER_STATUS_OK
);
599 struct trace_ir_metadata_maps
*trace_ir_metadata_maps_create(
600 struct trace_ir_maps
*ir_maps
,
601 const bt_trace_class
*in_trace_class
)
603 bt_self_component
*self_comp
= ir_maps
->self_comp
;
604 bt_trace_class_add_listener_status add_listener_status
;
605 struct trace_ir_metadata_maps
*md_maps
=
606 g_new0(struct trace_ir_metadata_maps
, 1);
609 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
610 "Error allocating trace_ir_maps");
614 md_maps
->log_level
= ir_maps
->log_level
;
615 md_maps
->self_comp
= ir_maps
->self_comp
;
616 md_maps
->input_trace_class
= in_trace_class
;
618 * Create the field class resolving context. This is needed to keep
619 * track of the field class already copied in order to do the field
620 * path resolution correctly.
622 md_maps
->fc_resolving_ctx
=
623 g_new0(struct field_class_resolving_context
, 1);
624 if (!md_maps
->fc_resolving_ctx
) {
625 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
626 "Error allocating field_class_resolving_context");
630 /* Create the hashtables used to map metadata objects. */
631 md_maps
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
632 g_direct_equal
, NULL
, (GDestroyNotify
) bt_stream_class_put_ref
);
633 md_maps
->event_class_map
= g_hash_table_new_full(g_direct_hash
,
634 g_direct_equal
, NULL
, (GDestroyNotify
) bt_event_class_put_ref
);
635 md_maps
->field_class_map
= g_hash_table_new_full(g_direct_hash
,
636 g_direct_equal
, NULL
, (GDestroyNotify
) bt_field_class_put_ref
);
637 md_maps
->clock_class_map
= g_hash_table_new_full(g_direct_hash
,
638 g_direct_equal
, NULL
, (GDestroyNotify
) bt_clock_class_put_ref
);
640 add_listener_status
= bt_trace_class_add_destruction_listener(
641 in_trace_class
, trace_ir_metadata_maps_remove_func
,
642 ir_maps
, &md_maps
->destruction_listener_id
);
643 BT_ASSERT(add_listener_status
== BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK
);
650 void trace_ir_data_maps_destroy(struct trace_ir_data_maps
*maps
)
652 bt_trace_remove_listener_status status
;
658 if (maps
->packet_map
) {
659 g_hash_table_destroy(maps
->packet_map
);
662 if (maps
->stream_map
) {
663 g_hash_table_destroy(maps
->stream_map
);
666 if (maps
->output_trace
) {
667 bt_trace_put_ref(maps
->output_trace
);
670 status
= bt_trace_remove_destruction_listener(maps
->input_trace
,
671 maps
->destruction_listener_id
);
672 if (status
!= BT_TRACE_REMOVE_LISTENER_STATUS_OK
) {
673 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
675 "Trace destruction listener removal failed.");
676 bt_current_thread_clear_error();
683 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps
*maps
)
685 bt_trace_class_remove_listener_status status
;
691 if (maps
->stream_class_map
) {
692 g_hash_table_destroy(maps
->stream_class_map
);
695 if (maps
->event_class_map
) {
696 g_hash_table_destroy(maps
->event_class_map
);
699 if (maps
->field_class_map
) {
700 g_hash_table_destroy(maps
->field_class_map
);
703 if (maps
->clock_class_map
) {
704 g_hash_table_destroy(maps
->clock_class_map
);
707 g_free(maps
->fc_resolving_ctx
);
709 if (maps
->output_trace_class
) {
710 bt_trace_class_put_ref(maps
->output_trace_class
);
713 status
= bt_trace_class_remove_destruction_listener(
714 maps
->input_trace_class
, maps
->destruction_listener_id
);
715 if (status
!= BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK
) {
716 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG
, maps
->log_level
,
718 "Trace destruction listener removal failed.");
719 bt_current_thread_clear_error();
725 void trace_ir_maps_clear(struct trace_ir_maps
*maps
)
727 if (maps
->data_maps
) {
728 g_hash_table_remove_all(maps
->data_maps
);
731 if (maps
->metadata_maps
) {
732 g_hash_table_remove_all(maps
->metadata_maps
);
737 void trace_ir_maps_destroy(struct trace_ir_maps
*maps
)
743 g_free(maps
->debug_info_field_class_name
);
745 if (maps
->data_maps
) {
746 g_hash_table_destroy(maps
->data_maps
);
747 maps
->data_maps
= NULL
;
750 if (maps
->metadata_maps
) {
751 g_hash_table_destroy(maps
->metadata_maps
);
752 maps
->metadata_maps
= NULL
;
759 struct trace_ir_maps
*trace_ir_maps_create(bt_self_component
*self_comp
,
760 const char *debug_info_field_name
, bt_logging_level log_level
)
762 struct trace_ir_maps
*ir_maps
= g_new0(struct trace_ir_maps
, 1);
764 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
765 "Error allocating trace_ir_maps");
769 ir_maps
->log_level
= log_level
;
770 ir_maps
->self_comp
= self_comp
;
772 /* Copy debug info field name received from the user. */
773 ir_maps
->debug_info_field_class_name
= g_strdup(debug_info_field_name
);
774 if (!ir_maps
->debug_info_field_class_name
) {
775 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
776 "Cannot copy debug info field name");
780 ir_maps
->self_comp
= self_comp
;
782 ir_maps
->data_maps
= g_hash_table_new_full(g_direct_hash
,
783 g_direct_equal
, (GDestroyNotify
) NULL
,
784 (GDestroyNotify
) trace_ir_data_maps_destroy
);
786 ir_maps
->metadata_maps
= g_hash_table_new_full(g_direct_hash
,
787 g_direct_equal
, (GDestroyNotify
) NULL
,
788 (GDestroyNotify
) trace_ir_metadata_maps_destroy
);
792 trace_ir_maps_destroy(ir_maps
);