Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-mapping.c
1 /*
2 * Babeltrace - Mapping of IR metadata and data object between input and output
3 * trace
4 *
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>
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
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
25 * SOFTWARE.
26 */
27
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"
32
33 #include <stdbool.h>
34
35 #include "common/assert.h"
36 #include <babeltrace2/babeltrace.h>
37 /* For bt_property_availability */
38 #include <babeltrace2/property.h>
39
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"
44
45 static
46 bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps,
47 const bt_trace_class *in_trace_class)
48 {
49 int ret;
50 bt_trace_class *out_trace_class;
51
52 BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class);
53
54 BT_ASSERT(ir_maps);
55 BT_ASSERT(in_trace_class);
56
57 /* Create the ouput trace class. */
58 out_trace_class = bt_trace_class_create(ir_maps->self_comp);
59 if (!out_trace_class) {
60 BT_COMP_LOGE_STR("Error create output trace class");
61 goto end;
62 }
63
64 /* If not, create a new one and add it to the mapping. */
65 ret = copy_trace_class_content(in_trace_class, out_trace_class,
66 ir_maps->log_level, ir_maps->self_comp);
67 if (ret) {
68 BT_COMP_LOGE_STR("Error copy content to output trace class");
69 out_trace_class = NULL;
70 goto end;
71 }
72
73 BT_COMP_LOGD("Created new mapped trace class: in-tc-addr=%p, out-tc-addr=%p",
74 in_trace_class, out_trace_class);
75
76 end:
77 return out_trace_class;
78 }
79
80 static
81 bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps,
82 const bt_trace *in_trace)
83 {
84 struct trace_ir_metadata_maps *metadata_maps;
85 const bt_trace_class *in_trace_class;
86 bt_trace *out_trace;
87
88 BT_COMP_LOGD("Creating new mapped trace: in-t-addr=%p", in_trace);
89 BT_ASSERT(ir_maps);
90 BT_ASSERT(in_trace);
91
92 in_trace_class = bt_trace_borrow_class_const(in_trace);
93 metadata_maps = borrow_metadata_maps_from_input_trace_class(ir_maps,
94 in_trace_class);
95
96 if (!metadata_maps->output_trace_class) {
97 /*
98 * If there is no output trace class yet, create a one and add
99 * it to the mapping.
100 */
101 metadata_maps->output_trace_class =
102 create_new_mapped_trace_class(ir_maps, in_trace_class);
103 if (!metadata_maps->output_trace_class) {
104 out_trace = NULL;
105 goto end;
106 }
107 }
108
109 /* Create the output trace from the output trace class. */
110 out_trace = bt_trace_create(metadata_maps->output_trace_class);
111 if (!out_trace) {
112 BT_COMP_LOGE_STR("Error create output trace");
113 goto end;
114 }
115
116 /* Copy the content over to the output trace. */
117 copy_trace_content(in_trace, out_trace, ir_maps->log_level,
118 ir_maps->self_comp);
119
120 BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p",
121 in_trace, out_trace);
122 end:
123 return out_trace;
124 }
125
126 static
127 bt_stream_class *borrow_mapped_stream_class(struct trace_ir_metadata_maps *md_maps,
128 const bt_stream_class *in_stream_class)
129 {
130 BT_ASSERT_DBG(md_maps);
131 BT_ASSERT_DBG(in_stream_class);
132
133 return g_hash_table_lookup(md_maps->stream_class_map,
134 (gpointer) in_stream_class);
135 }
136
137 static
138 bt_stream_class *create_new_mapped_stream_class(struct trace_ir_maps *ir_maps,
139 const bt_stream_class *in_stream_class)
140 {
141 struct trace_ir_metadata_maps *md_maps;
142 bt_stream_class *out_stream_class;
143 int ret;
144
145 BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p",
146 in_stream_class);
147
148 BT_ASSERT(ir_maps);
149 BT_ASSERT(in_stream_class);
150
151 md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps,
152 in_stream_class);
153
154 BT_ASSERT(md_maps);
155 BT_ASSERT(!borrow_mapped_stream_class(md_maps, in_stream_class));
156
157 /* Create the output stream class. */
158 out_stream_class = bt_stream_class_create_with_id(
159 md_maps->output_trace_class,
160 bt_stream_class_get_id(in_stream_class));
161 if (!out_stream_class) {
162 BT_COMP_LOGE_STR("Error create output stream class");
163 goto end;
164 }
165
166 /* Copy the content over to the output stream class. */
167 ret = copy_stream_class_content(ir_maps, in_stream_class,
168 out_stream_class);
169 if (ret) {
170 BT_COMP_LOGE_STR("Error copy content to output stream class");
171 out_stream_class = NULL;
172 goto end;
173 }
174
175 /* Add it to the mapping. */
176 g_hash_table_insert(md_maps->stream_class_map,
177 (gpointer) in_stream_class, out_stream_class);
178
179 BT_COMP_LOGD("Created new mapped stream class: in-sc-addr=%p, out-sc-addr=%p",
180 in_stream_class, out_stream_class);
181
182 end:
183 return out_stream_class;
184 }
185
186 static
187 bt_stream *borrow_mapped_stream(struct trace_ir_data_maps *d_maps,
188 const bt_stream *in_stream)
189 {
190 BT_ASSERT_DBG(d_maps);
191 BT_ASSERT_DBG(in_stream);
192
193 return g_hash_table_lookup(d_maps->stream_map, (gpointer) in_stream);
194 }
195
196 BT_HIDDEN
197 bt_stream *trace_ir_mapping_create_new_mapped_stream(
198 struct trace_ir_maps *ir_maps, const bt_stream *in_stream)
199 {
200 struct trace_ir_data_maps *d_maps;
201 struct trace_ir_metadata_maps *md_maps;
202 const bt_stream_class *in_stream_class;
203 const bt_trace *in_trace;
204 bt_stream_class *out_stream_class;
205 bt_stream *out_stream = NULL;
206
207 BT_ASSERT(ir_maps);
208 BT_ASSERT(in_stream);
209 BT_COMP_LOGD("Creating new mapped stream: in-s-addr=%p", in_stream);
210
211 in_trace = bt_stream_borrow_trace_const(in_stream);
212
213 d_maps = borrow_data_maps_from_input_trace(ir_maps, in_trace);
214 if (!d_maps->output_trace) {
215 /* Create the output trace for this input trace. */
216 d_maps->output_trace = create_new_mapped_trace(ir_maps, in_trace);
217 if (!d_maps->output_trace) {
218 goto end;
219 }
220 }
221
222 BT_ASSERT(d_maps->output_trace);
223 BT_ASSERT(!borrow_mapped_stream(d_maps, in_stream));
224
225 in_stream_class = bt_stream_borrow_class_const(in_stream);
226 md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class);
227 out_stream_class = borrow_mapped_stream_class(md_maps, in_stream_class);
228 if (!out_stream_class) {
229 /* Create the output stream class for this input stream class. */
230 out_stream_class = create_new_mapped_stream_class(ir_maps,
231 in_stream_class);
232 if (!out_stream_class) {
233 goto end;
234 }
235 }
236 BT_ASSERT(out_stream_class);
237
238 /* Create the output stream for this input stream. */
239 out_stream = bt_stream_create_with_id(out_stream_class,
240 d_maps->output_trace, bt_stream_get_id(in_stream));
241 if (!out_stream) {
242 BT_COMP_LOGE_STR("Error creating output stream");
243 goto end;
244 }
245
246 /* Copy the content over to the output stream. */
247 copy_stream_content(in_stream, out_stream, ir_maps->log_level,
248 ir_maps->self_comp);
249
250 /* Add it to the mapping. */
251 g_hash_table_insert(d_maps->stream_map, (gpointer) in_stream,
252 out_stream);
253
254 BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p",
255 in_stream, out_stream);
256
257 end:
258 return out_stream;
259 }
260
261 BT_HIDDEN
262 bt_stream *trace_ir_mapping_borrow_mapped_stream(struct trace_ir_maps *ir_maps,
263 const bt_stream *in_stream)
264 {
265 struct trace_ir_data_maps *d_maps;
266
267 BT_ASSERT_DBG(ir_maps);
268 BT_ASSERT_DBG(in_stream);
269
270 d_maps = borrow_data_maps_from_input_stream(ir_maps, in_stream);
271 /* Return the mapped stream. */
272 return borrow_mapped_stream(d_maps, in_stream);
273 }
274
275 static inline
276 bt_event_class *borrow_mapped_event_class(struct trace_ir_metadata_maps *md_maps,
277 const bt_event_class *in_event_class)
278 {
279 return g_hash_table_lookup(md_maps->event_class_map,
280 (gpointer) in_event_class);
281 }
282
283 BT_HIDDEN
284 bt_event_class *trace_ir_mapping_create_new_mapped_event_class(
285 struct trace_ir_maps *ir_maps,
286 const bt_event_class *in_event_class)
287 {
288 struct trace_ir_metadata_maps *md_maps;
289 const bt_stream_class *in_stream_class;
290 bt_stream_class *out_stream_class;
291 bt_event_class *out_event_class;
292 int ret;
293
294 BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p",
295 in_event_class);
296
297 BT_ASSERT(ir_maps);
298 BT_ASSERT(in_event_class);
299
300 in_stream_class = bt_event_class_borrow_stream_class_const(in_event_class);
301
302 BT_ASSERT(in_stream_class);
303
304 md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps,
305 in_stream_class);
306
307 BT_ASSERT(md_maps);
308 BT_ASSERT(!borrow_mapped_event_class(md_maps, in_event_class));
309
310 /* Get the right output stream class to add the new event class to it. */
311 out_stream_class = borrow_mapped_stream_class(md_maps, in_stream_class);
312 BT_ASSERT(out_stream_class);
313
314 /* Create an output event class. */
315 out_event_class = bt_event_class_create_with_id(out_stream_class,
316 bt_event_class_get_id(in_event_class));
317 if (!out_event_class) {
318 BT_COMP_LOGE_STR("Error creating output event class");
319 goto end;
320 }
321
322 /* Copy the content over to the output event class. */
323 ret = copy_event_class_content(ir_maps, in_event_class,
324 out_event_class);
325 if (ret) {
326 BT_COMP_LOGE_STR("Error copy content to output event class");
327 out_event_class = NULL;
328 goto end;
329 }
330
331 /* Add it to the mapping. */
332 g_hash_table_insert(md_maps->event_class_map,
333 (gpointer) in_event_class, out_event_class);
334
335 BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p",
336 in_event_class, out_event_class);
337
338 end:
339 return out_event_class;
340 }
341
342 BT_HIDDEN
343 bt_event_class *trace_ir_mapping_borrow_mapped_event_class(
344 struct trace_ir_maps *ir_maps,
345 const bt_event_class *in_event_class)
346 {
347 struct trace_ir_metadata_maps *md_maps;
348
349 BT_ASSERT_DBG(ir_maps);
350 BT_ASSERT_DBG(in_event_class);
351
352 md_maps = borrow_metadata_maps_from_input_event_class(ir_maps,
353 in_event_class);
354
355 /* Return the mapped event_class. */
356 return borrow_mapped_event_class(md_maps, in_event_class);
357 }
358
359 static inline
360 bt_packet *borrow_mapped_packet(struct trace_ir_data_maps *d_maps,
361 const bt_packet *in_packet)
362 {
363 BT_ASSERT_DBG(d_maps);
364 BT_ASSERT_DBG(in_packet);
365
366 return g_hash_table_lookup(d_maps->packet_map, (gpointer) in_packet);
367 }
368
369 BT_HIDDEN
370 bt_packet *trace_ir_mapping_create_new_mapped_packet(
371 struct trace_ir_maps *ir_maps,
372 const bt_packet *in_packet)
373 {
374 struct trace_ir_data_maps *d_maps;
375 const bt_stream *in_stream;
376 const bt_trace *in_trace;
377 bt_packet *out_packet;
378 bt_stream *out_stream;
379
380 BT_COMP_LOGD("Creating new mapped packet: in-p-addr=%p", in_packet);
381
382 in_stream = bt_packet_borrow_stream_const(in_packet);
383 in_trace = bt_stream_borrow_trace_const(in_stream);
384 d_maps = borrow_data_maps_from_input_trace(ir_maps, in_trace);
385
386 /* There should never be a mapped packet already. */
387 BT_ASSERT(!borrow_mapped_packet(d_maps, in_packet));
388 BT_ASSERT(in_stream);
389
390 /* Get output stream corresponding to this input stream. */
391 out_stream = borrow_mapped_stream(d_maps, in_stream);
392 BT_ASSERT(out_stream);
393
394 /* Create the output packet. */
395 out_packet = bt_packet_create(out_stream);
396 if (!out_packet) {
397 BT_COMP_LOGE_STR("Error create output packet");
398 goto end;
399 }
400
401 /* Copy the content over to the output packet. */
402 copy_packet_content(in_packet, out_packet, ir_maps->log_level,
403 ir_maps->self_comp);
404
405 /* Add it to the mapping. */
406 g_hash_table_insert(d_maps->packet_map,
407 (gpointer) in_packet, out_packet);
408
409 BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p",
410 in_packet, out_packet);
411
412 end:
413 return out_packet;
414 }
415
416 BT_HIDDEN
417 bt_packet *trace_ir_mapping_borrow_mapped_packet(struct trace_ir_maps *ir_maps,
418 const bt_packet *in_packet)
419 {
420 struct trace_ir_data_maps *d_maps;
421 BT_ASSERT_DBG(ir_maps);
422 BT_ASSERT_DBG(in_packet);
423
424 d_maps = borrow_data_maps_from_input_packet(ir_maps, in_packet);
425
426 return borrow_mapped_packet(d_maps, in_packet);
427 }
428
429 BT_HIDDEN
430 void trace_ir_mapping_remove_mapped_packet(struct trace_ir_maps *ir_maps,
431 const bt_packet *in_packet)
432 {
433 struct trace_ir_data_maps *d_maps;
434 gboolean ret;
435
436 BT_ASSERT(ir_maps);
437 BT_ASSERT(in_packet);
438
439 d_maps = borrow_data_maps_from_input_packet(ir_maps, in_packet);
440
441 ret = g_hash_table_remove(d_maps->packet_map, in_packet);
442
443 BT_ASSERT(ret);
444 }
445
446 BT_HIDDEN
447 void trace_ir_mapping_remove_mapped_stream(struct trace_ir_maps *ir_maps,
448 const bt_stream *in_stream)
449 {
450 struct trace_ir_data_maps *d_maps;
451 gboolean ret;
452
453 BT_ASSERT(ir_maps);
454 BT_ASSERT(in_stream);
455
456 d_maps = borrow_data_maps_from_input_stream(ir_maps, in_stream);
457
458 ret = g_hash_table_remove(d_maps->stream_map, in_stream);
459
460 BT_ASSERT(ret);
461 }
462
463 static
464 void trace_ir_metadata_maps_remove_func(const bt_trace_class *in_trace_class,
465 void *data)
466 {
467 struct trace_ir_maps *maps = (struct trace_ir_maps *) data;
468 if (maps->metadata_maps) {
469 gboolean ret;
470 ret = g_hash_table_remove(maps->metadata_maps,
471 (gpointer) in_trace_class);
472 BT_ASSERT(ret);
473 }
474 }
475
476 static
477 void trace_ir_data_maps_remove_func(const bt_trace *in_trace, void *data)
478 {
479 struct trace_ir_maps *maps = (struct trace_ir_maps *) data;
480 if (maps->data_maps) {
481 gboolean ret;
482 ret = g_hash_table_remove(maps->data_maps, (gpointer) in_trace);
483 BT_ASSERT(ret);
484 }
485 }
486
487 struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_maps,
488 const bt_trace *in_trace)
489 {
490 bt_trace_add_listener_status add_listener_status;
491 struct trace_ir_data_maps *d_maps = g_new0(struct trace_ir_data_maps, 1);
492
493 if (!d_maps) {
494 BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
495 goto error;
496 }
497
498 d_maps->log_level = ir_maps->log_level;
499 d_maps->self_comp = ir_maps->self_comp;
500 d_maps->input_trace = in_trace;
501
502 /* Create the hashtables used to map data objects. */
503 d_maps->stream_map = g_hash_table_new_full(g_direct_hash,
504 g_direct_equal, NULL,(GDestroyNotify) bt_stream_put_ref);
505 d_maps->packet_map = g_hash_table_new_full(g_direct_hash,
506 g_direct_equal, NULL,(GDestroyNotify) bt_packet_put_ref);
507
508 add_listener_status = bt_trace_add_destruction_listener(
509 in_trace, trace_ir_data_maps_remove_func,
510 ir_maps, &d_maps->destruction_listener_id);
511 BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK);
512
513 error:
514 return d_maps;
515 }
516
517 struct trace_ir_metadata_maps *trace_ir_metadata_maps_create(
518 struct trace_ir_maps *ir_maps,
519 const bt_trace_class *in_trace_class)
520 {
521 bt_trace_class_add_listener_status add_listener_status;
522 struct trace_ir_metadata_maps *md_maps =
523 g_new0(struct trace_ir_metadata_maps, 1);
524
525 if (!md_maps) {
526 BT_COMP_LOGE_STR("Error allocating trace_ir_maps");
527 goto error;
528 }
529
530 md_maps->log_level = ir_maps->log_level;
531 md_maps->self_comp = ir_maps->self_comp;
532 md_maps->input_trace_class = in_trace_class;
533 /*
534 * Create the field class resolving context. This is needed to keep
535 * track of the field class already copied in order to do the field
536 * path resolution correctly.
537 */
538 md_maps->fc_resolving_ctx =
539 g_new0(struct field_class_resolving_context, 1);
540 if (!md_maps->fc_resolving_ctx) {
541 BT_COMP_LOGE_STR("Error allocating field_class_resolving_context");
542 goto error;
543 }
544
545 /* Create the hashtables used to map metadata objects. */
546 md_maps->stream_class_map = g_hash_table_new_full(g_direct_hash,
547 g_direct_equal, NULL, (GDestroyNotify) bt_stream_class_put_ref);
548 md_maps->event_class_map = g_hash_table_new_full(g_direct_hash,
549 g_direct_equal, NULL, (GDestroyNotify) bt_event_class_put_ref);
550 md_maps->field_class_map = g_hash_table_new_full(g_direct_hash,
551 g_direct_equal, NULL, (GDestroyNotify) bt_field_class_put_ref);
552 md_maps->clock_class_map = g_hash_table_new_full(g_direct_hash,
553 g_direct_equal, NULL, (GDestroyNotify) bt_clock_class_put_ref);
554
555 add_listener_status = bt_trace_class_add_destruction_listener(
556 in_trace_class, trace_ir_metadata_maps_remove_func,
557 ir_maps, &md_maps->destruction_listener_id);
558 BT_ASSERT(add_listener_status == BT_TRACE_CLASS_ADD_LISTENER_STATUS_OK);
559
560 error:
561 return md_maps;
562 }
563
564 BT_HIDDEN
565 void trace_ir_data_maps_destroy(struct trace_ir_data_maps *maps)
566 {
567 bt_trace_remove_listener_status status;
568
569 if (!maps) {
570 return;
571 }
572
573 if (maps->packet_map) {
574 g_hash_table_destroy(maps->packet_map);
575 }
576
577 if (maps->stream_map) {
578 g_hash_table_destroy(maps->stream_map);
579 }
580
581 if (maps->output_trace) {
582 bt_trace_put_ref(maps->output_trace);
583 }
584
585 status = bt_trace_remove_destruction_listener(maps->input_trace,
586 maps->destruction_listener_id);
587 if (status != BT_TRACE_REMOVE_LISTENER_STATUS_OK) {
588 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
589 maps->self_comp,
590 "Trace destruction listener removal failed.");
591 bt_current_thread_clear_error();
592 }
593
594 g_free(maps);
595 }
596
597 BT_HIDDEN
598 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *maps)
599 {
600 bt_trace_class_remove_listener_status status;
601
602 if (!maps) {
603 return;
604 }
605
606 if (maps->stream_class_map) {
607 g_hash_table_destroy(maps->stream_class_map);
608 }
609
610 if (maps->event_class_map) {
611 g_hash_table_destroy(maps->event_class_map);
612 }
613
614 if (maps->field_class_map) {
615 g_hash_table_destroy(maps->field_class_map);
616 }
617
618 if (maps->clock_class_map) {
619 g_hash_table_destroy(maps->clock_class_map);
620 }
621
622 g_free(maps->fc_resolving_ctx);
623
624 if (maps->output_trace_class) {
625 bt_trace_class_put_ref(maps->output_trace_class);
626 }
627
628 status = bt_trace_class_remove_destruction_listener(
629 maps->input_trace_class, maps->destruction_listener_id);
630 if (status != BT_TRACE_CLASS_REMOVE_LISTENER_STATUS_OK) {
631 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, maps->log_level,
632 maps->self_comp,
633 "Trace destruction listener removal failed.");
634 bt_current_thread_clear_error();
635 }
636
637 g_free(maps);
638 }
639
640 void trace_ir_maps_clear(struct trace_ir_maps *maps)
641 {
642 if (maps->data_maps) {
643 g_hash_table_remove_all(maps->data_maps);
644 }
645
646 if (maps->metadata_maps) {
647 g_hash_table_remove_all(maps->metadata_maps);
648 }
649 }
650
651 BT_HIDDEN
652 void trace_ir_maps_destroy(struct trace_ir_maps *maps)
653 {
654 if (!maps) {
655 return;
656 }
657
658 g_free(maps->debug_info_field_class_name);
659
660 if (maps->data_maps) {
661 g_hash_table_destroy(maps->data_maps);
662 maps->data_maps = NULL;
663 }
664
665 if (maps->metadata_maps) {
666 g_hash_table_destroy(maps->metadata_maps);
667 maps->metadata_maps = NULL;
668 }
669
670 g_free(maps);
671 }
672
673 BT_HIDDEN
674 struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp,
675 const char *debug_info_field_name, bt_logging_level log_level)
676 {
677 struct trace_ir_maps *ir_maps = g_new0(struct trace_ir_maps, 1);
678 if (!ir_maps) {
679 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
680 "Error allocating trace_ir_maps");
681 goto error;
682 }
683
684 ir_maps->log_level = log_level;
685 ir_maps->self_comp = self_comp;
686
687 /* Copy debug info field name received from the user. */
688 ir_maps->debug_info_field_class_name = g_strdup(debug_info_field_name);
689 if (!ir_maps->debug_info_field_class_name) {
690 BT_COMP_LOGE_STR("Cannot copy debug info field name");
691 goto error;
692 }
693
694 ir_maps->self_comp = self_comp;
695
696 ir_maps->data_maps = g_hash_table_new_full(g_direct_hash,
697 g_direct_equal, (GDestroyNotify) NULL,
698 (GDestroyNotify) trace_ir_data_maps_destroy);
699
700 ir_maps->metadata_maps = g_hash_table_new_full(g_direct_hash,
701 g_direct_equal, (GDestroyNotify) NULL,
702 (GDestroyNotify) trace_ir_metadata_maps_destroy);
703
704 goto end;
705 error:
706 trace_ir_maps_destroy(ir_maps);
707 ir_maps = NULL;
708 end:
709 return ir_maps;
710 }
This page took 0.043422 seconds and 4 git commands to generate.