4 * Babeltrace CTF IR - Trace
6 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@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 #include <babeltrace/ctf-ir/trace-internal.h>
30 #include <babeltrace/ctf-ir/clock-internal.h>
31 #include <babeltrace/ctf-ir/stream-internal.h>
32 #include <babeltrace/ctf-ir/stream-class-internal.h>
33 #include <babeltrace/ctf-ir/event-internal.h>
34 #include <babeltrace/ctf-ir/event-class.h>
35 #include <babeltrace/ctf-ir/event-class-internal.h>
36 #include <babeltrace/ctf-writer/functor-internal.h>
37 #include <babeltrace/ctf-ir/field-types-internal.h>
38 #include <babeltrace/ctf-ir/attributes-internal.h>
39 #include <babeltrace/ctf-ir/validation-internal.h>
40 #include <babeltrace/ctf-ir/utils.h>
41 #include <babeltrace/compiler.h>
42 #include <babeltrace/values.h>
43 #include <babeltrace/ref.h>
44 #include <babeltrace/endian.h>
46 #define DEFAULT_IDENTIFIER_SIZE 128
47 #define DEFAULT_METADATA_STRING_SIZE 4096
50 void bt_ctf_trace_destroy(struct bt_object
*obj
);
52 int init_trace_packet_header(struct bt_ctf_trace
*trace
);
54 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
);
57 const unsigned int field_type_aliases_alignments
[] = {
58 [FIELD_TYPE_ALIAS_UINT5_T
] = 1,
59 [FIELD_TYPE_ALIAS_UINT8_T
... FIELD_TYPE_ALIAS_UINT16_T
] = 8,
60 [FIELD_TYPE_ALIAS_UINT27_T
] = 1,
61 [FIELD_TYPE_ALIAS_UINT32_T
... FIELD_TYPE_ALIAS_UINT64_T
] = 8,
65 const unsigned int field_type_aliases_sizes
[] = {
66 [FIELD_TYPE_ALIAS_UINT5_T
] = 5,
67 [FIELD_TYPE_ALIAS_UINT8_T
] = 8,
68 [FIELD_TYPE_ALIAS_UINT16_T
] = 16,
69 [FIELD_TYPE_ALIAS_UINT27_T
] = 27,
70 [FIELD_TYPE_ALIAS_UINT32_T
] = 32,
71 [FIELD_TYPE_ALIAS_UINT64_T
] = 64,
74 struct bt_ctf_trace
*bt_ctf_trace_create(void)
76 struct bt_ctf_trace
*trace
= NULL
;
78 trace
= g_new0(struct bt_ctf_trace
, 1);
83 bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
);
84 bt_object_init(trace
, bt_ctf_trace_destroy
);
85 trace
->clocks
= g_ptr_array_new_with_free_func(
86 (GDestroyNotify
) bt_put
);
87 trace
->streams
= g_ptr_array_new_with_free_func(
88 (GDestroyNotify
) bt_object_release
);
89 trace
->stream_classes
= g_ptr_array_new_with_free_func(
90 (GDestroyNotify
) bt_object_release
);
91 if (!trace
->clocks
|| !trace
->stream_classes
|| !trace
->streams
) {
95 /* Generate a trace UUID */
96 uuid_generate(trace
->uuid
);
97 if (init_trace_packet_header(trace
)) {
101 /* Create the environment array object */
102 trace
->environment
= bt_ctf_attributes_create();
103 if (!trace
->environment
) {
114 void bt_ctf_trace_destroy(struct bt_object
*obj
)
116 struct bt_ctf_trace
*trace
;
118 trace
= container_of(obj
, struct bt_ctf_trace
, base
);
119 if (trace
->environment
) {
120 bt_ctf_attributes_destroy(trace
->environment
);
124 g_ptr_array_free(trace
->clocks
, TRUE
);
127 if (trace
->streams
) {
128 g_ptr_array_free(trace
->streams
, TRUE
);
131 if (trace
->stream_classes
) {
132 g_ptr_array_free(trace
->stream_classes
, TRUE
);
135 bt_put(trace
->packet_header_type
);
139 int bt_ctf_trace_set_environment_field(struct bt_ctf_trace
*trace
,
140 const char *name
, struct bt_value
*value
)
144 if (!trace
|| !name
|| !value
||
145 bt_ctf_validate_identifier(name
) ||
146 !(bt_value_is_integer(value
) || bt_value_is_string(value
))) {
151 if (strchr(name
, ' ')) {
158 * New environment fields may be added to a frozen trace,
159 * but existing fields may not be changed.
161 * The object passed is frozen like all other attributes.
163 struct bt_value
*attribute
=
164 bt_ctf_attributes_get_field_value_by_name(
165 trace
->environment
, name
);
173 bt_value_freeze(value
);
176 ret
= bt_ctf_attributes_set_field_value(trace
->environment
, name
,
183 int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace
*trace
,
184 const char *name
, const char *value
)
187 struct bt_value
*env_value_string_obj
= NULL
;
189 if (!trace
|| !name
|| !value
) {
196 * New environment fields may be added to a frozen trace,
197 * but existing fields may not be changed.
199 struct bt_value
*attribute
=
200 bt_ctf_attributes_get_field_value_by_name(
201 trace
->environment
, name
);
210 env_value_string_obj
= bt_value_string_create_init(value
);
212 if (!env_value_string_obj
) {
218 bt_value_freeze(env_value_string_obj
);
220 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
221 env_value_string_obj
);
224 BT_PUT(env_value_string_obj
);
228 int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace
*trace
,
229 const char *name
, int64_t value
)
232 struct bt_value
*env_value_integer_obj
= NULL
;
234 if (!trace
|| !name
) {
241 * New environment fields may be added to a frozen trace,
242 * but existing fields may not be changed.
244 struct bt_value
*attribute
=
245 bt_ctf_attributes_get_field_value_by_name(
246 trace
->environment
, name
);
255 env_value_integer_obj
= bt_value_integer_create_init(value
);
256 if (!env_value_integer_obj
) {
261 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
262 env_value_integer_obj
);
264 bt_value_freeze(env_value_integer_obj
);
267 BT_PUT(env_value_integer_obj
);
271 int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace
*trace
)
280 ret
= bt_ctf_attributes_get_count(trace
->environment
);
287 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
290 const char *ret
= NULL
;
296 ret
= bt_ctf_attributes_get_field_name(trace
->environment
, index
);
302 struct bt_value
*bt_ctf_trace_get_environment_field_value(
303 struct bt_ctf_trace
*trace
, int index
)
305 struct bt_value
*ret
= NULL
;
311 ret
= bt_ctf_attributes_get_field_value(trace
->environment
, index
);
317 struct bt_value
*bt_ctf_trace_get_environment_field_value_by_name(
318 struct bt_ctf_trace
*trace
, const char *name
)
320 struct bt_value
*ret
= NULL
;
322 if (!trace
|| !name
) {
326 ret
= bt_ctf_attributes_get_field_value_by_name(trace
->environment
,
333 int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
334 struct bt_ctf_clock
*clock
)
337 struct search_query query
= { .value
= clock
, .found
= 0 };
339 if (!trace
|| !clock
) {
344 /* Check for duplicate clocks */
345 g_ptr_array_foreach(trace
->clocks
, value_exists
, &query
);
352 g_ptr_array_add(trace
->clocks
, clock
);
354 if (!trace
->is_created_by_writer
) {
356 * Non-writer mode trace: disable clock value functions
357 * because clock values are per-stream in that
360 clock
->has_value
= 0;
364 bt_ctf_clock_freeze(clock
);
370 int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
)
378 ret
= trace
->clocks
->len
;
383 struct bt_ctf_clock
*bt_ctf_trace_get_clock(struct bt_ctf_trace
*trace
,
386 struct bt_ctf_clock
*clock
= NULL
;
388 if (!trace
|| index
< 0 || index
>= trace
->clocks
->len
) {
392 clock
= g_ptr_array_index(trace
->clocks
, index
);
398 int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
399 struct bt_ctf_stream_class
*stream_class
)
403 struct bt_ctf_validation_output trace_sc_validation_output
= { 0 };
404 struct bt_ctf_validation_output
*ec_validation_outputs
= NULL
;
405 const enum bt_ctf_validation_flag trace_sc_validation_flags
=
406 BT_CTF_VALIDATION_FLAG_TRACE
|
407 BT_CTF_VALIDATION_FLAG_STREAM
;
408 const enum bt_ctf_validation_flag ec_validation_flags
=
409 BT_CTF_VALIDATION_FLAG_EVENT
;
410 struct bt_ctf_field_type
*packet_header_type
= NULL
;
411 struct bt_ctf_field_type
*packet_context_type
= NULL
;
412 struct bt_ctf_field_type
*event_header_type
= NULL
;
413 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
414 int event_class_count
;
415 struct bt_ctf_clock
*clock_to_add_to_trace
= NULL
;
417 if (!trace
|| !stream_class
) {
423 bt_ctf_stream_class_get_event_class_count(stream_class
);
424 assert(event_class_count
>= 0);
426 /* Check for duplicate stream classes */
427 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
428 if (trace
->stream_classes
->pdata
[i
] == stream_class
) {
429 /* Stream class already registered to the trace */
436 * If the stream class has a clock, register this clock to this
437 * trace if not already done.
439 if (stream_class
->clock
) {
440 const char *clock_name
=
441 bt_ctf_clock_get_name(stream_class
->clock
);
442 struct bt_ctf_clock
*trace_clock
;
445 trace_clock
= bt_ctf_trace_get_clock_by_name(trace
, clock_name
);
448 if (trace_clock
!= stream_class
->clock
) {
450 * Error: two different clocks in the
451 * trace would share the same name.
457 clock_to_add_to_trace
= bt_get(stream_class
->clock
);
462 * We're about to freeze both the trace and the stream class.
463 * Also, each event class contained in this stream class are
466 * This trace, this stream class, and all its event classes
467 * should be valid at this point.
469 * Validate trace and stream class first, then each event
470 * class of this stream class can be validated individually.
473 bt_ctf_trace_get_packet_header_type(trace
);
474 packet_context_type
=
475 bt_ctf_stream_class_get_packet_context_type(stream_class
);
477 bt_ctf_stream_class_get_event_header_type(stream_class
);
478 stream_event_ctx_type
=
479 bt_ctf_stream_class_get_event_context_type(stream_class
);
480 ret
= bt_ctf_validate_class_types(trace
->environment
,
481 packet_header_type
, packet_context_type
, event_header_type
,
482 stream_event_ctx_type
, NULL
, NULL
, trace
->valid
,
483 stream_class
->valid
, 1, &trace_sc_validation_output
,
484 trace_sc_validation_flags
);
485 BT_PUT(packet_header_type
);
486 BT_PUT(packet_context_type
);
487 BT_PUT(event_header_type
);
488 BT_PUT(stream_event_ctx_type
);
492 * This means something went wrong during the validation
493 * process, not that the objects are invalid.
498 if ((trace_sc_validation_output
.valid_flags
&
499 trace_sc_validation_flags
) !=
500 trace_sc_validation_flags
) {
501 /* Invalid trace/stream class */
506 if (event_class_count
> 0) {
507 ec_validation_outputs
= g_new0(struct bt_ctf_validation_output
,
509 if (!ec_validation_outputs
) {
515 /* Validate each event class individually */
516 for (i
= 0; i
< event_class_count
; i
++) {
517 struct bt_ctf_event_class
*event_class
=
518 bt_ctf_stream_class_get_event_class(stream_class
, i
);
519 struct bt_ctf_field_type
*event_context_type
= NULL
;
520 struct bt_ctf_field_type
*event_payload_type
= NULL
;
523 bt_ctf_event_class_get_context_type(event_class
);
525 bt_ctf_event_class_get_payload_type(event_class
);
528 * It is important to use the field types returned by
529 * the previous trace and stream class validation here
530 * because copies could have been made.
532 ret
= bt_ctf_validate_class_types(trace
->environment
,
533 trace_sc_validation_output
.packet_header_type
,
534 trace_sc_validation_output
.packet_context_type
,
535 trace_sc_validation_output
.event_header_type
,
536 trace_sc_validation_output
.stream_event_ctx_type
,
537 event_context_type
, event_payload_type
,
538 1, 1, event_class
->valid
, &ec_validation_outputs
[i
],
539 ec_validation_flags
);
540 BT_PUT(event_context_type
);
541 BT_PUT(event_payload_type
);
548 if ((ec_validation_outputs
[i
].valid_flags
&
549 ec_validation_flags
) != ec_validation_flags
) {
550 /* Invalid event class */
556 stream_id
= bt_ctf_stream_class_get_id(stream_class
);
558 stream_id
= trace
->next_stream_id
++;
560 /* Try to assign a new stream id */
561 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
562 if (stream_id
== bt_ctf_stream_class_get_id(
563 trace
->stream_classes
->pdata
[i
])) {
564 /* Duplicate stream id found */
570 if (bt_ctf_stream_class_set_id_no_check(stream_class
,
572 /* TODO Should retry with a different stream id */
578 bt_object_set_parent(stream_class
, trace
);
579 g_ptr_array_add(trace
->stream_classes
, stream_class
);
582 * At this point we know that the function will be successful.
583 * Therefore we can replace the trace and stream class field
584 * types with what's in their validation output structure and
585 * mark them as valid. We can also replace the field types of
586 * all the event classes of the stream class and mark them as
589 bt_ctf_validation_replace_types(trace
, stream_class
, NULL
,
590 &trace_sc_validation_output
, trace_sc_validation_flags
);
592 stream_class
->valid
= 1;
595 * Put what was not moved in bt_ctf_validation_replace_types().
597 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
599 for (i
= 0; i
< event_class_count
; i
++) {
600 struct bt_ctf_event_class
*event_class
=
601 bt_ctf_stream_class_get_event_class(stream_class
, i
);
603 bt_ctf_validation_replace_types(NULL
, NULL
, event_class
,
604 &ec_validation_outputs
[i
], ec_validation_flags
);
605 event_class
->valid
= 1;
609 * Put what was not moved in
610 * bt_ctf_validation_replace_types().
612 bt_ctf_validation_output_put_types(&ec_validation_outputs
[i
]);
616 * All field type byte orders set as "native" byte ordering can now be
617 * safely set to trace's own endianness, including the stream class'.
619 bt_ctf_field_type_set_native_byte_order(trace
->packet_header_type
,
621 bt_ctf_stream_class_set_byte_order(stream_class
, trace
->byte_order
);
623 /* Add stream class's clock if it exists */
624 if (clock_to_add_to_trace
) {
626 bt_ctf_trace_add_clock(trace
, clock_to_add_to_trace
);
627 assert(add_clock_ret
== 0);
631 * Freeze the trace and the stream class.
633 bt_ctf_stream_class_freeze(stream_class
);
634 bt_ctf_trace_freeze(trace
);
638 bt_object_set_parent(stream_class
, NULL
);
640 if (ec_validation_outputs
) {
641 for (i
= 0; i
< event_class_count
; i
++) {
642 bt_ctf_validation_output_put_types(
643 &ec_validation_outputs
[i
]);
648 g_free(ec_validation_outputs
);
649 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
650 BT_PUT(clock_to_add_to_trace
);
651 assert(!packet_header_type
);
652 assert(!packet_context_type
);
653 assert(!event_header_type
);
654 assert(!stream_event_ctx_type
);
659 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
)
668 ret
= trace
->stream_classes
->len
;
673 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
674 struct bt_ctf_trace
*trace
, int index
)
676 struct bt_ctf_stream_class
*stream_class
= NULL
;
678 if (!trace
|| index
< 0 || index
>= trace
->stream_classes
->len
) {
682 stream_class
= g_ptr_array_index(trace
->stream_classes
, index
);
683 bt_get(stream_class
);
688 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
689 struct bt_ctf_trace
*trace
, uint32_t id
)
692 struct bt_ctf_stream_class
*stream_class
= NULL
;
698 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
699 struct bt_ctf_stream_class
*stream_class_candidate
;
701 stream_class_candidate
=
702 g_ptr_array_index(trace
->stream_classes
, i
);
704 if (bt_ctf_stream_class_get_id(stream_class_candidate
) ==
706 stream_class
= stream_class_candidate
;
707 bt_get(stream_class
);
716 struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
717 struct bt_ctf_trace
*trace
, const char *name
)
720 struct bt_ctf_clock
*clock
= NULL
;
722 if (!trace
|| !name
) {
726 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
727 struct bt_ctf_clock
*cur_clk
=
728 g_ptr_array_index(trace
->clocks
, i
);
729 const char *cur_clk_name
= bt_ctf_clock_get_name(cur_clk
);
735 if (!strcmp(cur_clk_name
, name
)) {
747 const char *get_byte_order_string(int byte_order
)
751 switch (byte_order
) {
767 int append_trace_metadata(struct bt_ctf_trace
*trace
,
768 struct metadata_context
*context
)
770 unsigned char *uuid
= trace
->uuid
;
773 g_string_append(context
->string
, "trace {\n");
775 g_string_append(context
->string
, "\tmajor = 1;\n");
776 g_string_append(context
->string
, "\tminor = 8;\n");
778 g_string_append_printf(context
->string
,
779 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
780 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
781 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
782 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
783 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
784 g_string_append_printf(context
->string
, "\tbyte_order = %s;\n",
785 get_byte_order_string(trace
->byte_order
));
787 g_string_append(context
->string
, "\tpacket.header := ");
788 context
->current_indentation_level
++;
789 g_string_assign(context
->field_name
, "");
790 ret
= bt_ctf_field_type_serialize(trace
->packet_header_type
,
795 context
->current_indentation_level
--;
797 g_string_append(context
->string
, ";\n};\n\n");
803 void append_env_metadata(struct bt_ctf_trace
*trace
,
804 struct metadata_context
*context
)
809 env_size
= bt_ctf_attributes_get_count(trace
->environment
);
815 g_string_append(context
->string
, "env {\n");
817 for (i
= 0; i
< env_size
; i
++) {
818 struct bt_value
*env_field_value_obj
= NULL
;
819 const char *entry_name
;
821 entry_name
= bt_ctf_attributes_get_field_name(
822 trace
->environment
, i
);
823 env_field_value_obj
= bt_ctf_attributes_get_field_value(
824 trace
->environment
, i
);
826 if (!entry_name
|| !env_field_value_obj
) {
830 switch (bt_value_get_type(env_field_value_obj
)) {
831 case BT_VALUE_TYPE_INTEGER
:
836 ret
= bt_value_integer_get(env_field_value_obj
,
843 g_string_append_printf(context
->string
,
844 "\t%s = %" PRId64
";\n", entry_name
,
848 case BT_VALUE_TYPE_STRING
:
851 const char *str_value
;
852 char *escaped_str
= NULL
;
854 ret
= bt_value_string_get(env_field_value_obj
,
861 escaped_str
= g_strescape(str_value
, NULL
);
867 g_string_append_printf(context
->string
,
868 "\t%s = \"%s\";\n", entry_name
, escaped_str
);
878 BT_PUT(env_field_value_obj
);
881 g_string_append(context
->string
, "};\n\n");
884 char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
)
886 char *metadata
= NULL
;
887 struct metadata_context
*context
= NULL
;
895 context
= g_new0(struct metadata_context
, 1);
900 context
->field_name
= g_string_sized_new(DEFAULT_IDENTIFIER_SIZE
);
901 context
->string
= g_string_sized_new(DEFAULT_METADATA_STRING_SIZE
);
902 g_string_append(context
->string
, "/* CTF 1.8 */\n\n");
903 if (append_trace_metadata(trace
, context
)) {
906 append_env_metadata(trace
, context
);
907 g_ptr_array_foreach(trace
->clocks
,
908 (GFunc
)bt_ctf_clock_serialize
, context
);
910 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
911 err
= bt_ctf_stream_class_serialize(
912 trace
->stream_classes
->pdata
[i
], context
);
918 metadata
= context
->string
->str
;
920 g_string_free(context
->string
, err
? TRUE
: FALSE
);
921 g_string_free(context
->field_name
, TRUE
);
927 enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(struct bt_ctf_trace
*trace
)
929 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
935 switch (trace
->byte_order
) {
937 ret
= BT_CTF_BYTE_ORDER_BIG_ENDIAN
;
940 ret
= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
;
949 int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
950 enum bt_ctf_byte_order byte_order
)
953 int internal_byte_order
;
955 if (!trace
|| trace
->frozen
) {
960 switch (byte_order
) {
961 case BT_CTF_BYTE_ORDER_NATIVE
:
963 * This doesn't make sense since the CTF specification defines
964 * the "native" byte order as "the byte order described in the
965 * trace description". However, this behavior had been
966 * implemented as part of v1.2 and is kept to maintain
969 * This may be changed on a major version bump only.
971 internal_byte_order
= (G_BYTE_ORDER
== G_LITTLE_ENDIAN
) ?
972 LITTLE_ENDIAN
: BIG_ENDIAN
;
974 case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
:
975 internal_byte_order
= LITTLE_ENDIAN
;
977 case BT_CTF_BYTE_ORDER_BIG_ENDIAN
:
978 case BT_CTF_BYTE_ORDER_NETWORK
:
979 internal_byte_order
= BIG_ENDIAN
;
986 trace
->byte_order
= internal_byte_order
;
991 struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
992 struct bt_ctf_trace
*trace
)
994 struct bt_ctf_field_type
*field_type
= NULL
;
1000 bt_get(trace
->packet_header_type
);
1001 field_type
= trace
->packet_header_type
;
1006 int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
1007 struct bt_ctf_field_type
*packet_header_type
)
1011 if (!trace
|| !packet_header_type
|| trace
->frozen
) {
1016 /* packet_header_type must be a structure */
1017 if (bt_ctf_field_type_get_type_id(packet_header_type
) !=
1018 BT_CTF_TYPE_ID_STRUCT
) {
1023 bt_get(packet_header_type
);
1024 bt_put(trace
->packet_header_type
);
1025 trace
->packet_header_type
= packet_header_type
;
1031 struct bt_ctf_field_type
*get_field_type(enum field_type_alias alias
)
1033 unsigned int alignment
, size
;
1034 struct bt_ctf_field_type
*field_type
= NULL
;
1036 if (alias
>= NR_FIELD_TYPE_ALIAS
) {
1040 alignment
= field_type_aliases_alignments
[alias
];
1041 size
= field_type_aliases_sizes
[alias
];
1042 field_type
= bt_ctf_field_type_integer_create(size
);
1043 bt_ctf_field_type_set_alignment(field_type
, alignment
);
1049 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
)
1053 bt_ctf_field_type_freeze(trace
->packet_header_type
);
1054 bt_ctf_attributes_freeze(trace
->environment
);
1056 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
1057 struct bt_ctf_clock
*clock
=
1058 g_ptr_array_index(trace
->clocks
, i
);
1060 bt_ctf_clock_freeze(clock
);
1067 int init_trace_packet_header(struct bt_ctf_trace
*trace
)
1070 struct bt_ctf_field
*magic
= NULL
, *uuid_array
= NULL
;
1071 struct bt_ctf_field_type
*_uint32_t
=
1072 get_field_type(FIELD_TYPE_ALIAS_UINT32_T
);
1073 struct bt_ctf_field_type
*_uint8_t
=
1074 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
1075 struct bt_ctf_field_type
*trace_packet_header_type
=
1076 bt_ctf_field_type_structure_create();
1077 struct bt_ctf_field_type
*uuid_array_type
=
1078 bt_ctf_field_type_array_create(_uint8_t
, 16);
1080 if (!trace_packet_header_type
|| !uuid_array_type
) {
1085 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1086 _uint32_t
, "magic");
1091 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1092 uuid_array_type
, "uuid");
1097 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1098 _uint32_t
, "stream_id");
1103 ret
= bt_ctf_trace_set_packet_header_type(trace
,
1104 trace_packet_header_type
);
1109 bt_put(uuid_array_type
);
1114 bt_put(trace_packet_header_type
);