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
49 struct notification_handler
{
50 bt_ctf_notification_cb func
;
55 void bt_ctf_trace_destroy(struct bt_object
*obj
);
57 int init_trace_packet_header(struct bt_ctf_trace
*trace
);
59 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
);
62 const unsigned int field_type_aliases_alignments
[] = {
63 [FIELD_TYPE_ALIAS_UINT5_T
] = 1,
64 [FIELD_TYPE_ALIAS_UINT8_T
... FIELD_TYPE_ALIAS_UINT16_T
] = 8,
65 [FIELD_TYPE_ALIAS_UINT27_T
] = 1,
66 [FIELD_TYPE_ALIAS_UINT32_T
... FIELD_TYPE_ALIAS_UINT64_T
] = 8,
70 const unsigned int field_type_aliases_sizes
[] = {
71 [FIELD_TYPE_ALIAS_UINT5_T
] = 5,
72 [FIELD_TYPE_ALIAS_UINT8_T
] = 8,
73 [FIELD_TYPE_ALIAS_UINT16_T
] = 16,
74 [FIELD_TYPE_ALIAS_UINT27_T
] = 27,
75 [FIELD_TYPE_ALIAS_UINT32_T
] = 32,
76 [FIELD_TYPE_ALIAS_UINT64_T
] = 64,
79 struct bt_ctf_trace
*bt_ctf_trace_create(void)
81 struct bt_ctf_trace
*trace
= NULL
;
83 trace
= g_new0(struct bt_ctf_trace
, 1);
88 bt_ctf_trace_set_byte_order(trace
, BT_CTF_BYTE_ORDER_NATIVE
);
89 bt_object_init(trace
, bt_ctf_trace_destroy
);
90 trace
->clocks
= g_ptr_array_new_with_free_func(
91 (GDestroyNotify
) bt_put
);
92 trace
->streams
= g_ptr_array_new_with_free_func(
93 (GDestroyNotify
) bt_object_release
);
94 trace
->stream_classes
= g_ptr_array_new_with_free_func(
95 (GDestroyNotify
) bt_object_release
);
96 if (!trace
->clocks
|| !trace
->stream_classes
|| !trace
->streams
) {
100 /* Generate a trace UUID */
101 uuid_generate(trace
->uuid
);
102 if (init_trace_packet_header(trace
)) {
106 /* Create the environment array object */
107 trace
->environment
= bt_ctf_attributes_create();
108 if (!trace
->environment
) {
119 void bt_ctf_trace_destroy(struct bt_object
*obj
)
121 struct bt_ctf_trace
*trace
;
123 trace
= container_of(obj
, struct bt_ctf_trace
, base
);
124 if (trace
->environment
) {
125 bt_ctf_attributes_destroy(trace
->environment
);
129 g_ptr_array_free(trace
->clocks
, TRUE
);
132 if (trace
->streams
) {
133 g_ptr_array_free(trace
->streams
, TRUE
);
136 if (trace
->stream_classes
) {
137 g_ptr_array_free(trace
->stream_classes
, TRUE
);
140 bt_put(trace
->packet_header_type
);
144 int bt_ctf_trace_set_environment_field(struct bt_ctf_trace
*trace
,
145 const char *name
, struct bt_value
*value
)
149 if (!trace
|| !name
|| !value
||
150 bt_ctf_validate_identifier(name
) ||
151 !(bt_value_is_integer(value
) || bt_value_is_string(value
))) {
156 if (strchr(name
, ' ')) {
163 * New environment fields may be added to a frozen trace,
164 * but existing fields may not be changed.
166 * The object passed is frozen like all other attributes.
168 struct bt_value
*attribute
=
169 bt_ctf_attributes_get_field_value_by_name(
170 trace
->environment
, name
);
178 bt_value_freeze(value
);
181 ret
= bt_ctf_attributes_set_field_value(trace
->environment
, name
,
188 int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace
*trace
,
189 const char *name
, const char *value
)
192 struct bt_value
*env_value_string_obj
= NULL
;
194 if (!trace
|| !name
|| !value
) {
201 * New environment fields may be added to a frozen trace,
202 * but existing fields may not be changed.
204 struct bt_value
*attribute
=
205 bt_ctf_attributes_get_field_value_by_name(
206 trace
->environment
, name
);
215 env_value_string_obj
= bt_value_string_create_init(value
);
217 if (!env_value_string_obj
) {
223 bt_value_freeze(env_value_string_obj
);
225 ret
= bt_ctf_trace_set_environment_field(trace
, name
,
226 env_value_string_obj
);
229 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
);
276 int bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace
*trace
)
285 ret
= bt_ctf_attributes_get_count(trace
->environment
);
292 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
295 const char *ret
= NULL
;
301 ret
= bt_ctf_attributes_get_field_name(trace
->environment
, index
);
307 struct bt_value
*bt_ctf_trace_get_environment_field_value(
308 struct bt_ctf_trace
*trace
, int index
)
310 struct bt_value
*ret
= NULL
;
316 ret
= bt_ctf_attributes_get_field_value(trace
->environment
, index
);
322 struct bt_value
*bt_ctf_trace_get_environment_field_value_by_name(
323 struct bt_ctf_trace
*trace
, const char *name
)
325 struct bt_value
*ret
= NULL
;
327 if (!trace
|| !name
) {
331 ret
= bt_ctf_attributes_get_field_value_by_name(trace
->environment
,
338 int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
339 struct bt_ctf_clock
*clock
)
342 struct search_query query
= { .value
= clock
, .found
= 0 };
344 if (!trace
|| !clock
) {
349 /* Check for duplicate clocks */
350 g_ptr_array_foreach(trace
->clocks
, value_exists
, &query
);
357 g_ptr_array_add(trace
->clocks
, clock
);
359 if (!trace
->is_created_by_writer
) {
361 * Non-writer mode trace: disable clock value functions
362 * because clock values are per-stream in that
365 clock
->has_value
= 0;
369 bt_ctf_clock_freeze(clock
);
375 int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
)
383 ret
= trace
->clocks
->len
;
388 struct bt_ctf_clock
*bt_ctf_trace_get_clock(struct bt_ctf_trace
*trace
,
391 struct bt_ctf_clock
*clock
= NULL
;
393 if (!trace
|| index
< 0 || index
>= trace
->clocks
->len
) {
397 clock
= g_ptr_array_index(trace
->clocks
, index
);
403 int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
404 struct bt_ctf_stream_class
*stream_class
)
408 struct bt_ctf_validation_output trace_sc_validation_output
= { 0 };
409 struct bt_ctf_validation_output
*ec_validation_outputs
= NULL
;
410 const enum bt_ctf_validation_flag trace_sc_validation_flags
=
411 BT_CTF_VALIDATION_FLAG_TRACE
|
412 BT_CTF_VALIDATION_FLAG_STREAM
;
413 const enum bt_ctf_validation_flag ec_validation_flags
=
414 BT_CTF_VALIDATION_FLAG_EVENT
;
415 struct bt_ctf_field_type
*packet_header_type
= NULL
;
416 struct bt_ctf_field_type
*packet_context_type
= NULL
;
417 struct bt_ctf_field_type
*event_header_type
= NULL
;
418 struct bt_ctf_field_type
*stream_event_ctx_type
= NULL
;
419 int event_class_count
;
420 struct bt_ctf_clock
*clock_to_add_to_trace
= NULL
;
422 if (!trace
|| !stream_class
) {
428 bt_ctf_stream_class_get_event_class_count(stream_class
);
429 assert(event_class_count
>= 0);
431 /* Check for duplicate stream classes */
432 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
433 if (trace
->stream_classes
->pdata
[i
] == stream_class
) {
434 /* Stream class already registered to the trace */
441 * If the stream class has a clock, register this clock to this
442 * trace if not already done.
444 if (stream_class
->clock
) {
445 const char *clock_name
=
446 bt_ctf_clock_get_name(stream_class
->clock
);
447 struct bt_ctf_clock
*trace_clock
;
450 trace_clock
= bt_ctf_trace_get_clock_by_name(trace
, clock_name
);
453 if (trace_clock
!= stream_class
->clock
) {
455 * Error: two different clocks in the
456 * trace would share the same name.
462 clock_to_add_to_trace
= bt_get(stream_class
->clock
);
467 * We're about to freeze both the trace and the stream class.
468 * Also, each event class contained in this stream class are
471 * This trace, this stream class, and all its event classes
472 * should be valid at this point.
474 * Validate trace and stream class first, then each event
475 * class of this stream class can be validated individually.
478 bt_ctf_trace_get_packet_header_type(trace
);
479 packet_context_type
=
480 bt_ctf_stream_class_get_packet_context_type(stream_class
);
482 bt_ctf_stream_class_get_event_header_type(stream_class
);
483 stream_event_ctx_type
=
484 bt_ctf_stream_class_get_event_context_type(stream_class
);
485 ret
= bt_ctf_validate_class_types(trace
->environment
,
486 packet_header_type
, packet_context_type
, event_header_type
,
487 stream_event_ctx_type
, NULL
, NULL
, trace
->valid
,
488 stream_class
->valid
, 1, &trace_sc_validation_output
,
489 trace_sc_validation_flags
);
490 BT_PUT(packet_header_type
);
491 BT_PUT(packet_context_type
);
492 BT_PUT(event_header_type
);
493 BT_PUT(stream_event_ctx_type
);
497 * This means something went wrong during the validation
498 * process, not that the objects are invalid.
503 if ((trace_sc_validation_output
.valid_flags
&
504 trace_sc_validation_flags
) !=
505 trace_sc_validation_flags
) {
506 /* Invalid trace/stream class */
511 if (event_class_count
> 0) {
512 ec_validation_outputs
= g_new0(struct bt_ctf_validation_output
,
514 if (!ec_validation_outputs
) {
520 /* Validate each event class individually */
521 for (i
= 0; i
< event_class_count
; i
++) {
522 struct bt_ctf_event_class
*event_class
=
523 bt_ctf_stream_class_get_event_class(stream_class
, i
);
524 struct bt_ctf_field_type
*event_context_type
= NULL
;
525 struct bt_ctf_field_type
*event_payload_type
= NULL
;
528 bt_ctf_event_class_get_context_type(event_class
);
530 bt_ctf_event_class_get_payload_type(event_class
);
533 * It is important to use the field types returned by
534 * the previous trace and stream class validation here
535 * because copies could have been made.
537 ret
= bt_ctf_validate_class_types(trace
->environment
,
538 trace_sc_validation_output
.packet_header_type
,
539 trace_sc_validation_output
.packet_context_type
,
540 trace_sc_validation_output
.event_header_type
,
541 trace_sc_validation_output
.stream_event_ctx_type
,
542 event_context_type
, event_payload_type
,
543 1, 1, event_class
->valid
, &ec_validation_outputs
[i
],
544 ec_validation_flags
);
545 BT_PUT(event_context_type
);
546 BT_PUT(event_payload_type
);
553 if ((ec_validation_outputs
[i
].valid_flags
&
554 ec_validation_flags
) != ec_validation_flags
) {
555 /* Invalid event class */
561 stream_id
= bt_ctf_stream_class_get_id(stream_class
);
563 stream_id
= trace
->next_stream_id
++;
565 /* Try to assign a new stream id */
566 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
567 if (stream_id
== bt_ctf_stream_class_get_id(
568 trace
->stream_classes
->pdata
[i
])) {
569 /* Duplicate stream id found */
575 if (bt_ctf_stream_class_set_id_no_check(stream_class
,
577 /* TODO Should retry with a different stream id */
583 bt_object_set_parent(stream_class
, trace
);
584 g_ptr_array_add(trace
->stream_classes
, stream_class
);
587 * At this point we know that the function will be successful.
588 * Therefore we can replace the trace and stream class field
589 * types with what's in their validation output structure and
590 * mark them as valid. We can also replace the field types of
591 * all the event classes of the stream class and mark them as
594 bt_ctf_validation_replace_types(trace
, stream_class
, NULL
,
595 &trace_sc_validation_output
, trace_sc_validation_flags
);
597 stream_class
->valid
= 1;
600 * Put what was not moved in bt_ctf_validation_replace_types().
602 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
604 for (i
= 0; i
< event_class_count
; i
++) {
605 struct bt_ctf_event_class
*event_class
=
606 bt_ctf_stream_class_get_event_class(stream_class
, i
);
608 bt_ctf_validation_replace_types(NULL
, NULL
, event_class
,
609 &ec_validation_outputs
[i
], ec_validation_flags
);
610 event_class
->valid
= 1;
614 * Put what was not moved in
615 * bt_ctf_validation_replace_types().
617 bt_ctf_validation_output_put_types(&ec_validation_outputs
[i
]);
621 * All field type byte orders set as "native" byte ordering can now be
622 * safely set to trace's own endianness, including the stream class'.
624 bt_ctf_field_type_set_native_byte_order(trace
->packet_header_type
,
626 bt_ctf_stream_class_set_byte_order(stream_class
, trace
->byte_order
);
628 /* Add stream class's clock if it exists */
629 if (clock_to_add_to_trace
) {
631 bt_ctf_trace_add_clock(trace
, clock_to_add_to_trace
);
632 assert(add_clock_ret
== 0);
636 * Freeze the trace and the stream class.
638 bt_ctf_stream_class_freeze(stream_class
);
639 bt_ctf_trace_freeze(trace
);
643 bt_object_set_parent(stream_class
, NULL
);
645 if (ec_validation_outputs
) {
646 for (i
= 0; i
< event_class_count
; i
++) {
647 bt_ctf_validation_output_put_types(
648 &ec_validation_outputs
[i
]);
653 g_free(ec_validation_outputs
);
654 bt_ctf_validation_output_put_types(&trace_sc_validation_output
);
655 BT_PUT(clock_to_add_to_trace
);
656 assert(!packet_header_type
);
657 assert(!packet_context_type
);
658 assert(!event_header_type
);
659 assert(!stream_event_ctx_type
);
664 int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
)
673 ret
= trace
->stream_classes
->len
;
678 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
679 struct bt_ctf_trace
*trace
, int index
)
681 struct bt_ctf_stream_class
*stream_class
= NULL
;
683 if (!trace
|| index
< 0 || index
>= trace
->stream_classes
->len
) {
687 stream_class
= g_ptr_array_index(trace
->stream_classes
, index
);
688 bt_get(stream_class
);
693 struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
694 struct bt_ctf_trace
*trace
, uint32_t id
)
697 struct bt_ctf_stream_class
*stream_class
= NULL
;
703 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
704 struct bt_ctf_stream_class
*stream_class_candidate
;
706 stream_class_candidate
=
707 g_ptr_array_index(trace
->stream_classes
, i
);
709 if (bt_ctf_stream_class_get_id(stream_class_candidate
) ==
711 stream_class
= stream_class_candidate
;
712 bt_get(stream_class
);
721 struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
722 struct bt_ctf_trace
*trace
, const char *name
)
725 struct bt_ctf_clock
*clock
= NULL
;
727 if (!trace
|| !name
) {
731 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
732 struct bt_ctf_clock
*cur_clk
=
733 g_ptr_array_index(trace
->clocks
, i
);
734 const char *cur_clk_name
= bt_ctf_clock_get_name(cur_clk
);
740 if (!strcmp(cur_clk_name
, name
)) {
752 const char *get_byte_order_string(int byte_order
)
756 switch (byte_order
) {
772 int append_trace_metadata(struct bt_ctf_trace
*trace
,
773 struct metadata_context
*context
)
775 unsigned char *uuid
= trace
->uuid
;
778 g_string_append(context
->string
, "trace {\n");
780 g_string_append(context
->string
, "\tmajor = 1;\n");
781 g_string_append(context
->string
, "\tminor = 8;\n");
783 g_string_append_printf(context
->string
,
784 "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
785 uuid
[0], uuid
[1], uuid
[2], uuid
[3],
786 uuid
[4], uuid
[5], uuid
[6], uuid
[7],
787 uuid
[8], uuid
[9], uuid
[10], uuid
[11],
788 uuid
[12], uuid
[13], uuid
[14], uuid
[15]);
789 g_string_append_printf(context
->string
, "\tbyte_order = %s;\n",
790 get_byte_order_string(trace
->byte_order
));
792 g_string_append(context
->string
, "\tpacket.header := ");
793 context
->current_indentation_level
++;
794 g_string_assign(context
->field_name
, "");
795 ret
= bt_ctf_field_type_serialize(trace
->packet_header_type
,
800 context
->current_indentation_level
--;
802 g_string_append(context
->string
, ";\n};\n\n");
808 void append_env_metadata(struct bt_ctf_trace
*trace
,
809 struct metadata_context
*context
)
814 env_size
= bt_ctf_attributes_get_count(trace
->environment
);
820 g_string_append(context
->string
, "env {\n");
822 for (i
= 0; i
< env_size
; i
++) {
823 struct bt_value
*env_field_value_obj
= NULL
;
824 const char *entry_name
;
826 entry_name
= bt_ctf_attributes_get_field_name(
827 trace
->environment
, i
);
828 env_field_value_obj
= bt_ctf_attributes_get_field_value(
829 trace
->environment
, i
);
831 if (!entry_name
|| !env_field_value_obj
) {
835 switch (bt_value_get_type(env_field_value_obj
)) {
836 case BT_VALUE_TYPE_INTEGER
:
841 ret
= bt_value_integer_get(env_field_value_obj
,
848 g_string_append_printf(context
->string
,
849 "\t%s = %" PRId64
";\n", entry_name
,
853 case BT_VALUE_TYPE_STRING
:
856 const char *str_value
;
857 char *escaped_str
= NULL
;
859 ret
= bt_value_string_get(env_field_value_obj
,
866 escaped_str
= g_strescape(str_value
, NULL
);
872 g_string_append_printf(context
->string
,
873 "\t%s = \"%s\";\n", entry_name
, escaped_str
);
883 BT_PUT(env_field_value_obj
);
886 g_string_append(context
->string
, "};\n\n");
889 char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
)
891 char *metadata
= NULL
;
892 struct metadata_context
*context
= NULL
;
900 context
= g_new0(struct metadata_context
, 1);
905 context
->field_name
= g_string_sized_new(DEFAULT_IDENTIFIER_SIZE
);
906 context
->string
= g_string_sized_new(DEFAULT_METADATA_STRING_SIZE
);
907 g_string_append(context
->string
, "/* CTF 1.8 */\n\n");
908 if (append_trace_metadata(trace
, context
)) {
911 append_env_metadata(trace
, context
);
912 g_ptr_array_foreach(trace
->clocks
,
913 (GFunc
)bt_ctf_clock_serialize
, context
);
915 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
916 err
= bt_ctf_stream_class_serialize(
917 trace
->stream_classes
->pdata
[i
], context
);
923 metadata
= context
->string
->str
;
925 g_string_free(context
->string
, err
? TRUE
: FALSE
);
926 g_string_free(context
->field_name
, TRUE
);
932 enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(struct bt_ctf_trace
*trace
)
934 enum bt_ctf_byte_order ret
= BT_CTF_BYTE_ORDER_UNKNOWN
;
940 switch (trace
->byte_order
) {
942 ret
= BT_CTF_BYTE_ORDER_BIG_ENDIAN
;
945 ret
= BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
;
954 int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
955 enum bt_ctf_byte_order byte_order
)
958 int internal_byte_order
;
960 if (!trace
|| trace
->frozen
) {
965 switch (byte_order
) {
966 case BT_CTF_BYTE_ORDER_NATIVE
:
968 * This doesn't make sense since the CTF specification defines
969 * the "native" byte order as "the byte order described in the
970 * trace description". However, this behavior had been
971 * implemented as part of v1.2 and is kept to maintain
974 * This may be changed on a major version bump only.
976 internal_byte_order
= (G_BYTE_ORDER
== G_LITTLE_ENDIAN
) ?
977 LITTLE_ENDIAN
: BIG_ENDIAN
;
979 case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN
:
980 internal_byte_order
= LITTLE_ENDIAN
;
982 case BT_CTF_BYTE_ORDER_BIG_ENDIAN
:
983 case BT_CTF_BYTE_ORDER_NETWORK
:
984 internal_byte_order
= BIG_ENDIAN
;
991 trace
->byte_order
= internal_byte_order
;
996 struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
997 struct bt_ctf_trace
*trace
)
999 struct bt_ctf_field_type
*field_type
= NULL
;
1005 bt_get(trace
->packet_header_type
);
1006 field_type
= trace
->packet_header_type
;
1011 int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
1012 struct bt_ctf_field_type
*packet_header_type
)
1016 if (!trace
|| !packet_header_type
|| trace
->frozen
) {
1021 /* packet_header_type must be a structure */
1022 if (bt_ctf_field_type_get_type_id(packet_header_type
) !=
1023 BT_CTF_TYPE_ID_STRUCT
) {
1028 bt_get(packet_header_type
);
1029 bt_put(trace
->packet_header_type
);
1030 trace
->packet_header_type
= packet_header_type
;
1035 int bt_ctf_trace_add_notification_handler_cb(struct bt_ctf_trace
*trace
,
1036 bt_ctf_notification_cb handler
, void *handler_data
)
1039 struct notification_handler
*handler_wrapper
=
1040 g_new0(struct notification_handler
, 1);
1042 if (!trace
|| !handler
|| !handler_wrapper
) {
1047 handler_wrapper
->func
= handler
;
1048 handler_wrapper
->data
= handler_data
;
1049 g_ptr_array_add(trace
->notification_handlers
, handler_wrapper
);
1052 g_free(handler_wrapper
);
1057 struct bt_ctf_field_type
*get_field_type(enum field_type_alias alias
)
1060 unsigned int alignment
, size
;
1061 struct bt_ctf_field_type
*field_type
= NULL
;
1063 if (alias
>= NR_FIELD_TYPE_ALIAS
) {
1067 alignment
= field_type_aliases_alignments
[alias
];
1068 size
= field_type_aliases_sizes
[alias
];
1069 field_type
= bt_ctf_field_type_integer_create(size
);
1070 ret
= bt_ctf_field_type_set_alignment(field_type
, alignment
);
1079 void bt_ctf_trace_freeze(struct bt_ctf_trace
*trace
)
1083 bt_ctf_field_type_freeze(trace
->packet_header_type
);
1084 bt_ctf_attributes_freeze(trace
->environment
);
1086 for (i
= 0; i
< trace
->clocks
->len
; i
++) {
1087 struct bt_ctf_clock
*clock
=
1088 g_ptr_array_index(trace
->clocks
, i
);
1090 bt_ctf_clock_freeze(clock
);
1097 int init_trace_packet_header(struct bt_ctf_trace
*trace
)
1100 struct bt_ctf_field
*magic
= NULL
, *uuid_array
= NULL
;
1101 struct bt_ctf_field_type
*_uint32_t
=
1102 get_field_type(FIELD_TYPE_ALIAS_UINT32_T
);
1103 struct bt_ctf_field_type
*_uint8_t
=
1104 get_field_type(FIELD_TYPE_ALIAS_UINT8_T
);
1105 struct bt_ctf_field_type
*trace_packet_header_type
=
1106 bt_ctf_field_type_structure_create();
1107 struct bt_ctf_field_type
*uuid_array_type
=
1108 bt_ctf_field_type_array_create(_uint8_t
, 16);
1110 if (!trace_packet_header_type
|| !uuid_array_type
) {
1115 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1116 _uint32_t
, "magic");
1121 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1122 uuid_array_type
, "uuid");
1127 ret
= bt_ctf_field_type_structure_add_field(trace_packet_header_type
,
1128 _uint32_t
, "stream_id");
1133 ret
= bt_ctf_trace_set_packet_header_type(trace
,
1134 trace_packet_header_type
);
1139 bt_put(uuid_array_type
);
1144 bt_put(trace_packet_header_type
);