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-writer/functor-internal.h>
35 #include <babeltrace/ctf-ir/event-types-internal.h>
36 #include <babeltrace/ctf-ir/attributes-internal.h>
37 #include <babeltrace/ctf-ir/validation-internal.h>
38 #include <babeltrace/ctf-ir/utils.h>
39 #include <babeltrace/compiler.h>
40 #include <babeltrace/values.h>
41 #include <babeltrace/ref.h>
42 #include <babeltrace/endian.h>
44 #define DEFAULT_IDENTIFIER_SIZE 128
45 #define DEFAULT_METADATA_STRING_SIZE 4096
48 void bt_ctf_trace_destroy(struct bt_object
*obj
);
50 int init_trace_packet_header(struct bt_ctf_trace
*trace
);
52 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
);
55 const unsigned int field_type_aliases_alignments
[] = {
56 [FIELD_TYPE_ALIAS_UINT5_T
] = 1,
57 [FIELD_TYPE_ALIAS_UINT8_T
... FIELD_TYPE_ALIAS_UINT16_T
] = 8,
58 [FIELD_TYPE_ALIAS_UINT27_T
] = 1,
59 [FIELD_TYPE_ALIAS_UINT32_T
... FIELD_TYPE_ALIAS_UINT64_T
] = 8,
63 const unsigned int field_type_aliases_sizes
[] = {
64 [FIELD_TYPE_ALIAS_UINT5_T
] = 5,
65 [FIELD_TYPE_ALIAS_UINT8_T
] = 8,
66 [FIELD_TYPE_ALIAS_UINT16_T
] = 16,
67 [FIELD_TYPE_ALIAS_UINT27_T
] = 27,
68 [FIELD_TYPE_ALIAS_UINT32_T
] = 32,
69 [FIELD_TYPE_ALIAS_UINT64_T
] = 64,
72 struct bt_ctf_trace
*bt_ctf_trace_create(void)
74 struct bt_ctf_trace
*trace
= NULL
;
76 trace
= g_new0(struct bt_ctf_trace
, 1);
81 bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
);
82 bt_object_init(trace
, bt_ctf_trace_destroy
);
83 trace
->clocks
= g_ptr_array_new_with_free_func(
84 (GDestroyNotify
) bt_put
);
85 trace
->streams
= g_ptr_array_new_with_free_func(
86 (GDestroyNotify
) bt_object_release
);
87 trace
->stream_classes
= g_ptr_array_new_with_free_func(
88 (GDestroyNotify
) bt_object_release
);
89 if (!trace
->clocks
|| !trace
->stream_classes
|| !trace
->streams
) {
93 /* Generate a trace UUID */
94 uuid_generate(trace
->uuid
);
95 if (init_trace_packet_header(trace
)) {
99 /* Create the environment array object */
100 trace
->environment
= bt_ctf_attributes_create();
101 if (!trace
->environment
) {
112 void bt_ctf_trace_destroy(struct bt_object
*obj
)
114 struct bt_ctf_trace
*trace
;
116 trace
= container_of(obj
, struct bt_ctf_trace
, base
);
117 if (trace
->environment
) {
118 bt_ctf_attributes_destroy(trace
->environment
);
122 g_ptr_array_free(trace
->clocks
, TRUE
);
125 if (trace
->streams
) {
126 g_ptr_array_free(trace
->streams
, TRUE
);
129 if (trace
->stream_classes
) {
130 g_ptr_array_free(trace
->stream_classes
, TRUE
);
133 bt_put(trace
->packet_header_type
);
137 struct bt_ctf_stream
*bt_ctf_trace_create_stream(struct bt_ctf_trace
*trace
,
138 struct bt_ctf_stream_class
*stream_class
)
141 int stream_class_found
= 0;
143 struct bt_ctf_stream
*stream
= NULL
;
145 if (!trace
|| !stream_class
) {
149 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
150 if (trace
->stream_classes
->pdata
[i
] == stream_class
) {
151 stream_class_found
= 1;
155 if (!stream_class_found
) {
156 ret
= bt_ctf_trace_add_stream_class(trace
, stream_class
);
162 stream
= bt_ctf_stream_create(stream_class
, trace
);
167 g_ptr_array_add(trace
->streams
, stream
);
174 int bt_ctf_trace_set_environment_field(struct bt_ctf_trace
*trace
,
175 const char *name
, struct bt_value
*value
)
179 if (!trace
|| !name
|| !value
||
180 bt_ctf_validate_identifier(name
) ||
181 !(bt_value_is_integer(value
) || bt_value_is_string(value
))) {
186 if (strchr(name
, ' ')) {
193 * New environment fields may be added to a frozen trace,
194 * but existing fields may not be changed.
196 * The object passed is frozen like all other attributes.
198 struct bt_value
*attribute
=
199 bt_ctf_attributes_get_field_value_by_name(
200 trace
->environment
, name
);
208 bt_value_freeze(value
);
211 ret
= bt_ctf_attributes_set_field_value(trace
->environment
, name
,
218 int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace
*trace
,
219 const char *name
, const char *value
)
222 struct bt_value
*env_value_string_obj
= NULL
;
224 if (!trace
|| !name
|| !value
) {
231 * New environment fields may be added to a frozen trace,
232 * but existing fields may not be changed.
234 struct bt_value
*attribute
=
235 bt_ctf_attributes_get_field_value_by_name(
236 trace
->environment
, name
);
245 env_value_string_obj
= bt_value_string_create_init(value
);
247 if (!env_value_string_obj
) {
253 bt_value_freeze(env_value_string_obj
);
255 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
256 env_value_string_obj
);
259 BT_PUT(env_value_string_obj
);
263 int bt_ctf_trace_set_environment_field_integer(struct bt_ctf_trace
*trace
,
264 const char *name
, int64_t value
)
267 struct bt_value
*env_value_integer_obj
= NULL
;
269 if (!trace
|| !name
) {
276 * New environment fields may be added to a frozen trace,
277 * but existing fields may not be changed.
279 struct bt_value
*attribute
=
280 bt_ctf_attributes_get_field_value_by_name(
281 trace
->environment
, name
);
290 env_value_integer_obj
= bt_value_integer_create_init(value
);
291 if (!env_value_integer_obj
) {
296 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
297 env_value_integer_obj
);
299 bt_value_freeze(env_value_integer_obj
);
302 BT_PUT(env_value_integer_obj
);
306 int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace
*trace
)
315 ret
= bt_ctf_attributes_get_count(trace
->environment
);
322 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
325 const char *ret
= NULL
;
331 ret
= bt_ctf_attributes_get_field_name(trace
->environment
, index
);
337 struct bt_value
*bt_ctf_trace_get_environment_field_value(
338 struct bt_ctf_trace
*trace
, int index
)
340 struct bt_value
*ret
= NULL
;
346 ret
= bt_ctf_attributes_get_field_value(trace
->environment
, index
);
352 struct bt_value
*bt_ctf_trace_get_environment_field_value_by_name(
353 struct bt_ctf_trace
*trace
, const char *name
)
355 struct bt_value
*ret
= NULL
;
357 if (!trace
|| !name
) {
361 ret
= bt_ctf_attributes_get_field_value_by_name(trace
->environment
,
368 int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
369 struct bt_ctf_clock
*clock
)
372 struct search_query query
= { .value
= clock
, .found
= 0 };
374 if (!trace
|| !clock
) {
379 /* Check for duplicate clocks */
380 g_ptr_array_foreach(trace
->clocks
, value_exists
, &query
);
387 g_ptr_array_add(trace
->clocks
, clock
);
392 int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
)
400 ret
= trace
->clocks
->len
;
405 struct bt_ctf_clock
*bt_ctf_trace_get_clock(struct bt_ctf_trace
*trace
,
408 struct bt_ctf_clock
*clock
= NULL
;
410 if (!trace
|| index
< 0 || index
>= trace
->clocks
->len
) {
414 clock
= g_ptr_array_index(trace
->clocks
, index
);
420 int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
421 struct bt_ctf_stream_class
*stream_class
)
425 struct bt_ctf_validation_output trace_sc_validation_output
= { 0 };
426 struct bt_ctf_validation_output
*ec_validation_outputs
= NULL
;
427 const enum bt_ctf_validation_flag trace_sc_validation_flags
=
428 BT_CTF_VALIDATION_FLAG_TRACE
|
429 BT_CTF_VALIDATION_FLAG_STREAM
;
430 const enum bt_ctf_validation_flag ec_validation_flags
=
431 BT_CTF_VALIDATION_FLAG_EVENT
;
432 struct bt_ctf_field_type
*packet_header_type
= NULL
;
433 struct bt_ctf_field_type
*packet_context_type
= NULL
;
434 struct bt_ctf_field_type
*event_header_type
= NULL
;
435 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
436 int event_class_count
;
438 if (!trace
|| !stream_class
) {
444 bt_ctf_stream_class_get_event_class_count(stream_class
);
445 assert(event_class_count
>= 0);
447 /* Check for duplicate stream classes */
448 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
449 if (trace
->stream_classes
->pdata
[i
] == stream_class
) {
450 /* Stream class already registered to the trace */
457 * We're about to freeze both the trace and the stream class.
458 * Also, each event class contained in this stream class are
461 * This trace, this stream class, and all its event classes
462 * should be valid at this point.
464 * Validate trace and stream class first, then each event
465 * class of this stream class can be validated individually.
468 bt_ctf_trace_get_packet_header_type(trace
);
469 packet_context_type
=
470 bt_ctf_stream_class_get_packet_context_type(stream_class
);
472 bt_ctf_stream_class_get_event_header_type(stream_class
);
473 stream_event_ctx_type
=
474 bt_ctf_stream_class_get_event_context_type(stream_class
);
475 ret
= bt_ctf_validate_class_types(trace
->environment
,
476 packet_header_type
, packet_context_type
, event_header_type
,
477 stream_event_ctx_type
, NULL
, NULL
, trace
->valid
,
478 stream_class
->valid
, 1, &trace_sc_validation_output
,
479 trace_sc_validation_flags
);
480 BT_PUT(packet_header_type
);
481 BT_PUT(packet_context_type
);
482 BT_PUT(event_header_type
);
483 BT_PUT(stream_event_ctx_type
);
487 * This means something went wrong during the validation
488 * process, not that the objects are invalid.
493 if ((trace_sc_validation_output
.valid_flags
&
494 trace_sc_validation_flags
) !=
495 trace_sc_validation_flags
) {
496 /* Invalid trace/stream class */
501 if (event_class_count
> 0) {
502 ec_validation_outputs
= g_new0(struct bt_ctf_validation_output
,
504 if (!ec_validation_outputs
) {
510 /* Validate each event class individually */
511 for (i
= 0; i
< event_class_count
; ++i
) {
512 struct bt_ctf_event_class
*event_class
=
513 bt_ctf_stream_class_get_event_class(stream_class
, i
);
514 struct bt_ctf_field_type
*event_context_type
= NULL
;
515 struct bt_ctf_field_type
*event_payload_type
= NULL
;
518 bt_ctf_event_class_get_context_type(event_class
);
520 bt_ctf_event_class_get_payload_type(event_class
);
523 * It is important to use the field types returned by
524 * the previous trace and stream class validation here
525 * because copies could have been made.
527 ret
= bt_ctf_validate_class_types(trace
->environment
,
528 trace_sc_validation_output
.packet_header_type
,
529 trace_sc_validation_output
.packet_context_type
,
530 trace_sc_validation_output
.event_header_type
,
531 trace_sc_validation_output
.stream_event_ctx_type
,
532 event_context_type
, event_payload_type
,
533 1, 1, event_class
->valid
, &ec_validation_outputs
[i
],
534 ec_validation_flags
);
535 BT_PUT(event_context_type
);
536 BT_PUT(event_payload_type
);
543 if ((ec_validation_outputs
[i
].valid_flags
&
544 ec_validation_flags
) != ec_validation_flags
) {
545 /* Invalid event class */
551 stream_id
= bt_ctf_stream_class_get_id(stream_class
);
553 stream_id
= trace
->next_stream_id
++;
555 /* Try to assign a new stream id */
556 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
557 if (stream_id
== bt_ctf_stream_class_get_id(
558 trace
->stream_classes
->pdata
[i
])) {
559 /* Duplicate stream id found */
565 if (bt_ctf_stream_class_set_id_no_check(stream_class
,
567 /* TODO Should retry with a different stream id */
573 bt_object_set_parent(stream_class
, trace
);
574 g_ptr_array_add(trace
->stream_classes
, stream_class
);
577 * At this point we know that the function will be successful.
578 * Therefore we can replace the trace and stream class field
579 * types with what's in their validation output structure and
580 * mark them as valid. We can also replace the field types of
581 * all the event classes of the stream class and mark them as
584 bt_ctf_validation_replace_types(trace
, stream_class
, NULL
,
585 &trace_sc_validation_output
, trace_sc_validation_flags
);
587 stream_class
->valid
= 1;
590 * Put what was not moved in bt_ctf_validation_replace_types().
592 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
594 for (i
= 0; i
< event_class_count
; ++i
) {
595 struct bt_ctf_event_class
*event_class
=
596 bt_ctf_stream_class_get_event_class(stream_class
, i
);
598 bt_ctf_validation_replace_types(NULL
, NULL
, event_class
,
599 &ec_validation_outputs
[i
], ec_validation_flags
);
600 event_class
->valid
= 1;
604 * Put what was not moved in
605 * bt_ctf_validation_replace_types().
607 bt_ctf_validation_output_put_types(&ec_validation_outputs
[i
]);
611 * All field type byte orders set as "native" byte ordering can now be
612 * safely set to trace's own endianness, including the stream class'.
614 bt_ctf_field_type_set_native_byte_order(trace
->packet_header_type
,
616 bt_ctf_stream_class_set_byte_order(stream_class
, trace
->byte_order
);
619 * Freeze the trace and the stream class.
621 bt_ctf_stream_class_freeze(stream_class
);
622 bt_ctf_trace_freeze(trace
);
626 bt_object_set_parent(stream_class
, NULL
);
628 if (ec_validation_outputs
) {
629 for (i
= 0; i
< event_class_count
; ++i
) {
630 bt_ctf_validation_output_put_types(
631 &ec_validation_outputs
[i
]);
636 g_free(ec_validation_outputs
);
637 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
638 assert(!packet_header_type
);
639 assert(!packet_context_type
);
640 assert(!event_header_type
);
641 assert(!stream_event_ctx_type
);
646 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
)
655 ret
= trace
->stream_classes
->len
;
660 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
661 struct bt_ctf_trace
*trace
, int index
)
663 struct bt_ctf_stream_class
*stream_class
= NULL
;
665 if (!trace
|| index
< 0 || index
>= trace
->stream_classes
->len
) {
669 stream_class
= g_ptr_array_index(trace
->stream_classes
, index
);
670 bt_get(stream_class
);
675 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
676 struct bt_ctf_trace
*trace
, uint32_t id
)
679 struct bt_ctf_stream_class
*stream_class
= NULL
;
685 for (i
= 0; i
< trace
->stream_classes
->len
; ++i
) {
686 struct bt_ctf_stream_class
*stream_class_candidate
;
688 stream_class_candidate
=
689 g_ptr_array_index(trace
->stream_classes
, i
);
691 if (bt_ctf_stream_class_get_id(stream_class_candidate
) ==
693 stream_class
= stream_class_candidate
;
694 bt_get(stream_class
);
703 struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
704 struct bt_ctf_trace
*trace
, const char *name
)
707 struct bt_ctf_clock
*clock
= NULL
;
709 if (!trace
|| !name
) {
713 for (i
= 0; i
< trace
->clocks
->len
; ++i
) {
714 struct bt_ctf_clock
*cur_clk
=
715 g_ptr_array_index(trace
->clocks
, i
);
716 const char *cur_clk_name
= bt_ctf_clock_get_name(cur_clk
);
722 if (!strcmp(cur_clk_name
, name
)) {
734 const char *get_byte_order_string(int byte_order
)
738 switch (byte_order
) {
754 int append_trace_metadata(struct bt_ctf_trace
*trace
,
755 struct metadata_context
*context
)
757 unsigned char *uuid
= trace
->uuid
;
760 g_string_append(context
->string
, "trace {\n");
762 g_string_append(context
->string
, "\tmajor = 1;\n");
763 g_string_append(context
->string
, "\tminor = 8;\n");
765 g_string_append_printf(context
->string
,
766 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
767 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
768 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
769 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
770 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
771 g_string_append_printf(context
->string
, "\tbyte_order = %s;\n",
772 get_byte_order_string(trace
->byte_order
));
774 g_string_append(context
->string
, "\tpacket.header := ");
775 context
->current_indentation_level
++;
776 g_string_assign(context
->field_name
, "");
777 ret
= bt_ctf_field_type_serialize(trace
->packet_header_type
,
782 context
->current_indentation_level
--;
784 g_string_append(context
->string
, ";\n};\n\n");
790 void append_env_metadata(struct bt_ctf_trace
*trace
,
791 struct metadata_context
*context
)
796 env_size
= bt_ctf_attributes_get_count(trace
->environment
);
802 g_string_append(context
->string
, "env {\n");
804 for (i
= 0; i
< env_size
; ++i
) {
805 struct bt_value
*env_field_value_obj
= NULL
;
806 const char *entry_name
;
808 entry_name
= bt_ctf_attributes_get_field_name(
809 trace
->environment
, i
);
810 env_field_value_obj
= bt_ctf_attributes_get_field_value(
811 trace
->environment
, i
);
813 if (!entry_name
|| !env_field_value_obj
) {
817 switch (bt_value_get_type(env_field_value_obj
)) {
818 case BT_VALUE_TYPE_INTEGER
:
823 ret
= bt_value_integer_get(env_field_value_obj
,
830 g_string_append_printf(context
->string
,
831 "\t%s = %" PRId64
";\n", entry_name
,
835 case BT_VALUE_TYPE_STRING
:
838 const char *str_value
;
839 char *escaped_str
= NULL
;
841 ret
= bt_value_string_get(env_field_value_obj
,
848 escaped_str
= g_strescape(str_value
, NULL
);
854 g_string_append_printf(context
->string
,
855 "\t%s = \"%s\";\n", entry_name
, escaped_str
);
865 BT_PUT(env_field_value_obj
);
868 g_string_append(context
->string
, "};\n\n");
871 char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
)
873 char *metadata
= NULL
;
874 struct metadata_context
*context
= NULL
;
882 context
= g_new0(struct metadata_context
, 1);
887 context
->field_name
= g_string_sized_new(DEFAULT_IDENTIFIER_SIZE
);
888 context
->string
= g_string_sized_new(DEFAULT_METADATA_STRING_SIZE
);
889 g_string_append(context
->string
, "/* CTF 1.8 */\n\n");
890 if (append_trace_metadata(trace
, context
)) {
893 append_env_metadata(trace
, context
);
894 g_ptr_array_foreach(trace
->clocks
,
895 (GFunc
)bt_ctf_clock_serialize
, context
);
897 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
898 err
= bt_ctf_stream_class_serialize(
899 trace
->stream_classes
->pdata
[i
], context
);
905 metadata
= context
->string
->str
;
907 g_string_free(context
->string
, err
? TRUE
: FALSE
);
908 g_string_free(context
->field_name
, TRUE
);
914 enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(struct bt_ctf_trace
*trace
)
916 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
922 switch (trace
->byte_order
) {
924 ret
= BT_CTF_BYTE_ORDER_BIG_ENDIAN
;
927 ret
= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
;
936 int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
937 enum bt_ctf_byte_order byte_order
)
940 int internal_byte_order
;
942 if (!trace
|| trace
->frozen
) {
947 switch (byte_order
) {
948 case BT_CTF_BYTE_ORDER_NATIVE
:
950 * This doesn't make sense since the CTF specification defines
951 * the "native" byte order as "the byte order described in the
952 * trace description". However, this behavior had been
953 * implemented as part of v1.2 and is kept to maintain
956 * This may be changed on a major version bump only.
958 internal_byte_order
= (G_BYTE_ORDER
== G_LITTLE_ENDIAN
) ?
959 LITTLE_ENDIAN
: BIG_ENDIAN
;
961 case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
:
962 internal_byte_order
= LITTLE_ENDIAN
;
964 case BT_CTF_BYTE_ORDER_BIG_ENDIAN
:
965 case BT_CTF_BYTE_ORDER_NETWORK
:
966 internal_byte_order
= BIG_ENDIAN
;
973 trace
->byte_order
= internal_byte_order
;
978 struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
979 struct bt_ctf_trace
*trace
)
981 struct bt_ctf_field_type
*field_type
= NULL
;
987 bt_get(trace
->packet_header_type
);
988 field_type
= trace
->packet_header_type
;
993 int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
994 struct bt_ctf_field_type
*packet_header_type
)
998 if (!trace
|| !packet_header_type
|| trace
->frozen
) {
1003 /* packet_header_type must be a structure */
1004 if (bt_ctf_field_type_get_type_id(packet_header_type
) !=
1010 bt_get(packet_header_type
);
1011 bt_put(trace
->packet_header_type
);
1012 trace
->packet_header_type
= packet_header_type
;
1017 void bt_ctf_trace_get(struct bt_ctf_trace
*trace
)
1022 void bt_ctf_trace_put(struct bt_ctf_trace
*trace
)
1029 struct bt_ctf_field_type
*get_field_type(enum field_type_alias alias
)
1031 unsigned int alignment
, size
;
1032 struct bt_ctf_field_type
*field_type
= NULL
;
1034 if (alias
>= NR_FIELD_TYPE_ALIAS
) {
1038 alignment
= field_type_aliases_alignments
[alias
];
1039 size
= field_type_aliases_sizes
[alias
];
1040 field_type
= bt_ctf_field_type_integer_create(size
);
1041 bt_ctf_field_type_set_alignment(field_type
, alignment
);
1047 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
)
1049 bt_ctf_field_type_freeze(trace
->packet_header_type
);
1050 bt_ctf_attributes_freeze(trace
->environment
);
1055 int init_trace_packet_header(struct bt_ctf_trace
*trace
)
1058 struct bt_ctf_field
*magic
= NULL
, *uuid_array
= NULL
;
1059 struct bt_ctf_field_type
*_uint32_t
=
1060 get_field_type(FIELD_TYPE_ALIAS_UINT32_T
);
1061 struct bt_ctf_field_type
*_uint8_t
=
1062 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
1063 struct bt_ctf_field_type
*trace_packet_header_type
=
1064 bt_ctf_field_type_structure_create();
1065 struct bt_ctf_field_type
*uuid_array_type
=
1066 bt_ctf_field_type_array_create(_uint8_t
, 16);
1068 if (!trace_packet_header_type
|| !uuid_array_type
) {
1073 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1074 _uint32_t
, "magic");
1079 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1080 uuid_array_type
, "uuid");
1085 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1086 _uint32_t
, "stream_id");
1091 ret
= bt_ctf_trace_set_packet_header_type(trace
,
1092 trace_packet_header_type
);
1097 bt_put(uuid_array_type
);
1102 bt_put(trace_packet_header_type
);