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_bool_field_class(struct ctx
*ctx
,
186 __attribute__((unused
)) struct fs_sink_ctf_field_class_bool
*fc
)
189 * CTF 1.8 has no boolean field class type, so this component
190 * translates it to an 8-bit unsigned integer field class.
192 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
193 fc
->base
.base
.alignment
, false,
194 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
199 void append_bit_array_field_class(struct ctx
*ctx
,
200 struct fs_sink_ctf_field_class_bit_array
*fc
)
203 * CTF 1.8 has no bit array field class type, so this component
204 * translates it to an unsigned integer field class with an
207 append_integer_field_class_from_props(ctx
, fc
->size
,
208 fc
->base
.alignment
, false,
209 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
214 void append_integer_field_class(struct ctx
*ctx
,
215 struct fs_sink_ctf_field_class_int
*fc
)
217 const bt_field_class
*ir_fc
= fc
->base
.base
.ir_fc
;
218 bt_field_class_type type
= bt_field_class_get_type(ir_fc
);
219 bool is_signed
= type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
||
220 type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
;
222 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
223 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
224 g_string_append(ctx
->tsdl
, "enum : ");
227 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
228 fc
->base
.base
.alignment
, is_signed
,
229 bt_field_class_integer_get_preferred_display_base(ir_fc
),
232 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
233 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
236 g_string_append(ctx
->tsdl
, " {\n");
239 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_fc
); i
++) {
241 const bt_field_class_enumeration_mapping
*mapping
;
242 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
243 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
244 const bt_integer_range_set
*ranges
;
245 const bt_integer_range_set_unsigned
*u_ranges
;
246 const bt_integer_range_set_signed
*s_ranges
;
247 uint64_t range_count
;
251 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
253 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
255 s_ranges
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
257 ranges
= bt_integer_range_set_signed_as_range_set_const(
260 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
262 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
264 u_ranges
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
266 ranges
= bt_integer_range_set_unsigned_as_range_set_const(
270 label
= bt_field_class_enumeration_mapping_get_label(
272 range_count
= bt_integer_range_set_get_range_count(
275 for (range_i
= 0; range_i
< range_count
; range_i
++) {
277 g_string_append(ctx
->tsdl
, "\"");
278 append_quoted_string_content(ctx
, label
);
279 g_string_append(ctx
->tsdl
, "\" = ");
282 const bt_integer_range_signed
*range
;
283 int64_t lower
, upper
;
285 range
= bt_integer_range_set_signed_borrow_range_by_index_const(
287 lower
= bt_integer_range_signed_get_lower(
289 upper
= bt_integer_range_signed_get_upper(
292 if (lower
== upper
) {
293 g_string_append_printf(
294 ctx
->tsdl
, "%" PRId64
,
297 g_string_append_printf(
298 ctx
->tsdl
, "%" PRId64
" ... %" PRId64
,
302 const bt_integer_range_unsigned
*range
;
303 uint64_t lower
, upper
;
305 range
= bt_integer_range_set_unsigned_borrow_range_by_index_const(
307 lower
= bt_integer_range_unsigned_get_lower(
309 upper
= bt_integer_range_unsigned_get_upper(
312 if (lower
== upper
) {
313 g_string_append_printf(
314 ctx
->tsdl
, "%" PRIu64
,
317 g_string_append_printf(
318 ctx
->tsdl
, "%" PRIu64
" ... %" PRIu64
,
323 g_string_append(ctx
->tsdl
, ",\n");
327 append_end_block(ctx
);
332 void append_float_field_class(struct ctx
*ctx
,
333 struct fs_sink_ctf_field_class_float
*fc
)
335 unsigned int mant_dig
, exp_dig
;
337 if (bt_field_class_get_type(fc
->base
.base
.ir_fc
) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
) {
345 g_string_append_printf(ctx
->tsdl
,
346 "floating_point { mant_dig = %u; exp_dig = %u; align = %u; }",
347 mant_dig
, exp_dig
, fc
->base
.base
.alignment
);
351 void append_string_field_class(struct ctx
*ctx
,
352 struct fs_sink_ctf_field_class_float
*fc
)
354 g_string_append(ctx
->tsdl
, "string { encoding = UTF8; }");
358 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
);
361 void append_member(struct ctx
*ctx
, const char *name
,
362 struct fs_sink_ctf_field_class
*fc
)
364 GString
*lengths
= NULL
;
365 const char *lengths_str
= "";
369 while (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
||
370 fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
372 lengths
= g_string_new(NULL
);
376 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
) {
377 struct fs_sink_ctf_field_class_array
*array_fc
=
380 g_string_append_printf(lengths
, "[%" PRIu64
"]",
382 fc
= array_fc
->base
.elem_fc
;
384 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
387 g_string_append_printf(lengths
, "[%s]",
388 seq_fc
->length_ref
->str
);
389 fc
= seq_fc
->base
.elem_fc
;
393 append_field_class(ctx
, fc
);
396 lengths_str
= lengths
->str
;
399 g_string_append_printf(ctx
->tsdl
, " %s%s;\n", name
, lengths_str
);
402 g_string_free(lengths
, TRUE
);
407 void append_struct_field_class_members(struct ctx
*ctx
,
408 struct fs_sink_ctf_field_class_struct
*struct_fc
)
412 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
413 struct fs_sink_ctf_named_field_class
*named_fc
=
414 fs_sink_ctf_field_class_struct_borrow_member_by_index(
416 struct fs_sink_ctf_field_class
*fc
= named_fc
->fc
;
419 * For sequence, option, and variant field classes, if
420 * the length/tag field class is generated before, write
421 * it now before the dependent field class.
423 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
424 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
427 if (seq_fc
->length_is_before
) {
429 append_integer_field_class_from_props(ctx
,
431 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
432 NULL
, seq_fc
->length_ref
->str
, true);
434 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
) {
435 struct fs_sink_ctf_field_class_option
*opt_fc
=
439 * CTF 1.8 does not support the option field
440 * class type. To write something anyway, this
441 * component translates this type to a variant
442 * field class where the options are:
444 * * An empty structure field class.
445 * * The optional field class itself.
447 * The "tag" is always generated/before in that
448 * case (an 8-bit unsigned enumeration field
452 g_string_append(ctx
->tsdl
,
453 "/* The enumeration and variant field classes "
454 "below were a trace IR option field class. */\n");
456 g_string_append(ctx
->tsdl
, "enum : ");
457 append_integer_field_class_from_props(ctx
,
459 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
461 g_string_append(ctx
->tsdl
, " {\n");
464 g_string_append(ctx
->tsdl
, "none = 0,\n");
466 g_string_append(ctx
->tsdl
, "content = 1,\n");
467 append_end_block(ctx
);
468 g_string_append_printf(ctx
->tsdl
, " %s;\n",
469 opt_fc
->tag_ref
->str
);
470 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
) {
471 struct fs_sink_ctf_field_class_variant
*var_fc
=
474 if (var_fc
->tag_is_before
) {
476 g_string_append(ctx
->tsdl
, "enum : ");
477 append_integer_field_class_from_props(ctx
,
479 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
481 g_string_append(ctx
->tsdl
, " {\n");
484 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
485 struct fs_sink_ctf_named_field_class
*named_fc
=
486 fs_sink_ctf_field_class_variant_borrow_option_by_index(
490 g_string_append_printf(ctx
->tsdl
,
491 "\"%s\" = %" PRIu64
",\n",
492 named_fc
->name
->str
, i
);
495 append_end_block(ctx
);
496 g_string_append_printf(ctx
->tsdl
, " %s;\n",
497 var_fc
->tag_ref
->str
);
499 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
) {
501 g_string_append(ctx
->tsdl
,
502 "/* The integer field class below was a trace IR boolean field class. */\n");
503 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
) {
505 g_string_append(ctx
->tsdl
,
506 "/* The integer field class below was a trace IR bit array field class. */\n");
510 append_member(ctx
, named_fc
->name
->str
, fc
);
515 void append_struct_field_class(struct ctx
*ctx
,
516 struct fs_sink_ctf_field_class_struct
*fc
)
518 g_string_append(ctx
->tsdl
, "struct {\n");
520 append_struct_field_class_members(ctx
, fc
);
521 append_end_block(ctx
);
522 g_string_append_printf(ctx
->tsdl
, " align(%u)",
527 void append_option_field_class(struct ctx
*ctx
,
528 struct fs_sink_ctf_field_class_option
*opt_fc
)
530 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
531 opt_fc
->tag_ref
->str
);
534 g_string_append(ctx
->tsdl
, "struct { } none;\n");
536 append_member(ctx
, "content", opt_fc
->content_fc
);
537 append_end_block(ctx
);
541 void append_variant_field_class(struct ctx
*ctx
,
542 struct fs_sink_ctf_field_class_variant
*var_fc
)
546 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
547 var_fc
->tag_ref
->str
);
550 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
551 struct fs_sink_ctf_named_field_class
*named_fc
=
552 fs_sink_ctf_field_class_variant_borrow_option_by_index(
556 append_member(ctx
, named_fc
->name
->str
, named_fc
->fc
);
559 append_end_block(ctx
);
563 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
)
566 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
:
567 append_bool_field_class(ctx
, (void *) fc
);
569 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
:
570 append_bit_array_field_class(ctx
, (void *) fc
);
572 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
573 append_integer_field_class(ctx
, (void *) fc
);
575 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
576 append_float_field_class(ctx
, (void *) fc
);
578 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
579 append_string_field_class(ctx
, (void *) fc
);
581 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
582 append_struct_field_class(ctx
, (void *) fc
);
584 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
585 append_option_field_class(ctx
, (void *) fc
);
587 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
588 append_variant_field_class(ctx
, (void *) fc
);
596 void append_event_class(struct ctx
*ctx
, struct fs_sink_ctf_event_class
*ec
)
599 bt_event_class_log_level log_level
;
603 g_string_append(ctx
->tsdl
, "event {\n");
606 /* Event class properties */
608 g_string_append(ctx
->tsdl
, "name = ");
609 str
= bt_event_class_get_name(ec
->ir_ec
);
614 append_quoted_string(ctx
, str
);
615 g_string_append(ctx
->tsdl
, ";\n");
617 g_string_append_printf(ctx
->tsdl
, "stream_id = %" PRIu64
";\n",
618 bt_stream_class_get_id(ec
->sc
->ir_sc
));
620 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
621 bt_event_class_get_id(ec
->ir_ec
));
623 str
= bt_event_class_get_emf_uri(ec
->ir_ec
);
626 g_string_append(ctx
->tsdl
, "model.emf.uri = ");
627 append_quoted_string(ctx
, str
);
628 g_string_append(ctx
->tsdl
, ";\n");
631 if (bt_event_class_get_log_level(ec
->ir_ec
, &log_level
) ==
632 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
636 g_string_append(ctx
->tsdl
, "loglevel = ");
639 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
642 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
645 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
648 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
651 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
654 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
657 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
660 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
663 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
666 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
669 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
672 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
675 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
678 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
681 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
688 g_string_append_printf(ctx
->tsdl
, "%u;\n", level
);
691 /* Event specific context field class */
692 if (ec
->spec_context_fc
) {
694 g_string_append(ctx
->tsdl
, "context := ");
695 append_field_class(ctx
, ec
->spec_context_fc
);
696 g_string_append(ctx
->tsdl
, ";\n");
699 /* Event payload field class */
700 if (ec
->payload_fc
) {
702 g_string_append(ctx
->tsdl
, "fields := ");
703 append_field_class(ctx
, ec
->payload_fc
);
704 g_string_append(ctx
->tsdl
, ";\n");
707 append_end_block_semi_nl_nl(ctx
);
711 void append_stream_class(struct ctx
*ctx
,
712 struct fs_sink_ctf_stream_class
*sc
)
716 /* Default clock class */
717 if (sc
->default_clock_class
) {
719 int64_t offset_seconds
;
720 uint64_t offset_cycles
;
724 g_string_append(ctx
->tsdl
, "clock {\n");
726 BT_ASSERT(sc
->default_clock_class_name
->len
> 0);
728 g_string_append_printf(ctx
->tsdl
, "name = %s;\n",
729 sc
->default_clock_class_name
->str
);
730 descr
= bt_clock_class_get_description(sc
->default_clock_class
);
733 g_string_append(ctx
->tsdl
, "description = ");
734 append_quoted_string(ctx
, descr
);
735 g_string_append(ctx
->tsdl
, ";\n");
739 g_string_append_printf(ctx
->tsdl
, "freq = %" PRIu64
";\n",
740 bt_clock_class_get_frequency(sc
->default_clock_class
));
742 g_string_append_printf(ctx
->tsdl
, "precision = %" PRIu64
";\n",
743 bt_clock_class_get_precision(sc
->default_clock_class
));
744 bt_clock_class_get_offset(sc
->default_clock_class
,
745 &offset_seconds
, &offset_cycles
);
747 g_string_append_printf(ctx
->tsdl
, "offset_s = %" PRId64
";\n",
750 g_string_append_printf(ctx
->tsdl
, "offset = %" PRIu64
";\n",
753 g_string_append(ctx
->tsdl
, "absolute = ");
755 if (bt_clock_class_origin_is_unix_epoch(
756 sc
->default_clock_class
)) {
757 g_string_append(ctx
->tsdl
, "true");
759 g_string_append(ctx
->tsdl
, "false");
762 g_string_append(ctx
->tsdl
, ";\n");
763 uuid
= bt_clock_class_get_uuid(sc
->default_clock_class
);
766 g_string_append(ctx
->tsdl
, "uuid = ");
767 append_uuid(ctx
, uuid
);
768 g_string_append(ctx
->tsdl
, ";\n");
771 /* End clock class */
772 append_end_block_semi_nl_nl(ctx
);
777 g_string_append(ctx
->tsdl
, "stream {\n");
780 /* Stream class properties */
782 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
783 bt_stream_class_get_id(sc
->ir_sc
));
785 /* Packet context field class */
787 g_string_append(ctx
->tsdl
, "packet.context := struct {\n");
790 append_integer_field_class_from_props(ctx
, 64, 8, false,
791 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
792 NULL
, "packet_size", true);
794 append_integer_field_class_from_props(ctx
, 64, 8, false,
795 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
796 NULL
, "content_size", true);
798 if (sc
->packets_have_ts_begin
) {
800 append_integer_field_class_from_props(ctx
, 64, 8, false,
801 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
802 sc
->default_clock_class_name
->str
,
803 "timestamp_begin", true);
806 if (sc
->packets_have_ts_end
) {
808 append_integer_field_class_from_props(ctx
, 64, 8, false,
809 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
810 sc
->default_clock_class_name
->str
,
811 "timestamp_end", true);
814 if (sc
->has_discarded_events
) {
816 append_integer_field_class_from_props(ctx
, 64, 8, false,
817 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
818 NULL
, "events_discarded", true);
822 * Unconditionnally write the packet sequence number as, even if
823 * there's no possible discarded packets message, it's still
824 * useful information to have.
827 append_integer_field_class_from_props(ctx
, 64, 8, false,
828 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
829 NULL
, "packet_seq_num", true);
831 if (sc
->packet_context_fc
) {
832 append_struct_field_class_members(ctx
,
833 (void *) sc
->packet_context_fc
);
834 fs_sink_ctf_field_class_struct_align_at_least(
835 (void *) sc
->packet_context_fc
, 8);
838 /* End packet context field class */
839 append_end_block(ctx
);
840 g_string_append_printf(ctx
->tsdl
, " align(%u);\n\n",
841 sc
->packet_context_fc
? sc
->packet_context_fc
->alignment
: 8);
843 /* Event header field class */
845 g_string_append(ctx
->tsdl
, "event.header := struct {\n");
848 append_integer_field_class_from_props(ctx
, 64, 8, false,
849 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
852 if (sc
->default_clock_class
) {
854 append_integer_field_class_from_props(ctx
, 64, 8, false,
855 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
856 sc
->default_clock_class_name
->str
,
860 /* End event header field class */
861 append_end_block(ctx
);
862 g_string_append(ctx
->tsdl
, " align(8);\n");
864 /* Event common context field class */
865 if (sc
->event_common_context_fc
) {
867 g_string_append(ctx
->tsdl
, "event.context := ");
868 append_field_class(ctx
,
869 (void *) sc
->event_common_context_fc
);
870 g_string_append(ctx
->tsdl
, ";\n");
873 /* End stream class */
874 append_end_block_semi_nl_nl(ctx
);
877 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
878 append_event_class(ctx
, sc
->event_classes
->pdata
[i
]);
883 void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace
*trace
,
893 g_string_assign(tsdl
, "/* CTF 1.8 */\n\n");
894 g_string_append(tsdl
, "/* This was generated by a Babeltrace `sink.ctf.fs` component. */\n\n");
898 g_string_append(tsdl
, "trace {\n");
901 /* Trace class properties */
903 g_string_append(tsdl
, "major = 1;\n");
905 g_string_append(tsdl
, "minor = 8;\n");
907 g_string_append(tsdl
, "uuid = ");
908 append_uuid(&ctx
, trace
->uuid
);
909 g_string_append(tsdl
, ";\n");
911 g_string_append(tsdl
, "byte_order = ");
913 if (BYTE_ORDER
== LITTLE_ENDIAN
) {
914 g_string_append(tsdl
, "le");
916 g_string_append(tsdl
, "be");
919 g_string_append(tsdl
, ";\n");
921 /* Packet header field class */
923 g_string_append(tsdl
, "packet.header := struct {\n");
926 append_integer_field_class_from_props(&ctx
, 32, 8, false,
927 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
928 NULL
, "magic", true);
930 append_integer_field_class_from_props(&ctx
, 8, 8, false,
931 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
932 NULL
, "uuid[16]", true);
934 append_integer_field_class_from_props(&ctx
, 64, 8, false,
935 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
936 NULL
, "stream_id", true);
938 append_integer_field_class_from_props(&ctx
, 64, 8, false,
939 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
940 NULL
, "stream_instance_id", true);
942 /* End packet header field class */
943 append_end_block(&ctx
);
944 g_string_append(ctx
.tsdl
, " align(8);\n");
946 /* End trace class */
947 append_end_block_semi_nl_nl(&ctx
);
949 /* Trace environment */
950 count
= bt_trace_get_environment_entry_count(trace
->ir_trace
);
953 g_string_append(tsdl
, "env {\n");
956 for (i
= 0; i
< count
; i
++) {
960 bt_trace_borrow_environment_entry_by_index_const(
961 trace
->ir_trace
, i
, &name
, &val
);
963 g_string_append_printf(tsdl
, "%s = ", name
);
965 switch (bt_value_get_type(val
)) {
966 case BT_VALUE_TYPE_SIGNED_INTEGER
:
967 g_string_append_printf(tsdl
, "%" PRId64
,
968 bt_value_integer_signed_get(val
));
970 case BT_VALUE_TYPE_STRING
:
971 append_quoted_string(&ctx
, bt_value_string_get(val
));
976 * translate_trace_trace_ir_to_ctf_ir().
981 g_string_append(tsdl
, ";\n");
984 /* End trace class environment */
985 append_end_block_semi_nl_nl(&ctx
);
988 /* Stream classes and their event classes */
989 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
990 append_stream_class(&ctx
, trace
->stream_classes
->pdata
[i
]);