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 "\"" BT_UUID_FMT
"\"",
54 BT_UUID_FMT_VALUES(uuid
));
58 void append_quoted_string_content(struct ctx
*ctx
, const char *str
)
62 for (ch
= str
; *ch
!= '\0'; ch
++) {
63 unsigned char uch
= (unsigned char) *ch
;
65 if (uch
< 32 || uch
>= 127) {
68 g_string_append(ctx
->tsdl
, "\\a");
71 g_string_append(ctx
->tsdl
, "\\b");
74 g_string_append(ctx
->tsdl
, "\\f");
77 g_string_append(ctx
->tsdl
, "\\n");
80 g_string_append(ctx
->tsdl
, "\\r");
83 g_string_append(ctx
->tsdl
, "\\t");
86 g_string_append(ctx
->tsdl
, "\\v");
89 g_string_append_printf(ctx
->tsdl
, "\\x%02x",
93 } else if (*ch
== '"' || *ch
== '\\') {
94 g_string_append_c(ctx
->tsdl
, '\\');
95 g_string_append_c(ctx
->tsdl
, *ch
);
97 g_string_append_c(ctx
->tsdl
, *ch
);
103 void append_quoted_string(struct ctx
*ctx
, const char *str
)
105 g_string_append_c(ctx
->tsdl
, '"');
106 append_quoted_string_content(ctx
, str
);
107 g_string_append_c(ctx
->tsdl
, '"');
111 void append_integer_field_class_from_props(struct ctx
*ctx
, unsigned int size
,
112 unsigned int alignment
, bool is_signed
,
113 bt_field_class_integer_preferred_display_base disp_base
,
114 const char *mapped_clock_class_name
, const char *field_name
,
117 g_string_append_printf(ctx
->tsdl
,
118 "integer { size = %u; align = %u;",
122 g_string_append(ctx
->tsdl
, " signed = true;");
125 if (disp_base
!= BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
) {
126 g_string_append(ctx
->tsdl
, " base = ");
129 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY
:
130 g_string_append(ctx
->tsdl
, "b");
132 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL
:
133 g_string_append(ctx
->tsdl
, "o");
135 case BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
:
136 g_string_append(ctx
->tsdl
, "x");
142 g_string_append_c(ctx
->tsdl
, ';');
145 if (mapped_clock_class_name
) {
146 g_string_append_printf(ctx
->tsdl
, " map = clock.%s.value;",
147 mapped_clock_class_name
);
150 g_string_append(ctx
->tsdl
, " }");
153 g_string_append_printf(ctx
->tsdl
, " %s", field_name
);
157 g_string_append(ctx
->tsdl
, ";\n");
162 void append_end_block(struct ctx
*ctx
)
166 g_string_append(ctx
->tsdl
, "}");
170 void append_end_block_semi_nl(struct ctx
*ctx
)
174 g_string_append(ctx
->tsdl
, "};\n");
178 void append_end_block_semi_nl_nl(struct ctx
*ctx
)
180 append_end_block_semi_nl(ctx
);
181 g_string_append_c(ctx
->tsdl
, '\n');
185 void append_integer_field_class(struct ctx
*ctx
,
186 struct fs_sink_ctf_field_class_int
*fc
)
188 const bt_field_class
*ir_fc
= fc
->base
.base
.ir_fc
;
189 bt_field_class_type type
= bt_field_class_get_type(ir_fc
);
190 bool is_signed
= type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
||
191 type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
;
193 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
194 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
195 g_string_append(ctx
->tsdl
, "enum : ");
198 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
199 fc
->base
.base
.alignment
, is_signed
,
200 bt_field_class_integer_get_preferred_display_base(ir_fc
),
203 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
204 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
207 g_string_append(ctx
->tsdl
, " {\n");
210 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_fc
); i
++) {
212 const bt_field_class_enumeration_mapping
*mapping
;
213 const bt_field_class_unsigned_enumeration_mapping
*u_mapping
;
214 const bt_field_class_signed_enumeration_mapping
*i_mapping
;
215 uint64_t range_count
;
219 i_mapping
= bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
221 mapping
= bt_field_class_signed_enumeration_mapping_as_mapping_const(
224 u_mapping
= bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
226 mapping
= bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
230 label
= bt_field_class_enumeration_mapping_get_label(
233 bt_field_class_enumeration_mapping_get_range_count(
236 for (range_i
= 0; range_i
< range_count
; range_i
++) {
240 * Systematically prepend `_` to the
241 * mapping's label as this could be used
242 * as the tag of a subsequent variant
243 * field class and variant FC option
244 * names are systematically protected
245 * with a leading `_`.
247 * FIXME: This is temporary as the
248 * library's API should change to
249 * decouple variant FC option names from
250 * selector FC labels. The current
251 * drawback is that an original label
252 * `HELLO` becomes `_HELLO` in the
253 * generated metadata, therefore tools
254 * expecting `HELLO` could fail.
256 g_string_append(ctx
->tsdl
, "\"_");
257 append_quoted_string_content(ctx
, label
);
258 g_string_append(ctx
->tsdl
, "\" = ");
261 int64_t lower
, upper
;
263 bt_field_class_signed_enumeration_mapping_get_range_by_index(
267 if (lower
== upper
) {
268 g_string_append_printf(
269 ctx
->tsdl
, "%" PRId64
,
272 g_string_append_printf(
273 ctx
->tsdl
, "%" PRId64
" ... %" PRId64
,
277 uint64_t lower
, upper
;
279 bt_field_class_unsigned_enumeration_mapping_get_range_by_index(
283 if (lower
== upper
) {
284 g_string_append_printf(
285 ctx
->tsdl
, "%" PRIu64
,
288 g_string_append_printf(
289 ctx
->tsdl
, "%" PRIu64
" ... %" PRIu64
,
294 g_string_append(ctx
->tsdl
, ",\n");
298 append_end_block(ctx
);
303 void append_float_field_class(struct ctx
*ctx
,
304 struct fs_sink_ctf_field_class_float
*fc
)
306 unsigned int mant_dig
, exp_dig
;
308 if (bt_field_class_real_is_single_precision(fc
->base
.base
.ir_fc
)) {
316 g_string_append_printf(ctx
->tsdl
,
317 "floating_point { mant_dig = %u; exp_dig = %u; align = %u; }",
318 mant_dig
, exp_dig
, fc
->base
.base
.alignment
);
322 void append_string_field_class(struct ctx
*ctx
,
323 struct fs_sink_ctf_field_class_float
*fc
)
325 g_string_append(ctx
->tsdl
, "string { encoding = UTF8; }");
329 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
);
332 void append_member(struct ctx
*ctx
, const char *name
,
333 struct fs_sink_ctf_field_class
*fc
)
335 GString
*lengths
= NULL
;
336 const char *lengths_str
= "";
338 while (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
||
339 fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
341 lengths
= g_string_new(NULL
);
345 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
) {
346 struct fs_sink_ctf_field_class_array
*array_fc
=
349 g_string_append_printf(lengths
, "[%" PRIu64
"]",
351 fc
= array_fc
->base
.elem_fc
;
353 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
356 g_string_append_printf(lengths
, "[%s]",
357 seq_fc
->length_ref
->str
);
358 fc
= seq_fc
->base
.elem_fc
;
362 append_field_class(ctx
, fc
);
365 lengths_str
= lengths
->str
;
368 g_string_append_printf(ctx
->tsdl
, " %s%s;\n", name
, lengths_str
);
371 g_string_free(lengths
, TRUE
);
376 void append_struct_field_class_members(struct ctx
*ctx
,
377 struct fs_sink_ctf_field_class_struct
*struct_fc
)
381 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
382 struct fs_sink_ctf_named_field_class
*named_fc
=
383 fs_sink_ctf_field_class_struct_borrow_member_by_index(
385 struct fs_sink_ctf_field_class
*fc
= named_fc
->fc
;
387 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
388 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
391 if (seq_fc
->length_is_before
) {
393 append_integer_field_class_from_props(ctx
,
395 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
396 NULL
, seq_fc
->length_ref
->str
, true);
398 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
) {
399 struct fs_sink_ctf_field_class_variant
*var_fc
=
402 if (var_fc
->tag_is_before
) {
404 g_string_append(ctx
->tsdl
, "enum : ");
405 append_integer_field_class_from_props(ctx
,
407 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
409 g_string_append(ctx
->tsdl
, " {\n");
412 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
413 struct fs_sink_ctf_named_field_class
*named_fc
=
414 fs_sink_ctf_field_class_variant_borrow_option_by_index(
418 g_string_append_printf(ctx
->tsdl
,
419 "\"%s\" = %" PRIu64
",\n",
420 named_fc
->name
->str
, i
);
423 append_end_block(ctx
);
424 g_string_append_printf(ctx
->tsdl
, " %s;\n",
425 var_fc
->tag_ref
->str
);
430 append_member(ctx
, named_fc
->name
->str
, fc
);
435 void append_struct_field_class(struct ctx
*ctx
,
436 struct fs_sink_ctf_field_class_struct
*fc
)
438 g_string_append(ctx
->tsdl
, "struct {\n");
440 append_struct_field_class_members(ctx
, fc
);
441 append_end_block(ctx
);
442 g_string_append_printf(ctx
->tsdl
, " align(%u)",
447 void append_variant_field_class(struct ctx
*ctx
,
448 struct fs_sink_ctf_field_class_variant
*var_fc
)
452 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
453 var_fc
->tag_ref
->str
);
456 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
457 struct fs_sink_ctf_named_field_class
*named_fc
=
458 fs_sink_ctf_field_class_variant_borrow_option_by_index(
462 append_member(ctx
, named_fc
->name
->str
, named_fc
->fc
);
465 append_end_block(ctx
);
469 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
)
472 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
473 append_integer_field_class(ctx
, (void *) fc
);
475 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
476 append_float_field_class(ctx
, (void *) fc
);
478 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
479 append_string_field_class(ctx
, (void *) fc
);
481 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
482 append_struct_field_class(ctx
, (void *) fc
);
484 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
485 append_variant_field_class(ctx
, (void *) fc
);
493 void append_event_class(struct ctx
*ctx
, struct fs_sink_ctf_event_class
*ec
)
496 bt_event_class_log_level log_level
;
500 g_string_append(ctx
->tsdl
, "event {\n");
503 /* Event class properties */
505 g_string_append(ctx
->tsdl
, "name = ");
506 str
= bt_event_class_get_name(ec
->ir_ec
);
511 append_quoted_string(ctx
, str
);
512 g_string_append(ctx
->tsdl
, ";\n");
514 g_string_append_printf(ctx
->tsdl
, "stream_id = %" PRIu64
";\n",
515 bt_stream_class_get_id(ec
->sc
->ir_sc
));
517 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
518 bt_event_class_get_id(ec
->ir_ec
));
520 str
= bt_event_class_get_emf_uri(ec
->ir_ec
);
523 g_string_append(ctx
->tsdl
, "model.emf.uri = ");
524 append_quoted_string(ctx
, str
);
525 g_string_append(ctx
->tsdl
, ";\n");
528 if (bt_event_class_get_log_level(ec
->ir_ec
, &log_level
) ==
529 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
533 g_string_append(ctx
->tsdl
, "loglevel = ");
536 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
539 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
542 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
545 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
548 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
551 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
554 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
557 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
560 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
563 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
566 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
569 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
572 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
575 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
578 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
585 g_string_append_printf(ctx
->tsdl
, "%u;\n", level
);
588 /* Event specific context field class */
589 if (ec
->spec_context_fc
) {
591 g_string_append(ctx
->tsdl
, "context := ");
592 append_field_class(ctx
, ec
->spec_context_fc
);
593 g_string_append(ctx
->tsdl
, ";\n");
596 /* Event payload field class */
597 if (ec
->payload_fc
) {
599 g_string_append(ctx
->tsdl
, "fields := ");
600 append_field_class(ctx
, ec
->payload_fc
);
601 g_string_append(ctx
->tsdl
, ";\n");
604 append_end_block_semi_nl_nl(ctx
);
608 void append_stream_class(struct ctx
*ctx
,
609 struct fs_sink_ctf_stream_class
*sc
)
613 /* Default clock class */
614 if (sc
->default_clock_class
) {
616 int64_t offset_seconds
;
617 uint64_t offset_cycles
;
621 g_string_append(ctx
->tsdl
, "clock {\n");
623 BT_ASSERT(sc
->default_clock_class_name
->len
> 0);
625 g_string_append_printf(ctx
->tsdl
, "name = %s;\n",
626 sc
->default_clock_class_name
->str
);
627 descr
= bt_clock_class_get_description(sc
->default_clock_class
);
630 g_string_append(ctx
->tsdl
, "description = ");
631 append_quoted_string(ctx
, descr
);
632 g_string_append(ctx
->tsdl
, ";\n");
636 g_string_append_printf(ctx
->tsdl
, "freq = %" PRIu64
";\n",
637 bt_clock_class_get_frequency(sc
->default_clock_class
));
639 g_string_append_printf(ctx
->tsdl
, "precision = %" PRIu64
";\n",
640 bt_clock_class_get_precision(sc
->default_clock_class
));
641 bt_clock_class_get_offset(sc
->default_clock_class
,
642 &offset_seconds
, &offset_cycles
);
644 g_string_append_printf(ctx
->tsdl
, "offset_s = %" PRId64
";\n",
647 g_string_append_printf(ctx
->tsdl
, "offset = %" PRIu64
";\n",
650 g_string_append(ctx
->tsdl
, "absolute = ");
652 if (bt_clock_class_origin_is_unix_epoch(
653 sc
->default_clock_class
)) {
654 g_string_append(ctx
->tsdl
, "true");
656 g_string_append(ctx
->tsdl
, "false");
659 g_string_append(ctx
->tsdl
, ";\n");
660 uuid
= bt_clock_class_get_uuid(sc
->default_clock_class
);
663 g_string_append(ctx
->tsdl
, "uuid = ");
664 append_uuid(ctx
, uuid
);
665 g_string_append(ctx
->tsdl
, ";\n");
668 /* End clock class */
669 append_end_block_semi_nl_nl(ctx
);
674 g_string_append(ctx
->tsdl
, "stream {\n");
677 /* Stream class properties */
679 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
680 bt_stream_class_get_id(sc
->ir_sc
));
682 /* Packet context field class */
684 g_string_append(ctx
->tsdl
, "packet.context := struct {\n");
687 append_integer_field_class_from_props(ctx
, 64, 8, false,
688 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
689 NULL
, "packet_size", true);
691 append_integer_field_class_from_props(ctx
, 64, 8, false,
692 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
693 NULL
, "content_size", true);
695 if (sc
->packets_have_ts_begin
) {
697 append_integer_field_class_from_props(ctx
, 64, 8, false,
698 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
699 sc
->default_clock_class_name
->str
,
700 "timestamp_begin", true);
703 if (sc
->packets_have_ts_end
) {
705 append_integer_field_class_from_props(ctx
, 64, 8, false,
706 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
707 sc
->default_clock_class_name
->str
,
708 "timestamp_end", true);
711 if (sc
->has_discarded_events
) {
713 append_integer_field_class_from_props(ctx
, 64, 8, false,
714 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
715 NULL
, "events_discarded", true);
719 * Unconditionnally write the packet sequence number as, even if
720 * there's no possible discarded packets message, it's still
721 * useful information to have.
724 append_integer_field_class_from_props(ctx
, 64, 8, false,
725 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
726 NULL
, "packet_seq_num", true);
728 if (sc
->packet_context_fc
) {
729 append_struct_field_class_members(ctx
,
730 (void *) sc
->packet_context_fc
);
731 fs_sink_ctf_field_class_struct_align_at_least(
732 (void *) sc
->packet_context_fc
, 8);
735 /* End packet context field class */
736 append_end_block(ctx
);
737 g_string_append_printf(ctx
->tsdl
, " align(%u);\n\n",
738 sc
->packet_context_fc
? sc
->packet_context_fc
->alignment
: 8);
740 /* Event header field class */
742 g_string_append(ctx
->tsdl
, "event.header := struct {\n");
745 append_integer_field_class_from_props(ctx
, 64, 8, false,
746 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
749 if (sc
->default_clock_class
) {
751 append_integer_field_class_from_props(ctx
, 64, 8, false,
752 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
753 sc
->default_clock_class_name
->str
,
757 /* End event header field class */
758 append_end_block(ctx
);
759 g_string_append(ctx
->tsdl
, " align(8);\n");
761 /* Event common context field class */
762 if (sc
->event_common_context_fc
) {
764 g_string_append(ctx
->tsdl
, "event.context := ");
765 append_field_class(ctx
,
766 (void *) sc
->event_common_context_fc
);
767 g_string_append(ctx
->tsdl
, ";\n");
770 /* End stream class */
771 append_end_block_semi_nl_nl(ctx
);
774 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
775 append_event_class(ctx
, sc
->event_classes
->pdata
[i
]);
780 void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace
*trace
,
790 g_string_assign(tsdl
, "/* CTF 1.8 */\n\n");
791 g_string_append(tsdl
, "/* This was generated by a Babeltrace `sink.ctf.fs` component. */\n\n");
795 g_string_append(tsdl
, "trace {\n");
798 /* Trace class properties */
800 g_string_append(tsdl
, "major = 1;\n");
802 g_string_append(tsdl
, "minor = 8;\n");
804 g_string_append(tsdl
, "uuid = ");
805 append_uuid(&ctx
, trace
->uuid
);
806 g_string_append(tsdl
, ";\n");
808 g_string_append(tsdl
, "byte_order = ");
810 if (BYTE_ORDER
== LITTLE_ENDIAN
) {
811 g_string_append(tsdl
, "le");
813 g_string_append(tsdl
, "be");
816 g_string_append(tsdl
, ";\n");
818 /* Packet header field class */
820 g_string_append(tsdl
, "packet.header := struct {\n");
823 append_integer_field_class_from_props(&ctx
, 32, 8, false,
824 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
825 NULL
, "magic", true);
827 append_integer_field_class_from_props(&ctx
, 8, 8, false,
828 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
829 NULL
, "uuid[16]", true);
831 append_integer_field_class_from_props(&ctx
, 64, 8, false,
832 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
833 NULL
, "stream_id", true);
835 append_integer_field_class_from_props(&ctx
, 64, 8, false,
836 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
837 NULL
, "stream_instance_id", true);
839 /* End packet header field class */
840 append_end_block(&ctx
);
841 g_string_append(ctx
.tsdl
, " align(8);\n");
843 /* End trace class */
844 append_end_block_semi_nl_nl(&ctx
);
846 /* Trace environment */
847 count
= bt_trace_get_environment_entry_count(trace
->ir_trace
);
850 g_string_append(tsdl
, "env {\n");
853 for (i
= 0; i
< count
; i
++) {
857 bt_trace_borrow_environment_entry_by_index_const(
858 trace
->ir_trace
, i
, &name
, &val
);
860 g_string_append_printf(tsdl
, "%s = ", name
);
862 switch (bt_value_get_type(val
)) {
863 case BT_VALUE_TYPE_SIGNED_INTEGER
:
864 g_string_append_printf(tsdl
, "%" PRId64
,
865 bt_value_signed_integer_get(val
));
867 case BT_VALUE_TYPE_STRING
:
868 append_quoted_string(&ctx
, bt_value_string_get(val
));
873 * translate_trace_trace_ir_to_ctf_ir().
878 g_string_append(tsdl
, ";\n");
881 /* End trace class environment */
882 append_end_block_semi_nl_nl(&ctx
);
885 /* Stream classes and their event classes */
886 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
887 append_stream_class(&ctx
, trace
->stream_classes
->pdata
[i
]);