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
30 #include <babeltrace/ctf-ir/event.h>
31 #include <babeltrace/ctf-ir/packet.h>
32 #include <babeltrace/ctf-ir/event-class.h>
33 #include <babeltrace/ctf-ir/stream.h>
34 #include <babeltrace/ctf-ir/stream-class.h>
35 #include <babeltrace/ctf-ir/clock-class.h>
36 #include <babeltrace/ctf-ir/fields.h>
37 #include <babeltrace/ctf-writer/stream-class.h>
38 #include <babeltrace/ctf-writer/stream.h>
40 #include <ctfcopytrace.h>
41 #include "debug-info.h"
44 void unref_stream(struct bt_ctf_stream
*stream
)
50 void unref_packet(struct bt_ctf_packet
*packet
)
56 void unref_stream_class(struct bt_ctf_stream_class
*stream_class
)
62 void unref_debug_info(struct debug_info
*debug_info
)
64 debug_info_destroy(debug_info
);
68 void destroy_stream_state_key(gpointer key
)
70 g_free((enum fs_writer_stream_state
*) key
);
74 struct bt_ctf_field
*get_payload_field(FILE *err
,
75 struct bt_ctf_event
*event
, const char *field_name
)
77 struct bt_ctf_field
*field
= NULL
, *sec
= NULL
;
78 struct bt_ctf_field_type
*sec_type
= NULL
;
80 sec
= bt_ctf_event_get_payload(event
, NULL
);
82 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
87 sec_type
= bt_ctf_field_get_type(sec
);
89 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
94 if (bt_ctf_field_type_get_type_id(sec_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
95 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
100 field
= bt_ctf_field_structure_get_field(sec
, field_name
);
109 struct bt_ctf_field
*get_stream_event_context_field(FILE *err
,
110 struct bt_ctf_event
*event
, const char *field_name
)
112 struct bt_ctf_field
*field
= NULL
, *sec
= NULL
;
113 struct bt_ctf_field_type
*sec_type
= NULL
;
115 sec
= bt_ctf_event_get_stream_event_context(event
);
120 sec_type
= bt_ctf_field_get_type(sec
);
122 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
127 if (bt_ctf_field_type_get_type_id(sec_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
128 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
133 field
= bt_ctf_field_structure_get_field(sec
, field_name
);
142 int get_stream_event_context_unsigned_int_field_value(FILE *err
,
143 struct bt_ctf_event
*event
, const char *field_name
,
147 struct bt_ctf_field
*field
= NULL
;
148 struct bt_ctf_field_type
*field_type
= NULL
;
150 field
= get_stream_event_context_field(err
, event
, field_name
);
155 field_type
= bt_ctf_field_get_type(field
);
157 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
162 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
163 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
168 if (bt_ctf_field_type_integer_get_signed(field_type
) != 0) {
169 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
174 ret
= bt_ctf_field_unsigned_integer_get_value(field
, value
);
186 int get_stream_event_context_int_field_value(FILE *err
, struct bt_ctf_event
*event
,
187 const char *field_name
, int64_t *value
)
189 struct bt_ctf_field
*field
= NULL
;
190 struct bt_ctf_field_type
*field_type
= NULL
;
193 field
= get_stream_event_context_field(err
, event
, field_name
);
198 field_type
= bt_ctf_field_get_type(field
);
200 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
205 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
206 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
211 if (bt_ctf_field_type_integer_get_signed(field_type
) != 1) {
212 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
217 ret
= bt_ctf_field_signed_integer_get_value(field
, value
);
229 int get_payload_unsigned_int_field_value(FILE *err
,
230 struct bt_ctf_event
*event
, const char *field_name
,
233 struct bt_ctf_field
*field
= NULL
;
234 struct bt_ctf_field_type
*field_type
= NULL
;
237 field
= get_payload_field(err
, event
, field_name
);
239 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
244 field_type
= bt_ctf_field_get_type(field
);
246 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
251 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
252 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
257 if (bt_ctf_field_type_integer_get_signed(field_type
) != 0) {
258 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
263 ret
= bt_ctf_field_unsigned_integer_get_value(field
, value
);
275 int get_payload_int_field_value(FILE *err
, struct bt_ctf_event
*event
,
276 const char *field_name
, int64_t *value
)
278 struct bt_ctf_field
*field
= NULL
;
279 struct bt_ctf_field_type
*field_type
= NULL
;
282 field
= get_payload_field(err
, event
, field_name
);
284 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
289 field_type
= bt_ctf_field_get_type(field
);
291 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
296 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
297 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
302 if (bt_ctf_field_type_integer_get_signed(field_type
) != 1) {
303 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
308 ret
= bt_ctf_field_signed_integer_get_value(field
, value
);
320 int get_payload_string_field_value(FILE *err
,
321 struct bt_ctf_event
*event
, const char *field_name
,
324 struct bt_ctf_field
*field
= NULL
;
325 struct bt_ctf_field_type
*field_type
= NULL
;
329 * The field might not exist, no error here.
331 field
= get_payload_field(err
, event
, field_name
);
336 field_type
= bt_ctf_field_get_type(field
);
338 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
343 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_STRING
) {
344 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
349 *value
= bt_ctf_field_string_get_value(field
);
351 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
368 int get_payload_build_id_field_value(FILE *err
,
369 struct bt_ctf_event
*event
, const char *field_name
,
370 uint8_t **build_id
, uint64_t *build_id_len
)
372 struct bt_ctf_field
*field
= NULL
, *seq_len
= NULL
;
373 struct bt_ctf_field_type
*field_type
= NULL
;
374 struct bt_ctf_field
*seq_field
= NULL
;
380 field
= get_payload_field(err
, event
, field_name
);
382 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
387 field_type
= bt_ctf_field_get_type(field
);
389 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
394 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
395 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
401 seq_len
= bt_ctf_field_sequence_get_length(field
);
403 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
408 ret
= bt_ctf_field_unsigned_integer_get_value(seq_len
, build_id_len
);
410 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
416 *build_id
= g_new0(uint8_t, *build_id_len
);
418 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
423 for (i
= 0; i
< *build_id_len
; i
++) {
426 seq_field
= bt_ctf_field_sequence_get_field(field
, i
);
428 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
433 ret
= bt_ctf_field_unsigned_integer_get_value(seq_field
, &tmp
);
435 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
440 (*build_id
)[i
] = (uint8_t) tmp
;
455 struct debug_info
*lookup_trace_debug_info(struct debug_info_iterator
*debug_it
,
456 struct bt_ctf_trace
*writer_trace
,
457 struct debug_info_trace
*di_trace
)
459 return (struct debug_info
*) g_hash_table_lookup(
460 di_trace
->trace_debug_map
,
461 (gpointer
) writer_trace
);
465 struct debug_info
*insert_new_debug_info(struct debug_info_iterator
*debug_it
,
466 struct bt_ctf_trace
*writer_trace
,
467 struct debug_info_trace
*di_trace
)
469 struct debug_info
*debug_info
= NULL
;
470 struct bt_value
*field
= NULL
;
471 const char *str_value
;
472 enum bt_value_status ret
;
474 field
= bt_ctf_trace_get_environment_field_value_by_name(writer_trace
,
476 /* No domain field, no debug info */
480 ret
= bt_value_string_get(field
, &str_value
);
481 if (ret
!= BT_VALUE_STATUS_OK
) {
482 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
486 /* Domain not ust, no debug info */
487 if (strcmp(str_value
, "ust") != 0) {
492 /* No tracer_name, no debug info */
493 field
= bt_ctf_trace_get_environment_field_value_by_name(writer_trace
,
495 /* No tracer_name, no debug info */
499 ret
= bt_value_string_get(field
, &str_value
);
500 if (ret
!= BT_VALUE_STATUS_OK
) {
501 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
505 /* Tracer_name not lttng-ust, no debug info */
506 if (strcmp(str_value
, "lttng-ust") != 0) {
511 debug_info
= debug_info_create(debug_it
->debug_info_component
);
513 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
518 g_hash_table_insert(di_trace
->trace_debug_map
, (gpointer
) writer_trace
,
527 struct debug_info
*get_trace_debug_info(struct debug_info_iterator
*debug_it
,
528 struct bt_ctf_trace
*writer_trace
,
529 struct debug_info_trace
*di_trace
)
531 struct debug_info
*debug_info
;
533 debug_info
= lookup_trace_debug_info(debug_it
, writer_trace
, di_trace
);
538 debug_info
= insert_new_debug_info(debug_it
, writer_trace
, di_trace
);
545 struct debug_info_trace
*lookup_trace(struct debug_info_iterator
*debug_it
,
546 struct bt_ctf_trace
*trace
)
548 return (struct debug_info_trace
*) g_hash_table_lookup(
554 enum debug_info_stream_state
*insert_new_stream_state(
555 struct debug_info_iterator
*debug_it
,
556 struct debug_info_trace
*di_trace
, struct bt_ctf_stream
*stream
)
558 enum debug_info_stream_state
*v
= NULL
;
560 v
= g_new0(enum debug_info_stream_state
, 1);
562 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
565 *v
= DEBUG_INFO_UNKNOWN_STREAM
;
567 g_hash_table_insert(di_trace
->stream_states
, stream
, v
);
573 void check_completed_trace(gpointer key
, gpointer value
, gpointer user_data
)
575 enum debug_info_stream_state
*state
= value
;
576 int *trace_completed
= user_data
;
578 if (*state
!= DEBUG_INFO_COMPLETED_STREAM
) {
579 *trace_completed
= 0;
584 gboolean
empty_ht(gpointer key
, gpointer value
, gpointer user_data
)
590 void debug_info_close_trace(struct debug_info_iterator
*debug_it
,
591 struct debug_info_trace
*di_trace
)
593 if (di_trace
->static_listener_id
> 0) {
594 bt_ctf_trace_remove_is_static_listener(di_trace
->trace
,
595 di_trace
->static_listener_id
);
598 /* Empty the stream class HT. */
599 g_hash_table_foreach_remove(di_trace
->stream_class_map
,
601 g_hash_table_destroy(di_trace
->stream_class_map
);
603 /* Empty the stream HT. */
604 g_hash_table_foreach_remove(di_trace
->stream_map
,
606 g_hash_table_destroy(di_trace
->stream_map
);
608 /* Empty the stream state HT. */
609 g_hash_table_foreach_remove(di_trace
->stream_states
,
611 g_hash_table_destroy(di_trace
->stream_states
);
613 /* Empty the packet HT. */
614 g_hash_table_foreach_remove(di_trace
->packet_map
,
616 g_hash_table_destroy(di_trace
->packet_map
);
618 /* Empty the trace_debug HT. */
619 g_hash_table_foreach_remove(di_trace
->trace_debug_map
,
621 g_hash_table_destroy(di_trace
->trace_debug_map
);
625 void trace_is_static_listener(struct bt_ctf_trace
*trace
, void *data
)
627 struct debug_info_trace
*di_trace
= data
;
628 int trace_completed
= 1;
630 di_trace
->trace_static
= 1;
632 g_hash_table_foreach(di_trace
->stream_states
,
633 check_completed_trace
, &trace_completed
);
634 if (trace_completed
) {
635 debug_info_close_trace(di_trace
->debug_it
, di_trace
);
636 g_hash_table_remove(di_trace
->debug_it
->trace_map
,
642 struct debug_info_trace
*insert_new_trace(struct debug_info_iterator
*debug_it
,
643 struct bt_ctf_stream
*stream
) {
644 struct bt_ctf_trace
*writer_trace
= NULL
;
645 struct debug_info_trace
*di_trace
= NULL
;
646 struct bt_ctf_trace
*trace
= NULL
;
647 struct bt_ctf_stream_class
*stream_class
= NULL
;
648 int ret
, nr_stream
, i
;
650 writer_trace
= bt_ctf_trace_create();
652 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
657 stream_class
= bt_ctf_stream_get_class(stream
);
659 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
664 trace
= bt_ctf_stream_class_get_trace(stream_class
);
666 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
671 ret
= ctf_copy_trace(debug_it
->err
, trace
, writer_trace
);
672 if (ret
!= BT_COMPONENT_STATUS_OK
) {
673 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
678 di_trace
= g_new0(struct debug_info_trace
, 1);
680 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
685 di_trace
->trace
= trace
;
686 di_trace
->writer_trace
= writer_trace
;
687 di_trace
->debug_info_component
= debug_it
->debug_info_component
;
688 di_trace
->debug_it
= debug_it
;
689 di_trace
->stream_map
= g_hash_table_new_full(g_direct_hash
,
690 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream
);
691 di_trace
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
692 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream_class
);
693 di_trace
->packet_map
= g_hash_table_new_full(g_direct_hash
,
694 g_direct_equal
, NULL
, (GDestroyNotify
) unref_packet
);
695 di_trace
->trace_debug_map
= g_hash_table_new_full(g_direct_hash
,
696 g_direct_equal
, NULL
, (GDestroyNotify
) unref_debug_info
);
697 di_trace
->stream_states
= g_hash_table_new_full(g_direct_hash
,
698 g_direct_equal
, NULL
, destroy_stream_state_key
);
700 /* Set all the existing streams in the unknown state. */
701 nr_stream
= bt_ctf_trace_get_stream_count(trace
);
702 for (i
= 0; i
< nr_stream
; i
++) {
703 stream
= bt_ctf_trace_get_stream_by_index(trace
, i
);
705 fprintf(debug_it
->err
,
706 "[error] %s in %s:%d\n", __func__
,
710 insert_new_stream_state(debug_it
, di_trace
, stream
);
714 /* Check if the trace is already static or register a listener. */
715 if (bt_ctf_trace_is_static(trace
)) {
716 di_trace
->trace_static
= 1;
717 di_trace
->static_listener_id
= -1;
719 ret
= bt_ctf_trace_add_is_static_listener(trace
,
720 trace_is_static_listener
, di_trace
);
722 fprintf(debug_it
->err
,
723 "[error] %s in %s:%d\n", __func__
, __FILE__
,
727 di_trace
->static_listener_id
= ret
;
730 g_hash_table_insert(debug_it
->trace_map
, (gpointer
) trace
, di_trace
);
735 BT_PUT(writer_trace
);
739 bt_put(stream_class
);
745 struct bt_ctf_packet
*lookup_packet(struct debug_info_iterator
*debug_it
,
746 struct bt_ctf_packet
*packet
,
747 struct debug_info_trace
*di_trace
)
749 return (struct bt_ctf_packet
*) g_hash_table_lookup(
750 di_trace
->packet_map
,
755 struct bt_ctf_packet
*insert_new_packet(struct debug_info_iterator
*debug_it
,
756 struct bt_ctf_packet
*packet
,
757 struct bt_ctf_stream
*writer_stream
,
758 struct debug_info_trace
*di_trace
)
760 struct bt_ctf_packet
*writer_packet
;
762 writer_packet
= bt_ctf_packet_create(writer_stream
);
763 if (!writer_packet
) {
764 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
768 g_hash_table_insert(di_trace
->packet_map
, (gpointer
) packet
, writer_packet
);
771 return writer_packet
;
775 int add_debug_info_fields(FILE *err
,
776 struct bt_ctf_field_type
*writer_event_context_type
,
777 struct debug_info_component
*component
)
779 struct bt_ctf_field_type
*ip_field
= NULL
, *debug_field_type
= NULL
,
780 *bin_field_type
= NULL
, *func_field_type
= NULL
,
781 *src_field_type
= NULL
;
784 ip_field
= bt_ctf_field_type_structure_get_field_type_by_name(
785 writer_event_context_type
, "_ip");
786 /* No ip field, so no debug info. */
792 debug_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
793 writer_event_context_type
,
794 component
->arg_debug_info_field_name
);
795 /* Already existing debug_info field, no need to add it. */
796 if (debug_field_type
) {
800 debug_field_type
= bt_ctf_field_type_structure_create();
801 if (!debug_field_type
) {
802 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
807 bin_field_type
= bt_ctf_field_type_string_create();
808 if (!bin_field_type
) {
809 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
814 func_field_type
= bt_ctf_field_type_string_create();
815 if (!func_field_type
) {
816 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
821 src_field_type
= bt_ctf_field_type_string_create();
822 if (!src_field_type
) {
823 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
828 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
829 bin_field_type
, "bin");
831 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
836 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
837 func_field_type
, "func");
839 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
844 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
845 src_field_type
, "src");
847 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
852 ret
= bt_ctf_field_type_structure_add_field(writer_event_context_type
,
853 debug_field_type
, component
->arg_debug_info_field_name
);
855 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
864 BT_PUT(debug_field_type
);
867 bt_put(src_field_type
);
868 bt_put(func_field_type
);
869 bt_put(bin_field_type
);
870 bt_put(debug_field_type
);
875 int create_debug_info_event_context_type(FILE *err
,
876 struct bt_ctf_field_type
*event_context_type
,
877 struct bt_ctf_field_type
*writer_event_context_type
,
878 struct debug_info_component
*component
)
880 int ret
, nr_fields
, i
;
882 nr_fields
= bt_ctf_field_type_structure_get_field_count(event_context_type
);
883 for (i
= 0; i
< nr_fields
; i
++) {
884 struct bt_ctf_field_type
*field_type
= NULL
;
885 const char *field_name
;
887 if (bt_ctf_field_type_structure_get_field(event_context_type
,
888 &field_name
, &field_type
, i
) < 0) {
889 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
894 ret
= bt_ctf_field_type_structure_add_field(writer_event_context_type
,
895 field_type
, field_name
);
898 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
904 ret
= add_debug_info_fields(err
, writer_event_context_type
,
915 struct bt_ctf_stream_class
*copy_stream_class_debug_info(FILE *err
,
916 struct bt_ctf_stream_class
*stream_class
,
917 struct bt_ctf_trace
*writer_trace
,
918 struct debug_info_component
*component
)
920 struct bt_ctf_field_type
*type
= NULL
;
921 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
922 struct bt_ctf_field_type
*writer_event_context_type
= NULL
;
924 const char *name
= bt_ctf_stream_class_get_name(stream_class
);
926 if (strlen(name
) == 0) {
930 writer_stream_class
= bt_ctf_stream_class_create(name
);
931 if (!writer_stream_class
) {
932 fprintf(err
, "[error] %s in %s:%d\n",
933 __func__
, __FILE__
, __LINE__
);
937 type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
939 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
944 ret_int
= bt_ctf_stream_class_set_packet_context_type(
945 writer_stream_class
, type
);
947 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
953 type
= bt_ctf_stream_class_get_event_header_type(stream_class
);
955 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
960 ret_int
= bt_ctf_stream_class_set_event_header_type(
961 writer_stream_class
, type
);
963 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
969 type
= bt_ctf_stream_class_get_event_context_type(stream_class
);
971 writer_event_context_type
= bt_ctf_field_type_structure_create();
972 if (!writer_event_context_type
) {
973 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
977 ret_int
= create_debug_info_event_context_type(err
, type
,
978 writer_event_context_type
, component
);
980 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
986 ret_int
= bt_ctf_stream_class_set_event_context_type(
987 writer_stream_class
, writer_event_context_type
);
989 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
993 BT_PUT(writer_event_context_type
);
999 BT_PUT(writer_stream_class
);
1001 bt_put(writer_event_context_type
);
1003 return writer_stream_class
;
1007 * Add the original clock classes to the new trace, we do not need to copy
1008 * them, and if we did, we would have to manually inspect the stream class
1009 * to update the integers mapping to a clock.
1012 int add_clock_classes(FILE *err
, struct bt_ctf_trace
*writer_trace
,
1013 struct bt_ctf_stream_class
*writer_stream_class
,
1014 struct bt_ctf_trace
*trace
)
1016 int ret
, clock_class_count
, i
;
1018 clock_class_count
= bt_ctf_trace_get_clock_class_count(trace
);
1020 for (i
= 0; i
< clock_class_count
; i
++) {
1021 struct bt_ctf_clock_class
*clock_class
=
1022 bt_ctf_trace_get_clock_class_by_index(trace
, i
);
1025 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1030 ret
= bt_ctf_trace_add_clock_class(writer_trace
, clock_class
);
1031 BT_PUT(clock_class
);
1033 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1050 struct bt_ctf_stream_class
*insert_new_stream_class(
1051 struct debug_info_iterator
*debug_it
,
1052 struct bt_ctf_stream_class
*stream_class
)
1054 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
1055 struct bt_ctf_trace
*trace
, *writer_trace
= NULL
;
1056 struct debug_info_trace
*di_trace
;
1057 enum bt_component_status ret
;
1060 trace
= bt_ctf_stream_class_get_trace(stream_class
);
1062 fprintf(debug_it
->err
,
1063 "[error] %s in %s:%d\n", __func__
, __FILE__
,
1068 di_trace
= lookup_trace(debug_it
, trace
);
1070 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1071 __FILE__
, __LINE__
);
1072 ret
= BT_COMPONENT_STATUS_ERROR
;
1075 writer_trace
= di_trace
->writer_trace
;
1076 bt_get(writer_trace
);
1078 writer_stream_class
= copy_stream_class_debug_info(debug_it
->err
, stream_class
,
1079 writer_trace
, debug_it
->debug_info_component
);
1080 if (!writer_stream_class
) {
1081 fprintf(debug_it
->err
, "[error] Failed to copy stream class\n");
1082 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1083 __func__
, __FILE__
, __LINE__
);
1087 int_ret
= bt_ctf_trace_add_stream_class(writer_trace
, writer_stream_class
);
1089 fprintf(debug_it
->err
,
1090 "[error] %s in %s:%d\n", __func__
, __FILE__
,
1095 ret
= add_clock_classes(debug_it
->err
, writer_trace
,
1096 writer_stream_class
, trace
);
1097 if (ret
!= BT_COMPONENT_STATUS_OK
) {
1098 fprintf(debug_it
->err
,
1099 "[error] %s in %s:%d\n", __func__
, __FILE__
,
1104 g_hash_table_insert(di_trace
->stream_class_map
,
1105 (gpointer
) stream_class
, writer_stream_class
);
1110 BT_PUT(writer_stream_class
);
1113 bt_put(writer_trace
);
1114 return writer_stream_class
;
1118 struct bt_ctf_stream
*insert_new_stream(
1119 struct debug_info_iterator
*debug_it
,
1120 struct bt_ctf_stream
*stream
,
1121 struct debug_info_trace
*di_trace
)
1123 struct bt_ctf_stream
*writer_stream
= NULL
;
1124 struct bt_ctf_stream_class
*stream_class
= NULL
;
1125 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
1127 stream_class
= bt_ctf_stream_get_class(stream
);
1128 if (!stream_class
) {
1129 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1130 __func__
, __FILE__
, __LINE__
);
1134 writer_stream_class
= g_hash_table_lookup(
1135 di_trace
->stream_class_map
,
1136 (gpointer
) stream_class
);
1138 if (!writer_stream_class
) {
1139 writer_stream_class
= insert_new_stream_class(debug_it
,
1141 if (!writer_stream_class
) {
1142 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1143 __func__
, __FILE__
, __LINE__
);
1147 bt_get(writer_stream_class
);
1149 writer_stream
= bt_ctf_stream_create(writer_stream_class
,
1150 bt_ctf_stream_get_name(stream
));
1151 if (!writer_stream
) {
1152 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1153 __func__
, __FILE__
, __LINE__
);
1157 g_hash_table_insert(di_trace
->stream_map
, (gpointer
) stream
,
1163 BT_PUT(writer_stream
);
1165 bt_put(stream_class
);
1166 bt_put(writer_stream_class
);
1167 return writer_stream
;
1171 struct bt_ctf_stream
*lookup_stream(struct debug_info_iterator
*debug_it
,
1172 struct bt_ctf_stream
*stream
,
1173 struct debug_info_trace
*di_trace
)
1175 return (struct bt_ctf_stream
*) g_hash_table_lookup(
1176 di_trace
->stream_map
, (gpointer
) stream
);
1180 struct bt_ctf_event_class
*get_event_class(struct debug_info_iterator
*debug_it
,
1181 struct bt_ctf_stream_class
*writer_stream_class
,
1182 struct bt_ctf_event_class
*event_class
)
1184 return bt_ctf_stream_class_get_event_class_by_id(writer_stream_class
,
1185 bt_ctf_event_class_get_id(event_class
));
1189 struct debug_info_trace
*lookup_di_trace_from_stream(
1190 struct debug_info_iterator
*debug_it
,
1191 struct bt_ctf_stream
*stream
)
1193 struct bt_ctf_stream_class
*stream_class
= NULL
;
1194 struct bt_ctf_trace
*trace
= NULL
;
1195 struct debug_info_trace
*di_trace
= NULL
;
1197 stream_class
= bt_ctf_stream_get_class(stream
);
1198 if (!stream_class
) {
1199 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1200 __func__
, __FILE__
, __LINE__
);
1204 trace
= bt_ctf_stream_class_get_trace(stream_class
);
1206 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1207 __func__
, __FILE__
, __LINE__
);
1211 di_trace
= (struct debug_info_trace
*) g_hash_table_lookup(
1212 debug_it
->trace_map
, (gpointer
) trace
);
1215 BT_PUT(stream_class
);
1221 struct bt_ctf_stream
*get_writer_stream(
1222 struct debug_info_iterator
*debug_it
,
1223 struct bt_ctf_packet
*packet
, struct bt_ctf_stream
*stream
)
1225 struct bt_ctf_stream_class
*stream_class
= NULL
;
1226 struct bt_ctf_stream
*writer_stream
= NULL
;
1227 struct debug_info_trace
*di_trace
= NULL
;
1229 stream_class
= bt_ctf_stream_get_class(stream
);
1230 if (!stream_class
) {
1231 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1232 __func__
, __FILE__
, __LINE__
);
1236 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1238 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1239 __func__
, __FILE__
, __LINE__
);
1243 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1244 if (!writer_stream
) {
1245 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1246 __func__
, __FILE__
, __LINE__
);
1249 bt_get(writer_stream
);
1254 BT_PUT(writer_stream
);
1256 bt_put(stream_class
);
1257 return writer_stream
;
1261 struct bt_ctf_packet
*debug_info_new_packet(
1262 struct debug_info_iterator
*debug_it
,
1263 struct bt_ctf_packet
*packet
)
1265 struct bt_ctf_stream
*stream
= NULL
, *writer_stream
= NULL
;
1266 struct bt_ctf_field
*writer_packet_context
= NULL
;
1267 struct bt_ctf_packet
*writer_packet
= NULL
;
1268 struct debug_info_trace
*di_trace
;
1271 stream
= bt_ctf_packet_get_stream(packet
);
1273 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1274 __func__
, __FILE__
, __LINE__
);
1278 writer_stream
= get_writer_stream(debug_it
, packet
, stream
);
1279 if (!writer_stream
) {
1280 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1281 __func__
, __FILE__
, __LINE__
);
1285 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1287 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1288 __FILE__
, __LINE__
);
1293 * If a packet was already opened, close it and remove it from
1296 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1297 if (writer_packet
) {
1298 g_hash_table_remove(di_trace
->packet_map
, packet
);
1299 BT_PUT(writer_packet
);
1302 writer_packet
= insert_new_packet(debug_it
, packet
, writer_stream
,
1304 if (!writer_packet
) {
1305 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1306 __func__
, __FILE__
, __LINE__
);
1310 writer_packet_context
= ctf_copy_packet_context(debug_it
->err
, packet
,
1312 if (!writer_packet_context
) {
1313 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1314 __func__
, __FILE__
, __LINE__
);
1318 int_ret
= bt_ctf_packet_set_context(writer_packet
, writer_packet_context
);
1320 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1321 __func__
, __FILE__
, __LINE__
);
1325 bt_get(writer_packet
);
1331 bt_put(writer_packet_context
);
1332 bt_put(writer_stream
);
1334 return writer_packet
;
1338 struct bt_ctf_packet
*debug_info_close_packet(
1339 struct debug_info_iterator
*debug_it
,
1340 struct bt_ctf_packet
*packet
)
1342 struct bt_ctf_packet
*writer_packet
= NULL
;
1343 struct bt_ctf_stream
*stream
= NULL
;
1344 struct debug_info_trace
*di_trace
;
1346 stream
= bt_ctf_packet_get_stream(packet
);
1348 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1349 __FILE__
, __LINE__
);
1353 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1355 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1356 __FILE__
, __LINE__
);
1360 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1361 if (!writer_packet
) {
1362 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1363 __func__
, __FILE__
, __LINE__
);
1366 bt_get(writer_packet
);
1367 g_hash_table_remove(di_trace
->packet_map
, packet
);
1371 return writer_packet
;
1375 struct bt_ctf_stream
*debug_info_stream_begin(
1376 struct debug_info_iterator
*debug_it
,
1377 struct bt_ctf_stream
*stream
)
1379 struct bt_ctf_stream
*writer_stream
;
1380 enum debug_info_stream_state
*state
;
1381 struct debug_info_trace
*di_trace
= NULL
;
1383 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1385 di_trace
= insert_new_trace(debug_it
, stream
);
1387 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1388 __func__
, __FILE__
, __LINE__
);
1393 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1394 if (writer_stream
) {
1395 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1396 __func__
, __FILE__
, __LINE__
);
1400 /* Set the stream as active */
1401 state
= g_hash_table_lookup(di_trace
->stream_states
, stream
);
1403 if (di_trace
->trace_static
) {
1404 fprintf(debug_it
->err
, "[error] Adding a new stream "
1405 "on a static trace\n");
1408 state
= insert_new_stream_state(debug_it
, di_trace
,
1411 if (*state
!= DEBUG_INFO_UNKNOWN_STREAM
) {
1412 fprintf(debug_it
->err
, "[error] Unexpected stream state %d\n",
1416 *state
= DEBUG_INFO_ACTIVE_STREAM
;
1418 writer_stream
= insert_new_stream(debug_it
, stream
, di_trace
);
1419 bt_get(writer_stream
);
1424 BT_PUT(writer_stream
);
1426 return writer_stream
;
1430 struct bt_ctf_stream
*debug_info_stream_end(struct debug_info_iterator
*debug_it
,
1431 struct bt_ctf_stream
*stream
)
1433 struct bt_ctf_stream
*writer_stream
;
1434 struct debug_info_trace
*di_trace
= NULL
;
1435 enum debug_info_stream_state
*state
;
1437 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1439 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1440 __func__
, __FILE__
, __LINE__
);
1444 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1445 if (!writer_stream
) {
1446 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1447 __func__
, __FILE__
, __LINE__
);
1451 * Take the ref on the stream and keep it until the notification
1454 bt_get(writer_stream
);
1456 state
= g_hash_table_lookup(di_trace
->stream_states
, stream
);
1457 if (*state
!= DEBUG_INFO_ACTIVE_STREAM
) {
1458 fprintf(debug_it
->err
, "[error] Unexpected stream "
1459 "state %d\n", *state
);
1462 *state
= DEBUG_INFO_COMPLETED_STREAM
;
1464 g_hash_table_remove(di_trace
->stream_map
, stream
);
1466 if (di_trace
->trace_static
) {
1467 int trace_completed
= 1;
1469 g_hash_table_foreach(di_trace
->stream_states
,
1470 check_completed_trace
, &trace_completed
);
1471 if (trace_completed
) {
1472 debug_info_close_trace(debug_it
, di_trace
);
1473 g_hash_table_remove(debug_it
->trace_map
,
1481 BT_PUT(writer_stream
);
1484 return writer_stream
;
1488 struct debug_info_source
*lookup_debug_info(FILE *err
,
1489 struct bt_ctf_event
*event
,
1490 struct debug_info
*debug_info
)
1494 struct debug_info_source
*dbg_info_src
= NULL
;
1497 ret
= get_stream_event_context_int_field_value(err
, event
,
1503 ret
= get_stream_event_context_unsigned_int_field_value(err
, event
,
1509 /* Get debug info for this context. */
1510 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1513 return dbg_info_src
;
1517 int set_debug_info_field(FILE *err
, struct bt_ctf_field
*debug_field
,
1518 struct debug_info_source
*dbg_info_src
,
1519 struct debug_info_component
*component
)
1521 int i
, nr_fields
, ret
= 0;
1522 struct bt_ctf_field_type
*debug_field_type
= NULL
;
1523 struct bt_ctf_field
*field
= NULL
;
1524 struct bt_ctf_field_type
*field_type
= NULL
;
1526 debug_field_type
= bt_ctf_field_get_type(debug_field
);
1527 if (!debug_field_type
) {
1528 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1529 __FILE__
, __LINE__
);
1533 nr_fields
= bt_ctf_field_type_structure_get_field_count(debug_field_type
);
1534 for (i
= 0; i
< nr_fields
; i
++) {
1535 const char *field_name
;
1537 if (bt_ctf_field_type_structure_get_field(debug_field_type
,
1538 &field_name
, &field_type
, i
) < 0) {
1539 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1540 __FILE__
, __LINE__
);
1545 field
= bt_ctf_field_structure_get_field_by_index(debug_field
, i
);
1546 if (!strcmp(field_name
, "bin")) {
1547 if (dbg_info_src
&& dbg_info_src
->bin_path
) {
1548 GString
*tmp
= g_string_new(NULL
);
1550 if (component
->arg_full_path
) {
1551 g_string_printf(tmp
, "%s%s",
1552 dbg_info_src
->bin_path
,
1553 dbg_info_src
->bin_loc
);
1555 g_string_printf(tmp
, "%s%s",
1556 dbg_info_src
->short_bin_path
,
1557 dbg_info_src
->bin_loc
);
1559 ret
= bt_ctf_field_string_set_value(field
, tmp
->str
);
1560 g_string_free(tmp
, true);
1562 ret
= bt_ctf_field_string_set_value(field
, "");
1564 } else if (!strcmp(field_name
, "func")) {
1565 if (dbg_info_src
&& dbg_info_src
->func
) {
1566 ret
= bt_ctf_field_string_set_value(field
,
1567 dbg_info_src
->func
);
1569 ret
= bt_ctf_field_string_set_value(field
, "");
1571 } else if (!strcmp(field_name
, "src")) {
1572 if (dbg_info_src
&& dbg_info_src
->src_path
) {
1573 GString
*tmp
= g_string_new(NULL
);
1575 if (component
->arg_full_path
) {
1576 g_string_printf(tmp
, "%s:%" PRId64
,
1577 dbg_info_src
->src_path
,
1578 dbg_info_src
->line_no
);
1580 g_string_printf(tmp
, "%s:%" PRId64
,
1581 dbg_info_src
->short_src_path
,
1582 dbg_info_src
->line_no
);
1584 ret
= bt_ctf_field_string_set_value(field
, tmp
->str
);
1585 g_string_free(tmp
, true);
1587 ret
= bt_ctf_field_string_set_value(field
, "");
1592 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1593 __FILE__
, __LINE__
);
1605 bt_put(debug_field_type
);
1610 int copy_set_debug_info_stream_event_context(FILE *err
,
1611 struct bt_ctf_field
*event_context
,
1612 struct bt_ctf_event
*event
,
1613 struct bt_ctf_event
*writer_event
,
1614 struct debug_info
*debug_info
,
1615 struct debug_info_component
*component
)
1617 struct bt_ctf_field_type
*writer_event_context_type
= NULL
,
1618 *event_context_type
= NULL
;
1619 struct bt_ctf_field
*writer_event_context
= NULL
;
1620 struct bt_ctf_field
*field
= NULL
, *copy_field
= NULL
, *debug_field
= NULL
;
1621 struct bt_ctf_field_type
*field_type
= NULL
;
1622 struct debug_info_source
*dbg_info_src
;
1623 int ret
, nr_fields
, i
;
1625 writer_event_context
= bt_ctf_event_get_stream_event_context(writer_event
);
1626 if (!writer_event_context
) {
1627 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
, __LINE__
);
1631 writer_event_context_type
= bt_ctf_field_get_type(writer_event_context
);
1632 if (!writer_event_context_type
) {
1633 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1634 __FILE__
, __LINE__
);
1638 event_context_type
= bt_ctf_field_get_type(event_context
);
1639 if (!event_context_type
) {
1640 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1641 __FILE__
, __LINE__
);
1646 * If it is not a structure, we did not modify it to add the debug info
1647 * fields, so just assign it as is.
1649 if (bt_ctf_field_type_get_type_id(writer_event_context_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1650 ret
= bt_ctf_event_set_event_context(writer_event
, event_context
);
1654 dbg_info_src
= lookup_debug_info(err
, event
, debug_info
);
1656 nr_fields
= bt_ctf_field_type_structure_get_field_count(writer_event_context_type
);
1657 for (i
= 0; i
< nr_fields
; i
++) {
1658 const char *field_name
;
1660 if (bt_ctf_field_type_structure_get_field(writer_event_context_type
,
1661 &field_name
, &field_type
, i
) < 0) {
1662 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1663 __FILE__
, __LINE__
);
1668 * Prevent illegal access in the event_context.
1670 if (i
< bt_ctf_field_type_structure_get_field_count(event_context_type
)) {
1671 field
= bt_ctf_field_structure_get_field_by_index(event_context
, i
);
1674 * The debug_info field, only exists in the writer event or
1675 * if it was set by a earlier pass of the debug_info plugin.
1677 if (!strcmp(field_name
, component
->arg_debug_info_field_name
) &&
1679 debug_field
= bt_ctf_field_structure_get_field_by_index(
1680 writer_event_context
, i
);
1682 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1683 __FILE__
, __LINE__
);
1686 ret
= set_debug_info_field(err
, debug_field
,
1687 dbg_info_src
, component
);
1689 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1690 __FILE__
, __LINE__
);
1693 BT_PUT(debug_field
);
1695 copy_field
= bt_ctf_field_copy(field
);
1697 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1698 __FILE__
, __LINE__
);
1702 ret
= bt_ctf_field_structure_set_field(writer_event_context
,
1703 field_name
, copy_field
);
1705 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1706 __FILE__
, __LINE__
);
1721 bt_put(event_context_type
);
1722 bt_put(writer_event_context_type
);
1723 bt_put(writer_event_context
);
1726 bt_put(debug_field
);
1732 struct bt_ctf_clock_class
*stream_class_get_clock_class(FILE *err
,
1733 struct bt_ctf_stream_class
*stream_class
)
1735 struct bt_ctf_trace
*trace
= NULL
;
1736 struct bt_ctf_clock_class
*clock_class
= NULL
;
1738 trace
= bt_ctf_stream_class_get_trace(stream_class
);
1740 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1745 /* FIXME multi-clock? */
1746 clock_class
= bt_ctf_trace_get_clock_class_by_index(trace
, 0);
1755 struct bt_ctf_clock_class
*event_get_clock_class(FILE *err
, struct bt_ctf_event
*event
)
1757 struct bt_ctf_event_class
*event_class
= NULL
;
1758 struct bt_ctf_stream_class
*stream_class
= NULL
;
1759 struct bt_ctf_clock_class
*clock_class
= NULL
;
1761 event_class
= bt_ctf_event_get_class(event
);
1763 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1768 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
1769 if (!stream_class
) {
1770 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1775 clock_class
= stream_class_get_clock_class(err
, stream_class
);
1779 BT_PUT(clock_class
);
1781 bt_put(stream_class
);
1782 bt_put(event_class
);
1787 int set_event_clock_value(FILE *err
, struct bt_ctf_event
*event
,
1788 struct bt_ctf_event
*writer_event
)
1790 struct bt_ctf_clock_class
*clock_class
= NULL
;
1791 struct bt_ctf_clock_value
*clock_value
= NULL
;
1794 clock_class
= event_get_clock_class(err
, event
);
1796 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1801 clock_value
= bt_ctf_event_get_clock_value(event
, clock_class
);
1803 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1809 * We share the same clocks, so we can assign the clock value to the
1812 ret
= bt_ctf_event_set_clock_value(writer_event
, clock_value
);
1814 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1825 bt_put(clock_class
);
1826 bt_put(clock_value
);
1831 struct bt_ctf_event
*debug_info_copy_event(FILE *err
, struct bt_ctf_event
*event
,
1832 struct bt_ctf_event_class
*writer_event_class
,
1833 struct debug_info
*debug_info
,
1834 struct debug_info_component
*component
)
1836 struct bt_ctf_event
*writer_event
= NULL
;
1837 struct bt_ctf_field
*field
= NULL
, *copy_field
= NULL
;
1840 writer_event
= bt_ctf_event_create(writer_event_class
);
1841 if (!writer_event
) {
1842 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1847 ret
= set_event_clock_value(err
, event
, writer_event
);
1849 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1850 __FILE__
, __LINE__
);
1854 /* Optional field, so it can fail silently. */
1855 field
= bt_ctf_event_get_header(event
);
1857 ret
= ctf_copy_event_header(err
, event
, writer_event_class
,
1858 writer_event
, field
);
1860 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1861 __FILE__
, __LINE__
);
1867 /* Optional field, so it can fail silently. */
1868 field
= bt_ctf_event_get_stream_event_context(event
);
1870 ret
= copy_set_debug_info_stream_event_context(err
,
1871 field
, event
, writer_event
, debug_info
,
1874 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1875 __FILE__
, __LINE__
);
1881 /* Optional field, so it can fail silently. */
1882 field
= bt_ctf_event_get_event_context(event
);
1884 copy_field
= bt_ctf_field_copy(field
);
1886 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1887 __FILE__
, __LINE__
);
1890 ret
= bt_ctf_event_set_event_context(writer_event
, copy_field
);
1892 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1893 __FILE__
, __LINE__
);
1900 field
= bt_ctf_event_get_event_payload(event
);
1902 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1903 __FILE__
, __LINE__
);
1906 copy_field
= bt_ctf_field_copy(field
);
1908 ret
= bt_ctf_event_set_event_payload(writer_event
, copy_field
);
1910 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1911 __FILE__
, __LINE__
);
1921 BT_PUT(writer_event
);
1925 return writer_event
;
1929 struct bt_ctf_event
*debug_info_output_event(
1930 struct debug_info_iterator
*debug_it
,
1931 struct bt_ctf_event
*event
)
1933 struct bt_ctf_event_class
*event_class
= NULL
, *writer_event_class
= NULL
;
1934 struct bt_ctf_stream_class
*stream_class
= NULL
, *writer_stream_class
= NULL
;
1935 struct bt_ctf_event
*writer_event
= NULL
;
1936 struct bt_ctf_packet
*packet
= NULL
, *writer_packet
= NULL
;
1937 struct bt_ctf_trace
*writer_trace
= NULL
;
1938 struct bt_ctf_stream
*stream
= NULL
;
1939 struct debug_info_trace
*di_trace
;
1940 struct debug_info
*debug_info
;
1941 const char *event_name
;
1944 event_class
= bt_ctf_event_get_class(event
);
1946 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1947 __FILE__
, __LINE__
);
1951 event_name
= bt_ctf_event_class_get_name(event_class
);
1953 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1954 __FILE__
, __LINE__
);
1958 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
1959 if (!stream_class
) {
1960 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1961 __FILE__
, __LINE__
);
1964 stream
= bt_ctf_event_get_stream(event
);
1966 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1967 __FILE__
, __LINE__
);
1970 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1972 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1973 __FILE__
, __LINE__
);
1977 writer_stream_class
= g_hash_table_lookup(
1978 di_trace
->stream_class_map
,
1979 (gpointer
) stream_class
);
1980 if (!writer_stream_class
) {
1981 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1982 __FILE__
, __LINE__
);
1985 bt_get(writer_stream_class
);
1987 writer_event_class
= get_event_class(debug_it
,
1988 writer_stream_class
, event_class
);
1989 if (!writer_event_class
) {
1990 writer_event_class
= ctf_copy_event_class(debug_it
->err
,
1992 if (!writer_event_class
) {
1993 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1994 __func__
, __FILE__
, __LINE__
);
1997 int_ret
= bt_ctf_stream_class_add_event_class(
1998 writer_stream_class
, writer_event_class
);
2000 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
2001 __func__
, __FILE__
, __LINE__
);
2006 writer_trace
= bt_ctf_stream_class_get_trace(writer_stream_class
);
2007 if (!writer_trace
) {
2008 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
2009 __FILE__
, __LINE__
);
2013 debug_info
= get_trace_debug_info(debug_it
, writer_trace
, di_trace
);
2015 debug_info_handle_event(debug_it
->err
, event
, debug_info
);
2018 writer_event
= debug_info_copy_event(debug_it
->err
, event
,
2019 writer_event_class
, debug_info
,
2020 debug_it
->debug_info_component
);
2021 if (!writer_event
) {
2022 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
2023 __FILE__
, __LINE__
);
2024 fprintf(debug_it
->err
, "[error] Failed to copy event %s\n",
2025 bt_ctf_event_class_get_name(writer_event_class
));
2029 packet
= bt_ctf_event_get_packet(event
);
2031 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
2032 __FILE__
, __LINE__
);
2036 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
2037 if (!writer_packet
) {
2038 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
2039 __FILE__
, __LINE__
);
2042 bt_get(writer_packet
);
2044 int_ret
= bt_ctf_event_set_packet(writer_event
, writer_packet
);
2046 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
2047 __FILE__
, __LINE__
);
2048 fprintf(debug_it
->err
, "[error] Failed to append event %s\n",
2049 bt_ctf_event_class_get_name(writer_event_class
));
2053 /* Keep the reference on the writer event */
2057 BT_PUT(writer_event
);
2061 bt_put(writer_trace
);
2062 bt_put(writer_packet
);
2064 bt_put(writer_event_class
);
2065 bt_put(writer_stream_class
);
2066 bt_put(stream_class
);
2067 bt_put(event_class
);
2068 return writer_event
;