2 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <babeltrace2/babeltrace.h>
24 #include "common/macros.h"
29 #include "common/assert.h"
30 #include "compat/endian.h"
32 #include "fs-sink-ctf-meta.h"
35 unsigned int indent_level
;
40 void append_indent(struct ctx
*ctx
)
44 for (i
= 0; i
< ctx
->indent_level
; i
++) {
45 g_string_append_c(ctx
->tsdl
, '\t');
50 void append_uuid(struct ctx
*ctx
, bt_uuid uuid
)
52 g_string_append_printf(ctx
->tsdl
,
53 "\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
54 (unsigned int) uuid
[0],
55 (unsigned int) uuid
[1],
56 (unsigned int) uuid
[2],
57 (unsigned int) uuid
[3],
58 (unsigned int) uuid
[4],
59 (unsigned int) uuid
[5],
60 (unsigned int) uuid
[6],
61 (unsigned int) uuid
[7],
62 (unsigned int) uuid
[8],
63 (unsigned int) uuid
[9],
64 (unsigned int) uuid
[10],
65 (unsigned int) uuid
[11],
66 (unsigned int) uuid
[12],
67 (unsigned int) uuid
[13],
68 (unsigned int) uuid
[14],
69 (unsigned int) uuid
[15]);
73 void append_quoted_string_content(struct ctx
*ctx
, const char *str
)
77 for (ch
= str
; *ch
!= '\0'; ch
++) {
78 unsigned char uch
= (unsigned char) *ch
;
80 if (uch
< 32 || uch
>= 127) {
83 g_string_append(ctx
->tsdl
, "\\a");
86 g_string_append(ctx
->tsdl
, "\\b");
89 g_string_append(ctx
->tsdl
, "\\f");
92 g_string_append(ctx
->tsdl
, "\\n");
95 g_string_append(ctx
->tsdl
, "\\r");
98 g_string_append(ctx
->tsdl
, "\\t");
101 g_string_append(ctx
->tsdl
, "\\v");
104 g_string_append_printf(ctx
->tsdl
, "\\x%02x",
108 } else if (*ch
== '"' || *ch
== '\\') {
109 g_string_append_c(ctx
->tsdl
, '\\');
110 g_string_append_c(ctx
->tsdl
, *ch
);
112 g_string_append_c(ctx
->tsdl
, *ch
);
118 void append_quoted_string(struct ctx
*ctx
, const char *str
)
120 g_string_append_c(ctx
->tsdl
, '"');
121 append_quoted_string_content(ctx
, str
);
122 g_string_append_c(ctx
->tsdl
, '"');
126 void append_integer_field_class_from_props(struct ctx
*ctx
, unsigned int size
,
127 unsigned int alignment
, bool is_signed
,
128 bt_field_class_integer_preferred_display_base disp_base
,
129 const char *mapped_clock_class_name
, const char *field_name
,
132 g_string_append_printf(ctx
->tsdl
,
133 "integer { size = %u; align = %u;",
137 g_string_append(ctx
->tsdl
, " signed = true;");
140 if (disp_base
!= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
) {
141 g_string_append(ctx
->tsdl
, " base = ");
144 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
145 g_string_append(ctx
->tsdl
, "b");
147 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
148 g_string_append(ctx
->tsdl
, "o");
150 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
151 g_string_append(ctx
->tsdl
, "x");
157 g_string_append_c(ctx
->tsdl
, ';');
160 if (mapped_clock_class_name
) {
161 g_string_append_printf(ctx
->tsdl
, " map = clock.%s.value;",
162 mapped_clock_class_name
);
165 g_string_append(ctx
->tsdl
, " }");
168 g_string_append_printf(ctx
->tsdl
, " %s", field_name
);
172 g_string_append(ctx
->tsdl
, ";\n");
177 void append_end_block(struct ctx
*ctx
)
181 g_string_append(ctx
->tsdl
, "}");
185 void append_end_block_semi_nl(struct ctx
*ctx
)
189 g_string_append(ctx
->tsdl
, "};\n");
193 void append_end_block_semi_nl_nl(struct ctx
*ctx
)
195 append_end_block_semi_nl(ctx
);
196 g_string_append_c(ctx
->tsdl
, '\n');
200 void append_integer_field_class(struct ctx
*ctx
,
201 struct fs_sink_ctf_field_class_int
*fc
)
203 const bt_field_class
*ir_fc
= fc
->base
.base
.ir_fc
;
204 bt_field_class_type type
= bt_field_class_get_type(ir_fc
);
205 bool is_signed
= type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
||
206 type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
;
208 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
209 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
210 g_string_append(ctx
->tsdl
, "enum : ");
213 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
214 fc
->base
.base
.alignment
, is_signed
,
215 bt_field_class_integer_get_preferred_display_base(ir_fc
),
218 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
219 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
222 g_string_append(ctx
->tsdl
, " {\n");
225 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_fc
); i
++) {
227 const bt_field_class_enumeration_mapping
*mapping
;
228 const bt_field_class_unsigned_enumeration_mapping
*u_mapping
;
229 const bt_field_class_signed_enumeration_mapping
*i_mapping
;
230 uint64_t range_count
;
234 i_mapping
= bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
236 mapping
= bt_field_class_signed_enumeration_mapping_as_mapping_const(
239 u_mapping
= bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
241 mapping
= bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
245 label
= bt_field_class_enumeration_mapping_get_label(
248 bt_field_class_enumeration_mapping_get_range_count(
251 for (range_i
= 0; range_i
< range_count
; range_i
++) {
255 * Systematically prepend `_` to the
256 * mapping's label as this could be used
257 * as the tag of a subsequent variant
258 * field class and variant FC option
259 * names are systematically protected
260 * with a leading `_`.
262 * FIXME: This is temporary as the
263 * library's API should change to
264 * decouple variant FC option names from
265 * selector FC labels. The current
266 * drawback is that an original label
267 * `HELLO` becomes `_HELLO` in the
268 * generated metadata, therefore tools
269 * expecting `HELLO` could fail.
271 g_string_append(ctx
->tsdl
, "\"_");
272 append_quoted_string_content(ctx
, label
);
273 g_string_append(ctx
->tsdl
, "\" = ");
276 int64_t lower
, upper
;
278 bt_field_class_signed_enumeration_mapping_get_range_by_index(
282 if (lower
== upper
) {
283 g_string_append_printf(
284 ctx
->tsdl
, "%" PRId64
,
287 g_string_append_printf(
288 ctx
->tsdl
, "%" PRId64
" ... %" PRId64
,
292 uint64_t lower
, upper
;
294 bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
298 if (lower
== upper
) {
299 g_string_append_printf(
300 ctx
->tsdl
, "%" PRIu64
,
303 g_string_append_printf(
304 ctx
->tsdl
, "%" PRIu64
" ... %" PRIu64
,
309 g_string_append(ctx
->tsdl
, ",\n");
313 append_end_block(ctx
);
318 void append_float_field_class(struct ctx
*ctx
,
319 struct fs_sink_ctf_field_class_float
*fc
)
321 unsigned int mant_dig
, exp_dig
;
323 if (bt_field_class_real_is_single_precision(fc
->base
.base
.ir_fc
)) {
331 g_string_append_printf(ctx
->tsdl
,
332 "floating_point { mant_dig = %u; exp_dig = %u; align = %u; }",
333 mant_dig
, exp_dig
, fc
->base
.base
.alignment
);
337 void append_string_field_class(struct ctx
*ctx
,
338 struct fs_sink_ctf_field_class_float
*fc
)
340 g_string_append(ctx
->tsdl
, "string { encoding = UTF8; }");
344 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
);
347 void append_member(struct ctx
*ctx
, const char *name
,
348 struct fs_sink_ctf_field_class
*fc
)
350 GString
*lengths
= NULL
;
351 const char *lengths_str
= "";
353 while (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
||
354 fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
356 lengths
= g_string_new(NULL
);
360 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
) {
361 struct fs_sink_ctf_field_class_array
*array_fc
=
364 g_string_append_printf(lengths
, "[%" PRIu64
"]",
366 fc
= array_fc
->base
.elem_fc
;
368 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
371 g_string_append_printf(lengths
, "[%s]",
372 seq_fc
->length_ref
->str
);
373 fc
= seq_fc
->base
.elem_fc
;
377 append_field_class(ctx
, fc
);
380 lengths_str
= lengths
->str
;
383 g_string_append_printf(ctx
->tsdl
, " %s%s;\n", name
, lengths_str
);
386 g_string_free(lengths
, TRUE
);
391 void append_struct_field_class_members(struct ctx
*ctx
,
392 struct fs_sink_ctf_field_class_struct
*struct_fc
)
396 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
397 struct fs_sink_ctf_named_field_class
*named_fc
=
398 fs_sink_ctf_field_class_struct_borrow_member_by_index(
400 struct fs_sink_ctf_field_class
*fc
= named_fc
->fc
;
402 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
403 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
406 if (seq_fc
->length_is_before
) {
408 append_integer_field_class_from_props(ctx
,
410 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
411 NULL
, seq_fc
->length_ref
->str
, true);
413 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
) {
414 struct fs_sink_ctf_field_class_variant
*var_fc
=
417 if (var_fc
->tag_is_before
) {
419 g_string_append(ctx
->tsdl
, "enum : ");
420 append_integer_field_class_from_props(ctx
,
422 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
424 g_string_append(ctx
->tsdl
, " {\n");
427 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
428 struct fs_sink_ctf_named_field_class
*named_fc
=
429 fs_sink_ctf_field_class_variant_borrow_option_by_index(
433 g_string_append_printf(ctx
->tsdl
,
434 "\"%s\" = %" PRIu64
",\n",
435 named_fc
->name
->str
, i
);
438 append_end_block(ctx
);
439 g_string_append_printf(ctx
->tsdl
, " %s;\n",
440 var_fc
->tag_ref
->str
);
445 append_member(ctx
, named_fc
->name
->str
, fc
);
450 void append_struct_field_class(struct ctx
*ctx
,
451 struct fs_sink_ctf_field_class_struct
*fc
)
453 g_string_append(ctx
->tsdl
, "struct {\n");
455 append_struct_field_class_members(ctx
, fc
);
456 append_end_block(ctx
);
457 g_string_append_printf(ctx
->tsdl
, " align(%u)",
462 void append_variant_field_class(struct ctx
*ctx
,
463 struct fs_sink_ctf_field_class_variant
*var_fc
)
467 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
468 var_fc
->tag_ref
->str
);
471 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
472 struct fs_sink_ctf_named_field_class
*named_fc
=
473 fs_sink_ctf_field_class_variant_borrow_option_by_index(
477 append_member(ctx
, named_fc
->name
->str
, named_fc
->fc
);
480 append_end_block(ctx
);
484 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
)
487 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
488 append_integer_field_class(ctx
, (void *) fc
);
490 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
491 append_float_field_class(ctx
, (void *) fc
);
493 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
494 append_string_field_class(ctx
, (void *) fc
);
496 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
497 append_struct_field_class(ctx
, (void *) fc
);
499 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
500 append_variant_field_class(ctx
, (void *) fc
);
508 void append_event_class(struct ctx
*ctx
, struct fs_sink_ctf_event_class
*ec
)
511 bt_event_class_log_level log_level
;
515 g_string_append(ctx
->tsdl
, "event {\n");
518 /* Event class properties */
520 g_string_append(ctx
->tsdl
, "name = ");
521 str
= bt_event_class_get_name(ec
->ir_ec
);
526 append_quoted_string(ctx
, str
);
527 g_string_append(ctx
->tsdl
, ";\n");
529 g_string_append_printf(ctx
->tsdl
, "stream_id = %" PRIu64
";\n",
530 bt_stream_class_get_id(ec
->sc
->ir_sc
));
532 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
533 bt_event_class_get_id(ec
->ir_ec
));
535 str
= bt_event_class_get_emf_uri(ec
->ir_ec
);
538 g_string_append(ctx
->tsdl
, "model.emf.uri = ");
539 append_quoted_string(ctx
, str
);
540 g_string_append(ctx
->tsdl
, ";\n");
543 if (bt_event_class_get_log_level(ec
->ir_ec
, &log_level
) ==
544 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
548 g_string_append(ctx
->tsdl
, "loglevel = ");
551 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
554 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
557 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
560 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
563 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
566 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
569 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
572 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
575 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
578 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
581 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
584 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
587 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
590 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
593 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
600 g_string_append_printf(ctx
->tsdl
, "%u;\n", level
);
603 /* Event specific context field class */
604 if (ec
->spec_context_fc
) {
606 g_string_append(ctx
->tsdl
, "context := ");
607 append_field_class(ctx
, ec
->spec_context_fc
);
608 g_string_append(ctx
->tsdl
, ";\n");
611 /* Event payload field class */
612 if (ec
->payload_fc
) {
614 g_string_append(ctx
->tsdl
, "fields := ");
615 append_field_class(ctx
, ec
->payload_fc
);
616 g_string_append(ctx
->tsdl
, ";\n");
619 append_end_block_semi_nl_nl(ctx
);
623 void append_stream_class(struct ctx
*ctx
,
624 struct fs_sink_ctf_stream_class
*sc
)
628 /* Default clock class */
629 if (sc
->default_clock_class
) {
631 int64_t offset_seconds
;
632 uint64_t offset_cycles
;
636 g_string_append(ctx
->tsdl
, "clock {\n");
638 BT_ASSERT(sc
->default_clock_class_name
->len
> 0);
640 g_string_append_printf(ctx
->tsdl
, "name = %s;\n",
641 sc
->default_clock_class_name
->str
);
642 descr
= bt_clock_class_get_description(sc
->default_clock_class
);
645 g_string_append(ctx
->tsdl
, "description = ");
646 append_quoted_string(ctx
, descr
);
647 g_string_append(ctx
->tsdl
, ";\n");
651 g_string_append_printf(ctx
->tsdl
, "freq = %" PRIu64
";\n",
652 bt_clock_class_get_frequency(sc
->default_clock_class
));
654 g_string_append_printf(ctx
->tsdl
, "precision = %" PRIu64
";\n",
655 bt_clock_class_get_precision(sc
->default_clock_class
));
656 bt_clock_class_get_offset(sc
->default_clock_class
,
657 &offset_seconds
, &offset_cycles
);
659 g_string_append_printf(ctx
->tsdl
, "offset_s = %" PRId64
";\n",
662 g_string_append_printf(ctx
->tsdl
, "offset = %" PRIu64
";\n",
665 g_string_append(ctx
->tsdl
, "absolute = ");
667 if (bt_clock_class_origin_is_unix_epoch(
668 sc
->default_clock_class
)) {
669 g_string_append(ctx
->tsdl
, "true");
671 g_string_append(ctx
->tsdl
, "false");
674 g_string_append(ctx
->tsdl
, ";\n");
675 uuid
= bt_clock_class_get_uuid(sc
->default_clock_class
);
678 g_string_append(ctx
->tsdl
, "uuid = ");
679 append_uuid(ctx
, uuid
);
680 g_string_append(ctx
->tsdl
, ";\n");
683 /* End clock class */
684 append_end_block_semi_nl_nl(ctx
);
689 g_string_append(ctx
->tsdl
, "stream {\n");
692 /* Stream class properties */
694 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
695 bt_stream_class_get_id(sc
->ir_sc
));
697 /* Packet context field class */
699 g_string_append(ctx
->tsdl
, "packet.context := struct {\n");
702 append_integer_field_class_from_props(ctx
, 64, 8, false,
703 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
704 NULL
, "packet_size", true);
706 append_integer_field_class_from_props(ctx
, 64, 8, false,
707 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
708 NULL
, "content_size", true);
710 if (sc
->packets_have_ts_begin
) {
712 append_integer_field_class_from_props(ctx
, 64, 8, false,
713 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
714 sc
->default_clock_class_name
->str
,
715 "timestamp_begin", true);
718 if (sc
->packets_have_ts_end
) {
720 append_integer_field_class_from_props(ctx
, 64, 8, false,
721 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
722 sc
->default_clock_class_name
->str
,
723 "timestamp_end", true);
726 if (sc
->has_discarded_events
) {
728 append_integer_field_class_from_props(ctx
, 64, 8, false,
729 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
730 NULL
, "events_discarded", true);
734 * Unconditionnally write the packet sequence number as, even if
735 * there's no possible discarded packets message, it's still
736 * useful information to have.
739 append_integer_field_class_from_props(ctx
, 64, 8, false,
740 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
741 NULL
, "packet_seq_num", true);
743 if (sc
->packet_context_fc
) {
744 append_struct_field_class_members(ctx
,
745 (void *) sc
->packet_context_fc
);
746 fs_sink_ctf_field_class_struct_align_at_least(
747 (void *) sc
->packet_context_fc
, 8);
750 /* End packet context field class */
751 append_end_block(ctx
);
752 g_string_append_printf(ctx
->tsdl
, " align(%u);\n\n",
753 sc
->packet_context_fc
? sc
->packet_context_fc
->alignment
: 8);
755 /* Event header field class */
757 g_string_append(ctx
->tsdl
, "event.header := struct {\n");
760 append_integer_field_class_from_props(ctx
, 64, 8, false,
761 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
764 if (sc
->default_clock_class
) {
766 append_integer_field_class_from_props(ctx
, 64, 8, false,
767 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
768 sc
->default_clock_class_name
->str
,
772 /* End event header field class */
773 append_end_block(ctx
);
774 g_string_append(ctx
->tsdl
, " align(8);\n");
776 /* Event common context field class */
777 if (sc
->event_common_context_fc
) {
779 g_string_append(ctx
->tsdl
, "event.context := ");
780 append_field_class(ctx
,
781 (void *) sc
->event_common_context_fc
);
782 g_string_append(ctx
->tsdl
, ";\n");
785 /* End stream class */
786 append_end_block_semi_nl_nl(ctx
);
789 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
790 append_event_class(ctx
, sc
->event_classes
->pdata
[i
]);
795 void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace
*trace
,
805 g_string_assign(tsdl
, "/* CTF 1.8 */\n\n");
806 g_string_append(tsdl
, "/* This was generated by a Babeltrace `sink.ctf.fs` component. */\n\n");
810 g_string_append(tsdl
, "trace {\n");
813 /* Trace class properties */
815 g_string_append(tsdl
, "major = 1;\n");
817 g_string_append(tsdl
, "minor = 8;\n");
819 g_string_append(tsdl
, "uuid = ");
820 append_uuid(&ctx
, trace
->uuid
);
821 g_string_append(tsdl
, ";\n");
823 g_string_append(tsdl
, "byte_order = ");
825 if (BYTE_ORDER
== LITTLE_ENDIAN
) {
826 g_string_append(tsdl
, "le");
828 g_string_append(tsdl
, "be");
831 g_string_append(tsdl
, ";\n");
833 /* Packet header field class */
835 g_string_append(tsdl
, "packet.header := struct {\n");
838 append_integer_field_class_from_props(&ctx
, 32, 8, false,
839 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
840 NULL
, "magic", true);
842 append_integer_field_class_from_props(&ctx
, 8, 8, false,
843 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
844 NULL
, "uuid[16]", true);
846 append_integer_field_class_from_props(&ctx
, 64, 8, false,
847 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
848 NULL
, "stream_id", true);
850 append_integer_field_class_from_props(&ctx
, 64, 8, false,
851 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
852 NULL
, "stream_instance_id", true);
854 /* End packet header field class */
855 append_end_block(&ctx
);
856 g_string_append(ctx
.tsdl
, " align(8);\n");
858 /* End trace class */
859 append_end_block_semi_nl_nl(&ctx
);
861 /* Trace environment */
862 count
= bt_trace_get_environment_entry_count(trace
->ir_trace
);
865 g_string_append(tsdl
, "env {\n");
868 for (i
= 0; i
< count
; i
++) {
872 bt_trace_borrow_environment_entry_by_index_const(
873 trace
->ir_trace
, i
, &name
, &val
);
875 g_string_append_printf(tsdl
, "%s = ", name
);
877 switch (bt_value_get_type(val
)) {
878 case BT_VALUE_TYPE_SIGNED_INTEGER
:
879 g_string_append_printf(tsdl
, "%" PRId64
,
880 bt_value_signed_integer_get(val
));
882 case BT_VALUE_TYPE_STRING
:
883 append_quoted_string(&ctx
, bt_value_string_get(val
));
888 * translate_trace_trace_ir_to_ctf_ir().
893 g_string_append(tsdl
, ";\n");
896 /* End trace class environment */
897 append_end_block_semi_nl_nl(&ctx
);
900 /* Stream classes and their event classes */
901 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
902 append_stream_class(&ctx
, trace
->stream_classes
->pdata
[i
]);