4 * Babeltrace Copy Trace Structure
6 * Copyright 2017 Julien Desfossez <jdesfossez@efficios.com>
8 * Author: Julien Desfossez <jdesfossez@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "PLUGIN-LTTNG-UTILS-DEBUG-INFO-FLT-COPY"
33 #include <babeltrace/assert-internal.h>
34 #include <babeltrace/babeltrace.h>
36 #include <ctfcopytrace.h>
37 #include "debug-info.h"
40 struct bt_stream
*insert_new_stream(
41 struct debug_info_iterator
*debug_it
,
42 struct bt_stream
*stream
,
43 struct debug_info_trace
*di_trace
);
46 void unref_stream(struct bt_stream
*stream
)
52 void unref_packet(struct bt_packet
*packet
)
58 void unref_stream_class(struct bt_stream_class
*stream_class
)
64 void unref_debug_info(struct debug_info
*debug_info
)
66 debug_info_destroy(debug_info
);
70 void destroy_stream_state_key(gpointer key
)
72 g_free((enum fs_writer_stream_state
*) key
);
76 struct bt_field
*get_payload_field(FILE *err
,
77 struct bt_event
*event
, const char *field_name
)
79 struct bt_field
*field
= NULL
, *payload
= NULL
;
80 struct bt_field_class
*payload_class
= NULL
;
82 payload
= bt_event_get_payload(event
, NULL
);
85 payload_class
= bt_field_get_class(payload
);
86 BT_ASSERT(payload_class
);
88 if (bt_field_class_id(payload_class
) != BT_FIELD_CLASS_ID_STRUCT
) {
89 BT_LOGE("Wrong type, expected struct: field-name=\"%s\"",
94 field
= bt_field_structure_get_field_by_name(payload
, field_name
);
97 bt_put(payload_class
);
103 struct bt_field
*get_stream_event_context_field(FILE *err
,
104 struct bt_event
*event
, const char *field_name
)
106 struct bt_field
*field
= NULL
, *sec
= NULL
;
107 struct bt_field_class
*sec_class
= NULL
;
109 sec
= bt_event_get_stream_event_context(event
);
114 sec_class
= bt_field_get_class(sec
);
115 BT_ASSERT(sec_class
);
117 if (bt_field_class_id(sec_class
) != BT_FIELD_CLASS_ID_STRUCT
) {
118 BT_LOGE("Wrong type, expected struct, field-name=\"%s\"",
123 field
= bt_field_structure_get_field_by_name(sec
, field_name
);
132 int get_stream_event_context_unsigned_int_field_value(FILE *err
,
133 struct bt_event
*event
, const char *field_name
,
137 struct bt_field
*field
= NULL
;
138 struct bt_field_class
*field_class
= NULL
;
140 field
= get_stream_event_context_field(err
, event
, field_name
);
145 field_class
= bt_field_get_class(field
);
146 BT_ASSERT(field_class
);
148 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_INTEGER
) {
149 BT_LOGE("Wrong type, expected integer: field-name=\"%s\"",
154 if (bt_ctf_field_class_integer_get_signed(field_class
) != 0) {
155 BT_LOGE("Wrong type, expected unsigned integer: field-name=\"%s\"",
160 ret
= bt_field_unsigned_integer_get_value(field
, value
);
162 BT_LOGE("Failed to get value: field-name=\"%s\"",
177 int get_stream_event_context_int_field_value(FILE *err
, struct bt_event
*event
,
178 const char *field_name
, int64_t *value
)
180 struct bt_field
*field
= NULL
;
181 struct bt_field_class
*field_class
= NULL
;
184 field
= get_stream_event_context_field(err
, event
, field_name
);
189 field_class
= bt_field_get_class(field
);
190 BT_ASSERT(field_class
);
192 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_INTEGER
) {
193 BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name
);
197 if (bt_ctf_field_class_integer_get_signed(field_class
) != 1) {
198 BT_LOGE("Wrong type, expected signed integer: field-name=\"%s\"",
203 ret
= bt_field_signed_integer_get_value(field
, value
);
215 int get_payload_unsigned_int_field_value(FILE *err
,
216 struct bt_event
*event
, const char *field_name
,
219 struct bt_field
*field
= NULL
;
220 struct bt_field_class
*field_class
= NULL
;
223 field
= get_payload_field(err
, event
, field_name
);
225 BT_LOGE("Failed to get payload: field-name=\"%s\"", field_name
);
229 field_class
= bt_field_get_class(field
);
230 BT_ASSERT(field_class
);
232 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_INTEGER
) {
233 BT_LOGE("Wrong type, expected integer: field-name=\"%s\"",
238 if (bt_ctf_field_class_integer_get_signed(field_class
) != 0) {
239 BT_LOGE("Wrong type, expected unsigned integer: field-name=\"%s\"",
244 ret
= bt_field_unsigned_integer_get_value(field
, value
);
246 BT_LOGE("Failed to get value: field-name=\"%s\"",
261 int get_payload_int_field_value(FILE *err
, struct bt_event
*event
,
262 const char *field_name
, int64_t *value
)
264 struct bt_field
*field
= NULL
;
265 struct bt_field_class
*field_class
= NULL
;
268 field
= get_payload_field(err
, event
, field_name
);
270 BT_LOGE("Failed to get payload: field-name=\"%s\"", field_name
);
274 field_class
= bt_field_get_class(field
);
275 BT_ASSERT(field_class
);
277 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_INTEGER
) {
278 BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name
);
282 if (bt_ctf_field_class_integer_get_signed(field_class
) != 1) {
283 BT_LOGE("Wrong type, expected signed integer field-name=\"%s\"",
288 ret
= bt_field_signed_integer_get_value(field
, value
);
290 BT_LOGE("Failed to get value: field-name=\"%s\"",
305 int get_payload_string_field_value(FILE *err
,
306 struct bt_event
*event
, const char *field_name
,
309 struct bt_field
*field
= NULL
;
310 struct bt_field_class
*field_class
= NULL
;
314 * The field might not exist, no error here.
316 field
= get_payload_field(err
, event
, field_name
);
321 field_class
= bt_field_get_class(field
);
322 BT_ASSERT(field_class
);
324 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_STRING
) {
325 BT_LOGE("Wrong type, expected string: field-name=\"%s\"",
330 *value
= bt_field_string_get_value(field
);
332 BT_LOGE("Failed to get value: field-name=\"%s\"",
349 int get_payload_build_id_field_value(FILE *err
,
350 struct bt_event
*event
, const char *field_name
,
351 uint8_t **build_id
, uint64_t *build_id_len
)
353 struct bt_field
*field
= NULL
, *seq_len
= NULL
;
354 struct bt_field_class
*field_class
= NULL
;
355 struct bt_field
*seq_field
= NULL
;
361 field
= get_payload_field(err
, event
, field_name
);
363 BT_LOGE("Failed to get payload: field-name=\"%s\"", field_name
);
367 field_class
= bt_field_get_class(field
);
368 BT_ASSERT(field_class
);
370 if (bt_field_class_id(field_class
) != BT_FIELD_CLASS_ID_SEQUENCE
) {
371 BT_LOGE("Wrong type, expected sequence: field-name=\"%s\"", field_name
);
376 seq_len
= bt_field_sequence_get_length(field
);
379 ret
= bt_field_unsigned_integer_get_value(seq_len
, build_id_len
);
381 BT_LOGE("Failed to get value: field-name=\"%s\"",
387 *build_id
= g_new0(uint8_t, *build_id_len
);
389 BT_LOGE_STR("Failed to allocate build_id.");
393 for (i
= 0; i
< *build_id_len
; i
++) {
396 seq_field
= bt_field_sequence_get_field(field
, i
);
398 BT_LOGE("Failed to get field in sequence: sequence-name=\"%s\", index=%" PRIu64
,
403 ret
= bt_field_unsigned_integer_get_value(seq_field
, &tmp
);
405 BT_LOGE("Failed to get value: field-name=\"%s\"",
411 (*build_id
)[i
] = (uint8_t) tmp
;
426 struct debug_info
*lookup_trace_debug_info(struct debug_info_iterator
*debug_it
,
427 struct bt_trace
*writer_trace
,
428 struct debug_info_trace
*di_trace
)
430 return (struct debug_info
*) g_hash_table_lookup(
431 di_trace
->trace_debug_map
,
432 (gpointer
) writer_trace
);
436 struct debug_info
*insert_new_debug_info(struct debug_info_iterator
*debug_it
,
437 struct bt_trace
*writer_trace
,
438 struct debug_info_trace
*di_trace
)
440 struct debug_info
*debug_info
= NULL
;
441 struct bt_value
*field
= NULL
;
442 const char *str_value
;
443 enum bt_value_status ret
;
445 field
= bt_trace_get_environment_field_value_by_name(writer_trace
,
447 /* No domain field, no debug info */
451 ret
= bt_value_string_get(field
, &str_value
);
452 BT_ASSERT(ret
== BT_VALUE_STATUS_OK
);
454 /* Domain not ust, no debug info */
455 if (strcmp(str_value
, "ust") != 0) {
460 /* No tracer_name, no debug info */
461 field
= bt_trace_get_environment_field_value_by_name(writer_trace
,
463 /* No tracer_name, no debug info */
467 ret
= bt_value_string_get(field
, &str_value
);
468 BT_ASSERT(ret
== BT_VALUE_STATUS_OK
);
470 /* Tracer_name not lttng-ust, no debug info */
471 if (strcmp(str_value
, "lttng-ust") != 0) {
476 debug_info
= debug_info_create(debug_it
->debug_info_component
);
478 BT_LOGE_STR("Failed to create debug info.");
482 g_hash_table_insert(di_trace
->trace_debug_map
, (gpointer
) writer_trace
,
491 struct debug_info
*get_trace_debug_info(struct debug_info_iterator
*debug_it
,
492 struct bt_trace
*writer_trace
,
493 struct debug_info_trace
*di_trace
)
495 struct debug_info
*debug_info
;
497 debug_info
= lookup_trace_debug_info(debug_it
, writer_trace
, di_trace
);
502 debug_info
= insert_new_debug_info(debug_it
, writer_trace
, di_trace
);
509 struct debug_info_trace
*lookup_trace(struct debug_info_iterator
*debug_it
,
510 struct bt_trace
*trace
)
512 return (struct debug_info_trace
*) g_hash_table_lookup(
518 enum debug_info_stream_state
*insert_new_stream_state(
519 struct debug_info_iterator
*debug_it
,
520 struct debug_info_trace
*di_trace
, struct bt_stream
*stream
)
522 enum debug_info_stream_state
*v
= NULL
;
524 v
= g_new0(enum debug_info_stream_state
, 1);
526 BT_LOGE_STR("Failed to allocate debug_info_stream_state.");
529 *v
= DEBUG_INFO_UNKNOWN_STREAM
;
531 g_hash_table_insert(di_trace
->stream_states
, stream
, v
);
538 void check_completed_trace(gpointer key
, gpointer value
, gpointer user_data
)
540 enum debug_info_stream_state
*state
= value
;
541 int *trace_completed
= user_data
;
543 if (*state
!= DEBUG_INFO_COMPLETED_STREAM
) {
544 *trace_completed
= 0;
549 gboolean
empty_ht(gpointer key
, gpointer value
, gpointer user_data
)
555 void debug_info_close_trace(struct debug_info_iterator
*debug_it
,
556 struct debug_info_trace
*di_trace
)
558 if (di_trace
->static_listener_id
>= 0) {
559 bt_trace_remove_is_static_listener(di_trace
->trace
,
560 di_trace
->static_listener_id
);
563 /* Empty the stream class HT. */
564 g_hash_table_foreach_remove(di_trace
->stream_class_map
,
566 g_hash_table_destroy(di_trace
->stream_class_map
);
568 /* Empty the stream HT. */
569 g_hash_table_foreach_remove(di_trace
->stream_map
,
571 g_hash_table_destroy(di_trace
->stream_map
);
573 /* Empty the stream state HT. */
574 g_hash_table_foreach_remove(di_trace
->stream_states
,
576 g_hash_table_destroy(di_trace
->stream_states
);
578 /* Empty the packet HT. */
579 g_hash_table_foreach_remove(di_trace
->packet_map
,
581 g_hash_table_destroy(di_trace
->packet_map
);
583 /* Empty the trace_debug HT. */
584 g_hash_table_foreach_remove(di_trace
->trace_debug_map
,
586 g_hash_table_destroy(di_trace
->trace_debug_map
);
590 int sync_event_classes(struct debug_info_iterator
*debug_it
,
591 struct bt_stream
*stream
,
592 struct bt_stream
*writer_stream
)
595 struct bt_stream_class
*stream_class
= NULL
,
596 *writer_stream_class
= NULL
;
597 enum bt_component_status ret
;
599 stream_class
= bt_stream_get_class(stream
);
600 BT_ASSERT(stream_class
);
602 writer_stream_class
= bt_stream_get_class(writer_stream
);
603 BT_ASSERT(writer_stream_class
);
605 ret
= ctf_copy_event_classes(debug_it
->err
, stream_class
,
606 writer_stream_class
);
607 if (ret
!= BT_COMPONENT_STATUS_OK
) {
608 BT_LOGE_STR("Failed to copy event classes.");
618 bt_put(stream_class
);
619 bt_put(writer_stream_class
);
624 void trace_is_static_listener(struct bt_trace
*trace
, void *data
)
626 struct debug_info_trace
*di_trace
= data
;
627 int trace_completed
= 1, ret
, nr_stream
, i
;
628 struct bt_stream
*stream
= NULL
, *writer_stream
= NULL
;
629 struct bt_trace
*writer_trace
= di_trace
->writer_trace
;
632 * When the trace becomes static, make sure that we have all
633 * the event classes in our stream_class copies before setting it
636 nr_stream
= bt_trace_get_stream_count(trace
);
637 for (i
= 0; i
< nr_stream
; i
++) {
638 stream
= bt_trace_get_stream_by_index(trace
, i
);
641 writer_stream
= bt_trace_get_stream_by_index(writer_trace
, i
);
642 BT_ASSERT(writer_stream
);
644 ret
= sync_event_classes(di_trace
->debug_it
, stream
, writer_stream
);
646 BT_LOGE_STR("Failed to synchronize the event classes.");
650 BT_PUT(writer_stream
);
653 bt_trace_set_is_static(di_trace
->writer_trace
);
654 di_trace
->trace_static
= 1;
656 g_hash_table_foreach(di_trace
->stream_states
,
657 check_completed_trace
, &trace_completed
);
658 if (trace_completed
) {
659 debug_info_close_trace(di_trace
->debug_it
, di_trace
);
660 g_hash_table_remove(di_trace
->debug_it
->trace_map
,
665 bt_put(writer_stream
);
670 struct debug_info_trace
*insert_new_trace(struct debug_info_iterator
*debug_it
,
671 struct bt_stream
*stream
) {
672 struct bt_trace
*writer_trace
= NULL
;
673 struct debug_info_trace
*di_trace
= NULL
;
674 struct bt_trace
*trace
= NULL
;
675 struct bt_stream_class
*stream_class
= NULL
;
676 struct bt_stream
*writer_stream
= NULL
;
677 int ret
, nr_stream
, i
;
679 writer_trace
= bt_trace_create();
681 BT_LOGE_STR("Failed to create a new trace.");
685 stream_class
= bt_stream_get_class(stream
);
686 BT_ASSERT(stream_class
);
688 trace
= bt_stream_class_get_trace(stream_class
);
691 ret
= ctf_copy_trace(debug_it
->err
, trace
, writer_trace
);
692 if (ret
!= BT_COMPONENT_STATUS_OK
) {
693 BT_LOGE_STR("Failed to copy CTF trace.");
697 di_trace
= g_new0(struct debug_info_trace
, 1);
699 BT_LOGE_STR("Failed to allocate debug_info_trace.");
703 di_trace
->trace
= trace
;
704 di_trace
->writer_trace
= writer_trace
;
705 di_trace
->debug_info_component
= debug_it
->debug_info_component
;
706 di_trace
->debug_it
= debug_it
;
707 di_trace
->stream_map
= g_hash_table_new_full(g_direct_hash
,
708 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream
);
709 di_trace
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
710 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream_class
);
711 di_trace
->packet_map
= g_hash_table_new_full(g_direct_hash
,
712 g_direct_equal
, NULL
, (GDestroyNotify
) unref_packet
);
713 di_trace
->trace_debug_map
= g_hash_table_new_full(g_direct_hash
,
714 g_direct_equal
, NULL
, (GDestroyNotify
) unref_debug_info
);
715 di_trace
->stream_states
= g_hash_table_new_full(g_direct_hash
,
716 g_direct_equal
, NULL
, destroy_stream_state_key
);
717 g_hash_table_insert(debug_it
->trace_map
, (gpointer
) trace
, di_trace
);
719 /* Set all the existing streams in the unknown state. */
720 nr_stream
= bt_trace_get_stream_count(trace
);
721 for (i
= 0; i
< nr_stream
; i
++) {
722 stream
= bt_trace_get_stream_by_index(trace
, i
);
725 insert_new_stream_state(debug_it
, di_trace
, stream
);
726 writer_stream
= insert_new_stream(debug_it
, stream
, di_trace
);
727 if (!writer_stream
) {
728 BT_LOGE_STR("Failed to insert new stream.");
731 bt_get(writer_stream
);
732 ret
= sync_event_classes(debug_it
, stream
, writer_stream
);
734 BT_LOGE_STR("Failed to synchronize event classes.");
737 BT_PUT(writer_stream
);
741 /* Check if the trace is already static or register a listener. */
742 if (bt_trace_is_static(trace
)) {
743 di_trace
->trace_static
= 1;
744 di_trace
->static_listener_id
= -1;
745 bt_trace_set_is_static(writer_trace
);
747 ret
= bt_trace_add_is_static_listener(trace
,
748 trace_is_static_listener
, NULL
, di_trace
);
750 di_trace
->static_listener_id
= ret
;
757 BT_PUT(writer_trace
);
762 bt_put(writer_stream
);
763 bt_put(stream_class
);
769 struct bt_packet
*lookup_packet(struct debug_info_iterator
*debug_it
,
770 struct bt_packet
*packet
,
771 struct debug_info_trace
*di_trace
)
773 return (struct bt_packet
*) g_hash_table_lookup(
774 di_trace
->packet_map
,
779 struct bt_packet
*insert_new_packet(struct debug_info_iterator
*debug_it
,
780 struct bt_packet
*packet
,
781 struct bt_stream
*writer_stream
,
782 struct debug_info_trace
*di_trace
)
784 struct bt_packet
*writer_packet
;
787 writer_packet
= bt_packet_create(writer_stream
);
788 if (!writer_packet
) {
789 BT_LOGE_STR("Failed to create new packet.");
793 ret
= ctf_packet_copy_header(debug_it
->err
, packet
, writer_packet
);
795 BT_LOGE_STR("Failed to copy packet header.");
799 g_hash_table_insert(di_trace
->packet_map
, (gpointer
) packet
,
804 BT_PUT(writer_packet
);
806 return writer_packet
;
810 int add_debug_info_fields(FILE *err
,
811 struct bt_field_class
*writer_event_context_class
,
812 struct debug_info_component
*component
)
814 struct bt_field_class
*ip_field
= NULL
, *debug_field_class
= NULL
,
815 *bin_field_class
= NULL
, *func_field_class
= NULL
,
816 *src_field_class
= NULL
;
819 ip_field
= bt_field_class_structure_get_field_class_by_name(
820 writer_event_context_class
, IP_FIELD_NAME
);
821 /* No ip field, so no debug info. */
827 debug_field_class
= bt_field_class_structure_get_field_class_by_name(
828 writer_event_context_class
,
829 component
->arg_debug_info_field_name
);
830 /* Already existing debug_info field, no need to add it. */
831 if (debug_field_class
) {
835 debug_field_class
= bt_field_class_structure_create();
836 if (!debug_field_class
) {
837 BT_LOGE_STR("Failed to create debug_info structure.");
841 bin_field_class
= bt_field_class_string_create();
842 if (!bin_field_class
) {
843 BT_LOGE_STR("Failed to create string for field=bin.");
847 func_field_class
= bt_field_class_string_create();
848 if (!func_field_class
) {
849 BT_LOGE_STR("Failed to create string for field=func.");
853 src_field_class
= bt_field_class_string_create();
854 if (!src_field_class
) {
855 BT_LOGE_STR("Failed to create string for field=src.");
859 ret
= bt_field_class_structure_add_field(debug_field_class
,
860 bin_field_class
, "bin");
862 BT_LOGE_STR("Failed to add a field to debug_info struct: field=bin.");
866 ret
= bt_field_class_structure_add_field(debug_field_class
,
867 func_field_class
, "func");
869 BT_LOGE_STR("Failed to add a field to debug_info struct: field=func.");
873 ret
= bt_field_class_structure_add_field(debug_field_class
,
874 src_field_class
, "src");
876 BT_LOGE_STR("Failed to add a field to debug_info struct: field=src.");
880 ret
= bt_field_class_structure_add_field(writer_event_context_class
,
881 debug_field_class
, component
->arg_debug_info_field_name
);
883 BT_LOGE_STR("Failed to add debug_info field to event_context.");
891 BT_PUT(debug_field_class
);
894 bt_put(src_field_class
);
895 bt_put(func_field_class
);
896 bt_put(bin_field_class
);
897 bt_put(debug_field_class
);
902 int create_debug_info_event_context_class(FILE *err
,
903 struct bt_field_class
*event_context_class
,
904 struct bt_field_class
*writer_event_context_class
,
905 struct debug_info_component
*component
)
907 int ret
, nr_fields
, i
;
909 nr_fields
= bt_field_class_structure_get_field_count(event_context_class
);
910 for (i
= 0; i
< nr_fields
; i
++) {
911 struct bt_field_class
*field_class
= NULL
;
912 const char *field_name
;
914 if (bt_field_class_structure_get_field_by_index(event_context_class
,
915 &field_name
, &field_class
, i
) < 0) {
916 BT_LOGE("Failed to get a field from the event-context: field-name=\"%s\"",
921 ret
= bt_field_class_structure_add_field(writer_event_context_class
,
922 field_class
, field_name
);
925 BT_LOGE("Failed to add a field to the event-context: field-name=\"%s\"",
931 ret
= add_debug_info_fields(err
, writer_event_context_class
,
942 struct bt_stream_class
*copy_stream_class_debug_info(FILE *err
,
943 struct bt_stream_class
*stream_class
,
944 struct bt_trace
*writer_trace
,
945 struct debug_info_component
*component
)
947 struct bt_field_class
*cls
= NULL
;
948 struct bt_stream_class
*writer_stream_class
= NULL
;
949 struct bt_field_class
*writer_event_context_class
= NULL
;
951 const char *name
= bt_stream_class_get_name(stream_class
);
953 writer_stream_class
= bt_stream_class_create_empty(name
);
954 if (!writer_stream_class
) {
955 BT_LOGE_STR("Failed to create empty stream class.");
959 type
= bt_stream_class_get_packet_context_class(stream_class
);
961 ret_int
= bt_stream_class_set_packet_context_class(
962 writer_stream_class
, type
);
964 BT_LOGE_STR("Failed to set packet_context type.");
970 type
= bt_stream_class_get_event_header_type(stream_class
);
972 ret_int
= bt_stream_class_set_event_header_type(
973 writer_stream_class
, type
);
975 BT_LOGE_STR("Failed to set event_header type.");
981 type
= bt_stream_class_get_event_context_class(stream_class
);
983 writer_event_context_class
= bt_field_class_structure_create();
984 if (!writer_event_context_class
) {
985 BT_LOGE_STR("Failed to create writer_event_context struct type.");
988 ret_int
= create_debug_info_event_context_class(err
, type
,
989 writer_event_context_class
, component
);
991 BT_LOGE_STR("Failed to create debug_info event_context type.");
996 ret_int
= bt_stream_class_set_event_context_class(
997 writer_stream_class
, writer_event_context_class
);
999 BT_LOGE_STR("Failed to set event_context type.");
1002 BT_PUT(writer_event_context_class
);
1008 BT_PUT(writer_stream_class
);
1010 bt_put(writer_event_context_class
);
1012 return writer_stream_class
;
1016 * Add the original clock classes to the new trace, we do not need to copy
1017 * them, and if we did, we would have to manually inspect the stream class
1018 * to update the integers mapping to a clock.
1021 int add_clock_classes(FILE *err
, struct bt_trace
*writer_trace
,
1022 struct bt_stream_class
*writer_stream_class
,
1023 struct bt_trace
*trace
)
1025 int ret
, clock_class_count
, i
;
1027 clock_class_count
= bt_trace_get_clock_class_count(trace
);
1029 for (i
= 0; i
< clock_class_count
; i
++) {
1030 struct bt_clock_class
*clock_class
=
1031 bt_trace_get_clock_class_by_index(trace
, i
);
1032 struct bt_clock_class
*existing_clock_class
= NULL
;
1034 BT_ASSERT(clock_class
);
1036 existing_clock_class
= bt_trace_get_clock_class_by_name(
1037 writer_trace
, bt_clock_class_get_name(clock_class
));
1038 bt_put(existing_clock_class
);
1039 if (existing_clock_class
) {
1040 bt_put(clock_class
);
1044 ret
= bt_trace_add_clock_class(writer_trace
, clock_class
);
1045 BT_PUT(clock_class
);
1047 BT_LOGE_STR("Failed to add clock_class.");
1063 struct bt_stream_class
*insert_new_stream_class(
1064 struct debug_info_iterator
*debug_it
,
1065 struct bt_stream_class
*stream_class
)
1067 struct bt_stream_class
*writer_stream_class
= NULL
;
1068 struct bt_trace
*trace
, *writer_trace
= NULL
;
1069 struct debug_info_trace
*di_trace
;
1070 enum bt_component_status ret
;
1073 trace
= bt_stream_class_get_trace(stream_class
);
1076 di_trace
= lookup_trace(debug_it
, trace
);
1078 BT_LOGE_STR("Failed to find existing trace.");
1079 ret
= BT_COMPONENT_STATUS_ERROR
;
1082 writer_trace
= di_trace
->writer_trace
;
1083 bt_get(writer_trace
);
1085 writer_stream_class
= copy_stream_class_debug_info(debug_it
->err
, stream_class
,
1086 writer_trace
, debug_it
->debug_info_component
);
1087 if (!writer_stream_class
) {
1088 BT_LOGE_STR("Failed to copy stream class.");
1092 int_ret
= bt_trace_add_stream_class(writer_trace
, writer_stream_class
);
1094 BT_LOGE_STR("Failed to add stream class.");
1098 ret
= add_clock_classes(debug_it
->err
, writer_trace
,
1099 writer_stream_class
, trace
);
1100 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1101 BT_LOGE_STR("Failed to add clock classes.");
1105 g_hash_table_insert(di_trace
->stream_class_map
,
1106 (gpointer
) stream_class
, writer_stream_class
);
1111 BT_PUT(writer_stream_class
);
1114 bt_put(writer_trace
);
1115 return writer_stream_class
;
1119 struct bt_stream
*insert_new_stream(
1120 struct debug_info_iterator
*debug_it
,
1121 struct bt_stream
*stream
,
1122 struct debug_info_trace
*di_trace
)
1124 struct bt_stream
*writer_stream
= NULL
;
1125 struct bt_stream_class
*stream_class
= NULL
;
1126 struct bt_stream_class
*writer_stream_class
= NULL
;
1129 stream_class
= bt_stream_get_class(stream
);
1130 BT_ASSERT(stream_class
);
1132 writer_stream_class
= g_hash_table_lookup(
1133 di_trace
->stream_class_map
,
1134 (gpointer
) stream_class
);
1136 if (!writer_stream_class
) {
1137 writer_stream_class
= insert_new_stream_class(debug_it
,
1139 if (!writer_stream_class
) {
1140 BT_LOGE_STR("Failed to insert new stream class.");
1144 bt_get(writer_stream_class
);
1146 id
= bt_stream_get_id(stream
);
1148 writer_stream
= bt_stream_create(writer_stream_class
,
1149 bt_stream_get_name(stream
));
1151 writer_stream
= bt_stream_create_with_id(
1152 writer_stream_class
,
1153 bt_stream_get_name(stream
), id
);
1156 if (!writer_stream
) {
1157 BT_LOGE_STR("Failed to create writer_stream.");
1161 g_hash_table_insert(di_trace
->stream_map
, (gpointer
) stream
,
1167 BT_PUT(writer_stream
);
1169 bt_put(stream_class
);
1170 bt_put(writer_stream_class
);
1171 return writer_stream
;
1175 struct bt_stream
*lookup_stream(struct debug_info_iterator
*debug_it
,
1176 struct bt_stream
*stream
,
1177 struct debug_info_trace
*di_trace
)
1179 return (struct bt_stream
*) g_hash_table_lookup(
1180 di_trace
->stream_map
, (gpointer
) stream
);
1184 struct bt_event_class
*get_event_class(struct debug_info_iterator
*debug_it
,
1185 struct bt_stream_class
*writer_stream_class
,
1186 struct bt_event_class
*event_class
)
1188 return bt_stream_class_get_event_class_by_id(writer_stream_class
,
1189 bt_event_class_get_id(event_class
));
1193 struct debug_info_trace
*lookup_di_trace_from_stream(
1194 struct debug_info_iterator
*debug_it
,
1195 struct bt_stream
*stream
)
1197 struct bt_stream_class
*stream_class
= NULL
;
1198 struct bt_trace
*trace
= NULL
;
1199 struct debug_info_trace
*di_trace
= NULL
;
1201 stream_class
= bt_stream_get_class(stream
);
1202 BT_ASSERT(stream_class
);
1204 trace
= bt_stream_class_get_trace(stream_class
);
1207 di_trace
= (struct debug_info_trace
*) g_hash_table_lookup(
1208 debug_it
->trace_map
, (gpointer
) trace
);
1210 BT_PUT(stream_class
);
1216 struct bt_stream
*get_writer_stream(
1217 struct debug_info_iterator
*debug_it
,
1218 struct bt_packet
*packet
, struct bt_stream
*stream
)
1220 struct bt_stream_class
*stream_class
= NULL
;
1221 struct bt_stream
*writer_stream
= NULL
;
1222 struct debug_info_trace
*di_trace
= NULL
;
1224 stream_class
= bt_stream_get_class(stream
);
1225 BT_ASSERT(stream_class
);
1227 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1229 BT_LOGE_STR("Failed to find existing trace from stream.");
1233 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1234 if (!writer_stream
) {
1235 BT_LOGE_STR("Failed to find existing stream.");
1238 bt_get(writer_stream
);
1243 BT_PUT(writer_stream
);
1245 bt_put(stream_class
);
1246 return writer_stream
;
1250 struct bt_packet
*debug_info_new_packet(
1251 struct debug_info_iterator
*debug_it
,
1252 struct bt_packet
*packet
)
1254 struct bt_stream
*stream
= NULL
, *writer_stream
= NULL
;
1255 struct bt_packet
*writer_packet
= NULL
;
1256 struct bt_field
*packet_context
= NULL
;
1257 struct debug_info_trace
*di_trace
;
1260 stream
= bt_packet_get_stream(packet
);
1263 writer_stream
= get_writer_stream(debug_it
, packet
, stream
);
1264 if (!writer_stream
) {
1265 BT_LOGE_STR("Failed to get writer stream.");
1269 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1271 BT_LOGE_STR("Failed to find existing trace from stream.");
1276 * If a packet was already opened, close it and remove it from
1279 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1280 if (writer_packet
) {
1281 g_hash_table_remove(di_trace
->packet_map
, packet
);
1282 BT_PUT(writer_packet
);
1285 writer_packet
= insert_new_packet(debug_it
, packet
, writer_stream
,
1287 if (!writer_packet
) {
1288 BT_LOGE_STR("Failed to insert new packet.");
1292 packet_context
= bt_packet_get_context(packet
);
1293 if (packet_context
) {
1294 int_ret
= ctf_packet_copy_context(debug_it
->err
,
1295 packet
, writer_stream
, writer_packet
);
1297 BT_LOGE_STR("Failed to copy packet context.");
1300 BT_PUT(packet_context
);
1303 bt_get(writer_packet
);
1309 bt_put(packet_context
);
1310 bt_put(writer_stream
);
1312 return writer_packet
;
1316 struct bt_packet
*debug_info_close_packet(
1317 struct debug_info_iterator
*debug_it
,
1318 struct bt_packet
*packet
)
1320 struct bt_packet
*writer_packet
= NULL
;
1321 struct bt_stream
*stream
= NULL
;
1322 struct debug_info_trace
*di_trace
;
1324 stream
= bt_packet_get_stream(packet
);
1327 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1329 BT_LOGE_STR("Failed to find trace from stream.");
1333 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1334 if (!writer_packet
) {
1335 BT_LOGE_STR("Failed to find existing packet.");
1338 bt_get(writer_packet
);
1339 g_hash_table_remove(di_trace
->packet_map
, packet
);
1343 return writer_packet
;
1347 struct bt_stream
*debug_info_stream_begin(
1348 struct debug_info_iterator
*debug_it
,
1349 struct bt_stream
*stream
)
1351 struct bt_stream
*writer_stream
= NULL
;
1352 enum debug_info_stream_state
*state
;
1353 struct debug_info_trace
*di_trace
= NULL
;
1355 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1357 di_trace
= insert_new_trace(debug_it
, stream
);
1359 BT_LOGE_STR("Failed to insert new trace.");
1364 /* Set the stream as active */
1365 state
= g_hash_table_lookup(di_trace
->stream_states
, stream
);
1367 if (di_trace
->trace_static
) {
1368 BT_LOGE_STR("Failed to add a new stream, trace is static.");
1371 state
= insert_new_stream_state(debug_it
, di_trace
,
1374 BT_LOGE_STR("Failed to add new stream state.");
1378 if (*state
!= DEBUG_INFO_UNKNOWN_STREAM
) {
1379 BT_LOGE("Unexpected stream state: state=%d", *state
);
1382 *state
= DEBUG_INFO_ACTIVE_STREAM
;
1384 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1385 if (!writer_stream
) {
1386 writer_stream
= insert_new_stream(debug_it
, stream
, di_trace
);
1388 bt_get(writer_stream
);
1393 BT_PUT(writer_stream
);
1395 return writer_stream
;
1399 struct bt_stream
*debug_info_stream_end(struct debug_info_iterator
*debug_it
,
1400 struct bt_stream
*stream
)
1402 struct bt_stream
*writer_stream
= NULL
;
1403 struct debug_info_trace
*di_trace
= NULL
;
1404 enum debug_info_stream_state
*state
;
1406 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1408 BT_LOGE_STR("Failed to find existing trace from stream.");
1412 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1413 if (!writer_stream
) {
1414 BT_LOGE_STR("Failed to find existing stream.");
1418 * Take the ref on the stream and keep it until the notification
1421 bt_get(writer_stream
);
1423 state
= g_hash_table_lookup(di_trace
->stream_states
, stream
);
1424 if (*state
!= DEBUG_INFO_ACTIVE_STREAM
) {
1425 BT_LOGE("Unexpected stream state: state=%d", *state
);
1428 *state
= DEBUG_INFO_COMPLETED_STREAM
;
1430 g_hash_table_remove(di_trace
->stream_map
, stream
);
1432 if (di_trace
->trace_static
) {
1433 int trace_completed
= 1;
1435 g_hash_table_foreach(di_trace
->stream_states
,
1436 check_completed_trace
, &trace_completed
);
1437 if (trace_completed
) {
1438 debug_info_close_trace(debug_it
, di_trace
);
1439 g_hash_table_remove(debug_it
->trace_map
,
1447 BT_PUT(writer_stream
);
1450 return writer_stream
;
1454 struct debug_info_source
*lookup_debug_info(FILE *err
,
1455 struct bt_event
*event
,
1456 struct debug_info
*debug_info
)
1460 struct debug_info_source
*dbg_info_src
= NULL
;
1463 ret
= get_stream_event_context_int_field_value(err
, event
,
1464 VPID_FIELD_NAME
, &vpid
);
1469 ret
= get_stream_event_context_unsigned_int_field_value(err
, event
,
1470 IP_FIELD_NAME
, &ip
);
1475 /* Get debug info for this context. */
1476 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1479 return dbg_info_src
;
1483 int set_debug_info_field(FILE *err
, struct bt_field
*debug_field
,
1484 struct debug_info_source
*dbg_info_src
,
1485 struct debug_info_component
*component
)
1487 int i
, nr_fields
, ret
= 0;
1488 struct bt_field_class
*debug_field_class
= NULL
;
1489 struct bt_field
*field
= NULL
;
1490 struct bt_field_class
*field_class
= NULL
;
1492 debug_field_class
= bt_field_get_class(debug_field
);
1493 BT_ASSERT(debug_field_class
);
1495 nr_fields
= bt_field_class_structure_get_field_count(debug_field_class
);
1496 for (i
= 0; i
< nr_fields
; i
++) {
1497 const char *field_name
;
1499 if (bt_field_class_structure_get_field_by_index(debug_field_class
,
1500 &field_name
, &field_class
, i
) < 0) {
1501 BT_LOGE("Failed to get field from debug_info struct: field-name=\"%s\"",
1505 BT_PUT(field_class
);
1507 field
= bt_field_structure_get_field_by_index(debug_field
, i
);
1508 if (!strcmp(field_name
, "bin")) {
1509 if (dbg_info_src
&& dbg_info_src
->bin_path
) {
1510 GString
*tmp
= g_string_new(NULL
);
1512 if (component
->arg_full_path
) {
1513 g_string_printf(tmp
, "%s%s",
1514 dbg_info_src
->bin_path
,
1515 dbg_info_src
->bin_loc
);
1517 g_string_printf(tmp
, "%s%s",
1518 dbg_info_src
->short_bin_path
,
1519 dbg_info_src
->bin_loc
);
1521 ret
= bt_field_string_set_value(field
, tmp
->str
);
1522 g_string_free(tmp
, true);
1524 ret
= bt_field_string_set_value(field
, "");
1526 } else if (!strcmp(field_name
, "func")) {
1527 if (dbg_info_src
&& dbg_info_src
->func
) {
1528 ret
= bt_field_string_set_value(field
,
1529 dbg_info_src
->func
);
1531 ret
= bt_field_string_set_value(field
, "");
1533 } else if (!strcmp(field_name
, "src")) {
1534 if (dbg_info_src
&& dbg_info_src
->src_path
) {
1535 GString
*tmp
= g_string_new(NULL
);
1537 if (component
->arg_full_path
) {
1538 g_string_printf(tmp
, "%s:%" PRId64
,
1539 dbg_info_src
->src_path
,
1540 dbg_info_src
->line_no
);
1542 g_string_printf(tmp
, "%s:%" PRId64
,
1543 dbg_info_src
->short_src_path
,
1544 dbg_info_src
->line_no
);
1546 ret
= bt_field_string_set_value(field
, tmp
->str
);
1547 g_string_free(tmp
, true);
1549 ret
= bt_field_string_set_value(field
, "");
1554 BT_LOGE("Failed to set value in debug-info struct: field-name=\"%s\"",
1565 bt_put(field_class
);
1567 bt_put(debug_field_class
);
1572 int copy_set_debug_info_stream_event_context(FILE *err
,
1573 struct bt_field
*event_context
,
1574 struct bt_event
*event
,
1575 struct bt_event
*writer_event
,
1576 struct debug_info
*debug_info
,
1577 struct debug_info_component
*component
)
1579 struct bt_field_class
*writer_event_context_class
= NULL
,
1580 *event_context_class
= NULL
;
1581 struct bt_field
*writer_event_context
= NULL
;
1582 struct bt_field
*field
= NULL
, *copy_field
= NULL
, *debug_field
= NULL
;
1583 struct bt_field_class
*field_class
= NULL
;
1584 struct debug_info_source
*dbg_info_src
;
1585 int ret
, nr_fields
, i
;
1587 writer_event_context
= bt_event_get_stream_event_context(writer_event
);
1588 BT_ASSERT(writer_event_context
);
1590 writer_event_context_class
= bt_field_get_class(writer_event_context
);
1591 BT_ASSERT(writer_event_context_class
);
1593 event_context_class
= bt_field_get_class(event_context
);
1594 BT_ASSERT(event_context_class
);
1597 * If it is not a structure, we did not modify it to add the debug info
1598 * fields, so just assign it as is.
1600 if (bt_field_class_id(writer_event_context_class
) != BT_FIELD_CLASS_ID_STRUCT
) {
1601 ret
= bt_event_set_event_context(writer_event
, event_context
);
1605 dbg_info_src
= lookup_debug_info(err
, event
, debug_info
);
1607 nr_fields
= bt_field_class_structure_get_field_count(writer_event_context_class
);
1608 for (i
= 0; i
< nr_fields
; i
++) {
1609 const char *field_name
;
1611 if (bt_field_class_structure_get_field_by_index(writer_event_context_class
,
1612 &field_name
, &field_class
, i
) < 0) {
1613 BT_LOGE("Failed to get field from event-context: field-name=\"%s\"",
1619 * Prevent illegal access in the event_context.
1621 if (i
< bt_field_class_structure_get_field_count(event_context_class
)) {
1622 field
= bt_field_structure_get_field_by_index(event_context
, i
);
1625 * The debug_info field, only exists in the writer event or
1626 * if it was set by a earlier pass of the debug_info plugin.
1628 if (!strcmp(field_name
, component
->arg_debug_info_field_name
) &&
1630 debug_field
= bt_field_structure_get_field_by_index(
1631 writer_event_context
, i
);
1632 BT_ASSERT(debug_field
);
1634 ret
= set_debug_info_field(err
, debug_field
,
1635 dbg_info_src
, component
);
1637 BT_LOGE_STR("Failed to set debug_info field.");
1640 BT_PUT(debug_field
);
1642 copy_field
= bt_field_copy(field
);
1644 BT_LOGE("Failed to copy field: field-name=\"%s\"",
1649 ret
= bt_field_structure_set_field_by_name(
1650 writer_event_context
,
1651 field_name
, copy_field
);
1653 BT_LOGE("Failed to set field: field-name=\"%s\"",
1659 BT_PUT(field_class
);
1669 bt_put(event_context_class
);
1670 bt_put(writer_event_context_class
);
1671 bt_put(writer_event_context
);
1674 bt_put(debug_field
);
1675 bt_put(field_class
);
1680 struct bt_clock_class
*stream_class_get_clock_class(FILE *err
,
1681 struct bt_stream_class
*stream_class
)
1683 struct bt_trace
*trace
= NULL
;
1684 struct bt_clock_class
*clock_class
= NULL
;
1686 trace
= bt_stream_class_get_trace(stream_class
);
1689 if (!bt_trace_get_clock_class_count(trace
)) {
1694 /* FIXME multi-clock? */
1695 clock_class
= bt_trace_get_clock_class_by_index(trace
, 0);
1704 struct bt_clock_class
*event_get_clock_class(FILE *err
, struct bt_event
*event
)
1706 struct bt_event_class
*event_class
= NULL
;
1707 struct bt_stream_class
*stream_class
= NULL
;
1708 struct bt_clock_class
*clock_class
= NULL
;
1710 event_class
= bt_event_get_class(event
);
1711 BT_ASSERT(event_class
);
1713 stream_class
= bt_event_class_get_stream_class(event_class
);
1714 BT_ASSERT(stream_class
);
1716 clock_class
= stream_class_get_clock_class(err
, stream_class
);
1720 bt_put(stream_class
);
1721 bt_put(event_class
);
1726 int set_event_clock_value(FILE *err
, struct bt_event
*event
,
1727 struct bt_event
*writer_event
)
1729 struct bt_clock_class
*clock_class
= NULL
;
1730 struct bt_clock_value
*clock_value
= NULL
;
1733 clock_class
= event_get_clock_class(err
, event
);
1735 /* No clock on input trace. */
1739 clock_value
= bt_event_get_clock_value(event
, clock_class
);
1746 * We share the same clocks, so we can assign the clock value to the
1749 ret
= bt_event_set_clock_value(writer_event
, clock_value
);
1751 BT_LOGE_STR("Failed to set clock value.");
1761 bt_put(clock_class
);
1762 bt_put(clock_value
);
1767 struct bt_event
*debug_info_copy_event(FILE *err
, struct bt_event
*event
,
1768 struct bt_event_class
*writer_event_class
,
1769 struct debug_info
*debug_info
,
1770 struct debug_info_component
*component
)
1772 struct bt_event
*writer_event
= NULL
;
1773 struct bt_field
*field
= NULL
, *copy_field
= NULL
;
1776 writer_event
= bt_event_create(writer_event_class
);
1777 if (!writer_event
) {
1778 BT_LOGE_STR("Failed to create new event.");
1782 ret
= set_event_clock_value(err
, event
, writer_event
);
1784 BT_LOGE_STR("Failed to set clock value.");
1788 /* Optional field, so it can fail silently. */
1789 field
= bt_event_get_header(event
);
1791 ret
= ctf_copy_event_header(err
, event
, writer_event_class
,
1792 writer_event
, field
);
1794 BT_LOGE_STR("Failed to copy event header.");
1800 /* Optional field, so it can fail silently. */
1801 field
= bt_event_get_stream_event_context(event
);
1803 ret
= copy_set_debug_info_stream_event_context(err
,
1804 field
, event
, writer_event
, debug_info
,
1807 BT_LOGE_STR("Failed to debug_info stream event context.");
1813 /* Optional field, so it can fail silently. */
1814 field
= bt_event_get_event_context(event
);
1816 copy_field
= bt_field_copy(field
);
1818 BT_LOGE_STR("Failed to copy field.");
1821 ret
= bt_event_set_event_context(writer_event
, copy_field
);
1823 BT_LOGE_STR("Failed to set event_context.");
1830 field
= bt_event_get_event_payload(event
);
1833 copy_field
= bt_field_copy(field
);
1835 ret
= bt_event_set_event_payload(writer_event
, copy_field
);
1837 BT_LOGE_STR("Failed to set event payload.");
1847 BT_PUT(writer_event
);
1851 return writer_event
;
1855 struct bt_event
*debug_info_output_event(
1856 struct debug_info_iterator
*debug_it
,
1857 struct bt_event
*event
)
1859 struct bt_event_class
*event_class
= NULL
, *writer_event_class
= NULL
;
1860 struct bt_stream_class
*stream_class
= NULL
, *writer_stream_class
= NULL
;
1861 struct bt_event
*writer_event
= NULL
;
1862 struct bt_packet
*packet
= NULL
, *writer_packet
= NULL
;
1863 struct bt_trace
*writer_trace
= NULL
;
1864 struct bt_stream
*stream
= NULL
;
1865 struct debug_info_trace
*di_trace
;
1866 struct debug_info
*debug_info
;
1869 event_class
= bt_event_get_class(event
);
1870 BT_ASSERT(event_class
);
1872 stream_class
= bt_event_class_get_stream_class(event_class
);
1873 BT_ASSERT(stream_class
);
1875 stream
= bt_event_get_stream(event
);
1878 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1880 BT_LOGE_STR("Failed to find existing trace from stream.");
1884 writer_stream_class
= g_hash_table_lookup(
1885 di_trace
->stream_class_map
,
1886 (gpointer
) stream_class
);
1887 if (!writer_stream_class
) {
1888 BT_LOGE_STR("Failed to find existing stream_class.");
1891 bt_get(writer_stream_class
);
1892 writer_trace
= bt_stream_class_get_trace(writer_stream_class
);
1893 BT_ASSERT(writer_trace
);
1894 writer_event_class
= get_event_class(debug_it
,
1895 writer_stream_class
, event_class
);
1896 if (!writer_event_class
) {
1897 writer_event_class
= ctf_copy_event_class(debug_it
->err
,
1898 writer_trace
, event_class
);
1899 if (!writer_event_class
) {
1900 BT_LOGE_STR("Failed to copy event_class.");
1903 int_ret
= bt_stream_class_add_event_class(
1904 writer_stream_class
, writer_event_class
);
1906 BT_LOGE_STR("Failed to add event_class.");
1911 debug_info
= get_trace_debug_info(debug_it
, writer_trace
, di_trace
);
1913 debug_info_handle_event(debug_it
->err
, event
, debug_info
);
1916 writer_event
= debug_info_copy_event(debug_it
->err
, event
,
1917 writer_event_class
, debug_info
,
1918 debug_it
->debug_info_component
);
1919 if (!writer_event
) {
1920 BT_LOGE("Failed to copy event: event-class-name=\"%s\"",
1921 bt_event_class_get_name(writer_event_class
));
1925 packet
= bt_event_get_packet(event
);
1928 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1929 if (!writer_packet
) {
1930 BT_LOGE_STR("Failed to find existing packet.");
1933 bt_get(writer_packet
);
1935 int_ret
= bt_event_set_packet(writer_event
, writer_packet
);
1937 BT_LOGE("Failed to append event to event-class-name=\"%s\"",
1938 bt_event_class_get_name(writer_event_class
));
1942 /* Keep the reference on the writer event */
1946 BT_PUT(writer_event
);
1950 bt_put(writer_trace
);
1951 bt_put(writer_packet
);
1953 bt_put(writer_event_class
);
1954 bt_put(writer_stream_class
);
1955 bt_put(stream_class
);
1956 bt_put(event_class
);
1957 return writer_event
;