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