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,
75 struct bt_ctf_trace
*bt_ctf_trace_create(void)
77 struct bt_ctf_trace
*trace
= NULL
;
79 trace
= g_new0(struct bt_ctf_trace
, 1);
84 bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
);
85 bt_object_init(trace
, bt_ctf_trace_destroy
);
86 trace
->clocks
= g_ptr_array_new_with_free_func(
87 (GDestroyNotify
) bt_put
);
88 trace
->streams
= g_ptr_array_new_with_free_func(
89 (GDestroyNotify
) bt_object_release
);
90 trace
->stream_classes
= g_ptr_array_new_with_free_func(
91 (GDestroyNotify
) bt_object_release
);
92 if (!trace
->clocks
|| !trace
->stream_classes
|| !trace
->streams
) {
96 /* Generate a trace UUID */
97 uuid_generate(trace
->uuid
);
98 if (init_trace_packet_header(trace
)) {
102 /* Create the environment array object */
103 trace
->environment
= bt_ctf_attributes_create();
104 if (!trace
->environment
) {
116 void bt_ctf_trace_destroy(struct bt_object
*obj
)
118 struct bt_ctf_trace
*trace
;
120 trace
= container_of(obj
, struct bt_ctf_trace
, base
);
121 if (trace
->environment
) {
122 bt_ctf_attributes_destroy(trace
->environment
);
126 g_ptr_array_free(trace
->clocks
, TRUE
);
129 if (trace
->streams
) {
130 g_ptr_array_free(trace
->streams
, TRUE
);
133 if (trace
->stream_classes
) {
134 g_ptr_array_free(trace
->stream_classes
, TRUE
);
137 bt_put(trace
->packet_header_type
);
142 int bt_ctf_trace_set_environment_field(struct bt_ctf_trace
*trace
,
143 const char *name
, struct bt_value
*value
)
147 if (!trace
|| !name
|| !value
||
148 bt_ctf_validate_identifier(name
) ||
149 !(bt_value_is_integer(value
) || bt_value_is_string(value
))) {
154 if (strchr(name
, ' ')) {
161 * New environment fields may be added to a frozen trace,
162 * but existing fields may not be changed.
164 * The object passed is frozen like all other attributes.
166 struct bt_value
*attribute
=
167 bt_ctf_attributes_get_field_value_by_name(
168 trace
->environment
, name
);
176 bt_value_freeze(value
);
179 ret
= bt_ctf_attributes_set_field_value(trace
->environment
, name
,
187 int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace
*trace
,
188 const char *name
, const char *value
)
191 struct bt_value
*env_value_string_obj
= NULL
;
193 if (!trace
|| !name
|| !value
) {
200 * New environment fields may be added to a frozen trace,
201 * but existing fields may not be changed.
203 struct bt_value
*attribute
=
204 bt_ctf_attributes_get_field_value_by_name(
205 trace
->environment
, name
);
214 env_value_string_obj
= bt_value_string_create_init(value
);
216 if (!env_value_string_obj
) {
222 bt_value_freeze(env_value_string_obj
);
224 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
225 env_value_string_obj
);
228 BT_PUT(env_value_string_obj
);
233 int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace
*trace
,
234 const char *name
, int64_t value
)
237 struct bt_value
*env_value_integer_obj
= NULL
;
239 if (!trace
|| !name
) {
246 * New environment fields may be added to a frozen trace,
247 * but existing fields may not be changed.
249 struct bt_value
*attribute
=
250 bt_ctf_attributes_get_field_value_by_name(
251 trace
->environment
, name
);
260 env_value_integer_obj
= bt_value_integer_create_init(value
);
261 if (!env_value_integer_obj
) {
266 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
267 env_value_integer_obj
);
269 bt_value_freeze(env_value_integer_obj
);
272 BT_PUT(env_value_integer_obj
);
277 int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace
*trace
)
286 ret
= bt_ctf_attributes_get_count(trace
->environment
);
294 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
297 const char *ret
= NULL
;
303 ret
= bt_ctf_attributes_get_field_name(trace
->environment
, index
);
310 struct bt_value
*bt_ctf_trace_get_environment_field_value(
311 struct bt_ctf_trace
*trace
, int index
)
313 struct bt_value
*ret
= NULL
;
319 ret
= bt_ctf_attributes_get_field_value(trace
->environment
, index
);
326 struct bt_value
*bt_ctf_trace_get_environment_field_value_by_name(
327 struct bt_ctf_trace
*trace
, const char *name
)
329 struct bt_value
*ret
= NULL
;
331 if (!trace
|| !name
) {
335 ret
= bt_ctf_attributes_get_field_value_by_name(trace
->environment
,
343 int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
344 struct bt_ctf_clock
*clock
)
347 struct search_query query
= { .value
= clock
, .found
= 0 };
349 if (!trace
|| !clock
) {
354 /* Check for duplicate clocks */
355 g_ptr_array_foreach(trace
->clocks
, value_exists
, &query
);
362 g_ptr_array_add(trace
->clocks
, clock
);
364 if (!trace
->is_created_by_writer
) {
366 * Non-writer mode trace: disable clock value functions
367 * because clock values are per-stream in that
370 clock
->has_value
= 0;
374 bt_ctf_clock_freeze(clock
);
381 int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
)
389 ret
= trace
->clocks
->len
;
395 struct bt_ctf_clock
*bt_ctf_trace_get_clock(struct bt_ctf_trace
*trace
,
398 struct bt_ctf_clock
*clock
= NULL
;
400 if (!trace
|| index
< 0 || index
>= trace
->clocks
->len
) {
404 clock
= g_ptr_array_index(trace
->clocks
, index
);
411 int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
412 struct bt_ctf_stream_class
*stream_class
)
416 struct bt_ctf_validation_output trace_sc_validation_output
= { 0 };
417 struct bt_ctf_validation_output
*ec_validation_outputs
= NULL
;
418 const enum bt_ctf_validation_flag trace_sc_validation_flags
=
419 BT_CTF_VALIDATION_FLAG_TRACE
|
420 BT_CTF_VALIDATION_FLAG_STREAM
;
421 const enum bt_ctf_validation_flag ec_validation_flags
=
422 BT_CTF_VALIDATION_FLAG_EVENT
;
423 struct bt_ctf_field_type
*packet_header_type
= NULL
;
424 struct bt_ctf_field_type
*packet_context_type
= NULL
;
425 struct bt_ctf_field_type
*event_header_type
= NULL
;
426 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
427 int event_class_count
;
428 struct bt_ctf_clock
*clock_to_add_to_trace
= NULL
;
430 if (!trace
|| !stream_class
) {
436 bt_ctf_stream_class_get_event_class_count(stream_class
);
437 assert(event_class_count
>= 0);
439 /* Check for duplicate stream classes */
440 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
441 if (trace
->stream_classes
->pdata
[i
] == stream_class
) {
442 /* Stream class already registered to the trace */
449 * If the stream class has a clock, register this clock to this
450 * trace if not already done.
452 if (stream_class
->clock
) {
453 const char *clock_name
=
454 bt_ctf_clock_get_name(stream_class
->clock
);
455 struct bt_ctf_clock
*trace_clock
;
458 trace_clock
= bt_ctf_trace_get_clock_by_name(trace
, clock_name
);
461 if (trace_clock
!= stream_class
->clock
) {
463 * Error: two different clocks in the
464 * trace would share the same name.
470 clock_to_add_to_trace
= bt_get(stream_class
->clock
);
475 * We're about to freeze both the trace and the stream class.
476 * Also, each event class contained in this stream class are
479 * This trace, this stream class, and all its event classes
480 * should be valid at this point.
482 * Validate trace and stream class first, then each event
483 * class of this stream class can be validated individually.
486 bt_ctf_trace_get_packet_header_type(trace
);
487 packet_context_type
=
488 bt_ctf_stream_class_get_packet_context_type(stream_class
);
490 bt_ctf_stream_class_get_event_header_type(stream_class
);
491 stream_event_ctx_type
=
492 bt_ctf_stream_class_get_event_context_type(stream_class
);
493 ret
= bt_ctf_validate_class_types(trace
->environment
,
494 packet_header_type
, packet_context_type
, event_header_type
,
495 stream_event_ctx_type
, NULL
, NULL
, trace
->valid
,
496 stream_class
->valid
, 1, &trace_sc_validation_output
,
497 trace_sc_validation_flags
);
498 BT_PUT(packet_header_type
);
499 BT_PUT(packet_context_type
);
500 BT_PUT(event_header_type
);
501 BT_PUT(stream_event_ctx_type
);
505 * This means something went wrong during the validation
506 * process, not that the objects are invalid.
511 if ((trace_sc_validation_output
.valid_flags
&
512 trace_sc_validation_flags
) !=
513 trace_sc_validation_flags
) {
514 /* Invalid trace/stream class */
519 if (event_class_count
> 0) {
520 ec_validation_outputs
= g_new0(struct bt_ctf_validation_output
,
522 if (!ec_validation_outputs
) {
528 /* Validate each event class individually */
529 for (i
= 0; i
< event_class_count
; i
++) {
530 struct bt_ctf_event_class
*event_class
=
531 bt_ctf_stream_class_get_event_class(stream_class
, i
);
532 struct bt_ctf_field_type
*event_context_type
= NULL
;
533 struct bt_ctf_field_type
*event_payload_type
= NULL
;
536 bt_ctf_event_class_get_context_type(event_class
);
538 bt_ctf_event_class_get_payload_type(event_class
);
541 * It is important to use the field types returned by
542 * the previous trace and stream class validation here
543 * because copies could have been made.
545 ret
= bt_ctf_validate_class_types(trace
->environment
,
546 trace_sc_validation_output
.packet_header_type
,
547 trace_sc_validation_output
.packet_context_type
,
548 trace_sc_validation_output
.event_header_type
,
549 trace_sc_validation_output
.stream_event_ctx_type
,
550 event_context_type
, event_payload_type
,
551 1, 1, event_class
->valid
, &ec_validation_outputs
[i
],
552 ec_validation_flags
);
553 BT_PUT(event_context_type
);
554 BT_PUT(event_payload_type
);
561 if ((ec_validation_outputs
[i
].valid_flags
&
562 ec_validation_flags
) != ec_validation_flags
) {
563 /* Invalid event class */
569 stream_id
= bt_ctf_stream_class_get_id(stream_class
);
571 stream_id
= trace
->next_stream_id
++;
573 /* Try to assign a new stream id */
574 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
575 if (stream_id
== bt_ctf_stream_class_get_id(
576 trace
->stream_classes
->pdata
[i
])) {
577 /* Duplicate stream id found */
583 if (bt_ctf_stream_class_set_id_no_check(stream_class
,
585 /* TODO Should retry with a different stream id */
591 bt_object_set_parent(stream_class
, trace
);
592 g_ptr_array_add(trace
->stream_classes
, stream_class
);
595 * At this point we know that the function will be successful.
596 * Therefore we can replace the trace and stream class field
597 * types with what's in their validation output structure and
598 * mark them as valid. We can also replace the field types of
599 * all the event classes of the stream class and mark them as
602 bt_ctf_validation_replace_types(trace
, stream_class
, NULL
,
603 &trace_sc_validation_output
, trace_sc_validation_flags
);
605 stream_class
->valid
= 1;
608 * Put what was not moved in bt_ctf_validation_replace_types().
610 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
612 for (i
= 0; i
< event_class_count
; i
++) {
613 struct bt_ctf_event_class
*event_class
=
614 bt_ctf_stream_class_get_event_class(stream_class
, i
);
616 bt_ctf_validation_replace_types(NULL
, NULL
, event_class
,
617 &ec_validation_outputs
[i
], ec_validation_flags
);
618 event_class
->valid
= 1;
622 * Put what was not moved in
623 * bt_ctf_validation_replace_types().
625 bt_ctf_validation_output_put_types(&ec_validation_outputs
[i
]);
629 * All field type byte orders set as "native" byte ordering can now be
630 * safely set to trace's own endianness, including the stream class'.
632 bt_ctf_field_type_set_native_byte_order(trace
->packet_header_type
,
634 bt_ctf_stream_class_set_byte_order(stream_class
, trace
->byte_order
);
636 /* Add stream class's clock if it exists */
637 if (clock_to_add_to_trace
) {
639 bt_ctf_trace_add_clock(trace
, clock_to_add_to_trace
);
640 assert(add_clock_ret
== 0);
644 * Freeze the trace and the stream class.
646 bt_ctf_stream_class_freeze(stream_class
);
647 bt_ctf_trace_freeze(trace
);
651 bt_object_set_parent(stream_class
, NULL
);
653 if (ec_validation_outputs
) {
654 for (i
= 0; i
< event_class_count
; i
++) {
655 bt_ctf_validation_output_put_types(
656 &ec_validation_outputs
[i
]);
661 g_free(ec_validation_outputs
);
662 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
663 BT_PUT(clock_to_add_to_trace
);
664 assert(!packet_header_type
);
665 assert(!packet_context_type
);
666 assert(!event_header_type
);
667 assert(!stream_event_ctx_type
);
673 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
)
682 ret
= trace
->stream_classes
->len
;
688 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
689 struct bt_ctf_trace
*trace
, int index
)
691 struct bt_ctf_stream_class
*stream_class
= NULL
;
693 if (!trace
|| index
< 0 || index
>= trace
->stream_classes
->len
) {
697 stream_class
= g_ptr_array_index(trace
->stream_classes
, index
);
698 bt_get(stream_class
);
704 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
705 struct bt_ctf_trace
*trace
, uint32_t id
)
708 struct bt_ctf_stream_class
*stream_class
= NULL
;
714 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
715 struct bt_ctf_stream_class
*stream_class_candidate
;
717 stream_class_candidate
=
718 g_ptr_array_index(trace
->stream_classes
, i
);
720 if (bt_ctf_stream_class_get_id(stream_class_candidate
) ==
722 stream_class
= stream_class_candidate
;
723 bt_get(stream_class
);
733 struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
734 struct bt_ctf_trace
*trace
, const char *name
)
737 struct bt_ctf_clock
*clock
= NULL
;
739 if (!trace
|| !name
) {
743 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
744 struct bt_ctf_clock
*cur_clk
=
745 g_ptr_array_index(trace
->clocks
, i
);
746 const char *cur_clk_name
= bt_ctf_clock_get_name(cur_clk
);
752 if (!strcmp(cur_clk_name
, name
)) {
764 const char *get_byte_order_string(int byte_order
)
768 switch (byte_order
) {
784 int append_trace_metadata(struct bt_ctf_trace
*trace
,
785 struct metadata_context
*context
)
787 unsigned char *uuid
= trace
->uuid
;
790 g_string_append(context
->string
, "trace {\n");
792 g_string_append(context
->string
, "\tmajor = 1;\n");
793 g_string_append(context
->string
, "\tminor = 8;\n");
795 g_string_append_printf(context
->string
,
796 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
797 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
798 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
799 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
800 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
801 g_string_append_printf(context
->string
, "\tbyte_order = %s;\n",
802 get_byte_order_string(trace
->byte_order
));
804 g_string_append(context
->string
, "\tpacket.header := ");
805 context
->current_indentation_level
++;
806 g_string_assign(context
->field_name
, "");
807 ret
= bt_ctf_field_type_serialize(trace
->packet_header_type
,
812 context
->current_indentation_level
--;
814 g_string_append(context
->string
, ";\n};\n\n");
820 void append_env_metadata(struct bt_ctf_trace
*trace
,
821 struct metadata_context
*context
)
826 env_size
= bt_ctf_attributes_get_count(trace
->environment
);
832 g_string_append(context
->string
, "env {\n");
834 for (i
= 0; i
< env_size
; i
++) {
835 struct bt_value
*env_field_value_obj
= NULL
;
836 const char *entry_name
;
838 entry_name
= bt_ctf_attributes_get_field_name(
839 trace
->environment
, i
);
840 env_field_value_obj
= bt_ctf_attributes_get_field_value(
841 trace
->environment
, i
);
843 if (!entry_name
|| !env_field_value_obj
) {
847 switch (bt_value_get_type(env_field_value_obj
)) {
848 case BT_VALUE_TYPE_INTEGER
:
853 ret
= bt_value_integer_get(env_field_value_obj
,
860 g_string_append_printf(context
->string
,
861 "\t%s = %" PRId64
";\n", entry_name
,
865 case BT_VALUE_TYPE_STRING
:
868 const char *str_value
;
869 char *escaped_str
= NULL
;
871 ret
= bt_value_string_get(env_field_value_obj
,
878 escaped_str
= g_strescape(str_value
, NULL
);
884 g_string_append_printf(context
->string
,
885 "\t%s = \"%s\";\n", entry_name
, escaped_str
);
895 BT_PUT(env_field_value_obj
);
898 g_string_append(context
->string
, "};\n\n");
902 char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
)
904 char *metadata
= NULL
;
905 struct metadata_context
*context
= NULL
;
913 context
= g_new0(struct metadata_context
, 1);
918 context
->field_name
= g_string_sized_new(DEFAULT_IDENTIFIER_SIZE
);
919 context
->string
= g_string_sized_new(DEFAULT_METADATA_STRING_SIZE
);
920 g_string_append(context
->string
, "/* CTF 1.8 */\n\n");
921 if (append_trace_metadata(trace
, context
)) {
924 append_env_metadata(trace
, context
);
925 g_ptr_array_foreach(trace
->clocks
,
926 (GFunc
)bt_ctf_clock_serialize
, context
);
928 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
929 err
= bt_ctf_stream_class_serialize(
930 trace
->stream_classes
->pdata
[i
], context
);
936 metadata
= context
->string
->str
;
938 g_string_free(context
->string
, err
? TRUE
: FALSE
);
939 g_string_free(context
->field_name
, TRUE
);
946 enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(struct bt_ctf_trace
*trace
)
948 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
954 switch (trace
->byte_order
) {
956 ret
= BT_CTF_BYTE_ORDER_BIG_ENDIAN
;
959 ret
= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
;
969 int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
970 enum bt_ctf_byte_order byte_order
)
973 int internal_byte_order
;
975 if (!trace
|| trace
->frozen
) {
980 switch (byte_order
) {
981 case BT_CTF_BYTE_ORDER_NATIVE
:
983 * This doesn't make sense since the CTF specification defines
984 * the "native" byte order as "the byte order described in the
985 * trace description". However, this behavior had been
986 * implemented as part of v1.2 and is kept to maintain
989 * This may be changed on a major version bump only.
991 internal_byte_order
= (G_BYTE_ORDER
== G_LITTLE_ENDIAN
) ?
992 LITTLE_ENDIAN
: BIG_ENDIAN
;
994 case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
:
995 internal_byte_order
= LITTLE_ENDIAN
;
997 case BT_CTF_BYTE_ORDER_BIG_ENDIAN
:
998 case BT_CTF_BYTE_ORDER_NETWORK
:
999 internal_byte_order
= BIG_ENDIAN
;
1006 trace
->byte_order
= internal_byte_order
;
1012 struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
1013 struct bt_ctf_trace
*trace
)
1015 struct bt_ctf_field_type
*field_type
= NULL
;
1021 bt_get(trace
->packet_header_type
);
1022 field_type
= trace
->packet_header_type
;
1028 int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
1029 struct bt_ctf_field_type
*packet_header_type
)
1033 if (!trace
|| !packet_header_type
|| trace
->frozen
) {
1038 /* packet_header_type must be a structure */
1039 if (bt_ctf_field_type_get_type_id(packet_header_type
) !=
1040 BT_CTF_TYPE_ID_STRUCT
) {
1045 bt_get(packet_header_type
);
1046 bt_put(trace
->packet_header_type
);
1047 trace
->packet_header_type
= packet_header_type
;
1053 struct bt_ctf_field_type
*get_field_type(enum field_type_alias alias
)
1056 unsigned int alignment
, size
;
1057 struct bt_ctf_field_type
*field_type
= NULL
;
1059 if (alias
>= NR_FIELD_TYPE_ALIAS
) {
1063 alignment
= field_type_aliases_alignments
[alias
];
1064 size
= field_type_aliases_sizes
[alias
];
1065 field_type
= bt_ctf_field_type_integer_create(size
);
1066 ret
= bt_ctf_field_type_set_alignment(field_type
, alignment
);
1075 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
)
1079 bt_ctf_field_type_freeze(trace
->packet_header_type
);
1080 bt_ctf_attributes_freeze(trace
->environment
);
1082 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
1083 struct bt_ctf_clock
*clock
=
1084 g_ptr_array_index(trace
->clocks
, i
);
1086 bt_ctf_clock_freeze(clock
);
1093 int init_trace_packet_header(struct bt_ctf_trace
*trace
)
1096 struct bt_ctf_field
*magic
= NULL
, *uuid_array
= NULL
;
1097 struct bt_ctf_field_type
*_uint32_t
=
1098 get_field_type(FIELD_TYPE_ALIAS_UINT32_T
);
1099 struct bt_ctf_field_type
*_uint8_t
=
1100 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
1101 struct bt_ctf_field_type
*trace_packet_header_type
=
1102 bt_ctf_field_type_structure_create();
1103 struct bt_ctf_field_type
*uuid_array_type
=
1104 bt_ctf_field_type_array_create(_uint8_t
, 16);
1106 if (!trace_packet_header_type
|| !uuid_array_type
) {
1111 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1112 _uint32_t
, "magic");
1117 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1118 uuid_array_type
, "uuid");
1123 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1124 _uint32_t
, "stream_id");
1129 ret
= bt_ctf_trace_set_packet_header_type(trace
,
1130 trace_packet_header_type
);
1135 bt_put(uuid_array_type
);
1140 bt_put(trace_packet_header_type
);