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
= bt_field_class_type_is(type
,
220 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
);
222 if (bt_field_class_type_is(type
, BT_FIELD_CLASS_TYPE_ENUMERATION
)) {
223 g_string_append(ctx
->tsdl
, "enum : ");
226 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
227 fc
->base
.base
.alignment
, is_signed
,
228 bt_field_class_integer_get_preferred_display_base(ir_fc
),
231 if (bt_field_class_type_is(type
, BT_FIELD_CLASS_TYPE_ENUMERATION
)) {
234 g_string_append(ctx
->tsdl
, " {\n");
237 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_fc
); i
++) {
239 const bt_field_class_enumeration_mapping
*mapping
;
240 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
241 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
242 const bt_integer_range_set
*ranges
;
243 const bt_integer_range_set_unsigned
*u_ranges
;
244 const bt_integer_range_set_signed
*s_ranges
;
245 uint64_t range_count
;
249 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
251 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
253 s_ranges
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
255 ranges
= bt_integer_range_set_signed_as_range_set_const(
258 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
260 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
262 u_ranges
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
264 ranges
= bt_integer_range_set_unsigned_as_range_set_const(
268 label
= bt_field_class_enumeration_mapping_get_label(
270 range_count
= bt_integer_range_set_get_range_count(
273 for (range_i
= 0; range_i
< range_count
; range_i
++) {
275 g_string_append(ctx
->tsdl
, "\"");
276 append_quoted_string_content(ctx
, label
);
277 g_string_append(ctx
->tsdl
, "\" = ");
280 const bt_integer_range_signed
*range
;
281 int64_t lower
, upper
;
283 range
= bt_integer_range_set_signed_borrow_range_by_index_const(
285 lower
= bt_integer_range_signed_get_lower(
287 upper
= bt_integer_range_signed_get_upper(
290 if (lower
== upper
) {
291 g_string_append_printf(
292 ctx
->tsdl
, "%" PRId64
,
295 g_string_append_printf(
296 ctx
->tsdl
, "%" PRId64
" ... %" PRId64
,
300 const bt_integer_range_unsigned
*range
;
301 uint64_t lower
, upper
;
303 range
= bt_integer_range_set_unsigned_borrow_range_by_index_const(
305 lower
= bt_integer_range_unsigned_get_lower(
307 upper
= bt_integer_range_unsigned_get_upper(
310 if (lower
== upper
) {
311 g_string_append_printf(
312 ctx
->tsdl
, "%" PRIu64
,
315 g_string_append_printf(
316 ctx
->tsdl
, "%" PRIu64
" ... %" PRIu64
,
321 g_string_append(ctx
->tsdl
, ",\n");
325 append_end_block(ctx
);
330 void append_float_field_class(struct ctx
*ctx
,
331 struct fs_sink_ctf_field_class_float
*fc
)
333 unsigned int mant_dig
, exp_dig
;
335 if (bt_field_class_get_type(fc
->base
.base
.ir_fc
) ==
336 BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
) {
344 g_string_append_printf(ctx
->tsdl
,
345 "floating_point { mant_dig = %u; exp_dig = %u; align = %u; }",
346 mant_dig
, exp_dig
, fc
->base
.base
.alignment
);
350 void append_string_field_class(struct ctx
*ctx
,
351 struct fs_sink_ctf_field_class_float
*fc
)
353 g_string_append(ctx
->tsdl
, "string { encoding = UTF8; }");
357 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
);
360 void append_member(struct ctx
*ctx
, const char *name
,
361 struct fs_sink_ctf_field_class
*fc
)
363 GString
*lengths
= NULL
;
364 const char *lengths_str
= "";
368 while (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
||
369 fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
371 lengths
= g_string_new(NULL
);
375 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
) {
376 struct fs_sink_ctf_field_class_array
*array_fc
=
379 g_string_append_printf(lengths
, "[%" PRIu64
"]",
381 fc
= array_fc
->base
.elem_fc
;
383 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
386 g_string_append_printf(lengths
, "[%s]",
387 seq_fc
->length_ref
->str
);
388 fc
= seq_fc
->base
.elem_fc
;
392 append_field_class(ctx
, fc
);
395 lengths_str
= lengths
->str
;
398 g_string_append_printf(ctx
->tsdl
, " %s%s;\n", name
, lengths_str
);
401 g_string_free(lengths
, TRUE
);
406 void append_struct_field_class_members(struct ctx
*ctx
,
407 struct fs_sink_ctf_field_class_struct
*struct_fc
)
411 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
412 struct fs_sink_ctf_named_field_class
*named_fc
=
413 fs_sink_ctf_field_class_struct_borrow_member_by_index(
415 struct fs_sink_ctf_field_class
*fc
= named_fc
->fc
;
418 * For sequence, option, and variant field classes, if
419 * the length/tag field class is generated before, write
420 * it now before the dependent field class.
422 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
423 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
426 if (seq_fc
->length_is_before
) {
428 append_integer_field_class_from_props(ctx
,
430 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
431 NULL
, seq_fc
->length_ref
->str
, true);
433 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
) {
434 struct fs_sink_ctf_field_class_option
*opt_fc
=
438 * CTF 1.8 does not support the option field
439 * class type. To write something anyway, this
440 * component translates this type to a variant
441 * field class where the options are:
443 * * An empty structure field class.
444 * * The optional field class itself.
446 * The "tag" is always generated/before in that
447 * case (an 8-bit unsigned enumeration field
451 g_string_append(ctx
->tsdl
,
452 "/* The enumeration and variant field classes "
453 "below were a trace IR option field class. */\n");
455 g_string_append(ctx
->tsdl
, "enum : ");
456 append_integer_field_class_from_props(ctx
,
458 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
460 g_string_append(ctx
->tsdl
, " {\n");
463 g_string_append(ctx
->tsdl
, "none = 0,\n");
465 g_string_append(ctx
->tsdl
, "content = 1,\n");
466 append_end_block(ctx
);
467 g_string_append_printf(ctx
->tsdl
, " %s;\n",
468 opt_fc
->tag_ref
->str
);
469 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
) {
470 struct fs_sink_ctf_field_class_variant
*var_fc
=
473 if (var_fc
->tag_is_before
) {
475 g_string_append(ctx
->tsdl
, "enum : ");
476 append_integer_field_class_from_props(ctx
,
478 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
480 g_string_append(ctx
->tsdl
, " {\n");
483 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
484 struct fs_sink_ctf_named_field_class
*option_named_fc
=
485 fs_sink_ctf_field_class_variant_borrow_option_by_index(
489 g_string_append_printf(ctx
->tsdl
,
490 "\"%s\" = %" PRIu64
",\n",
491 option_named_fc
->name
->str
, i
);
494 append_end_block(ctx
);
495 g_string_append_printf(ctx
->tsdl
, " %s;\n",
496 var_fc
->tag_ref
->str
);
498 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
) {
500 g_string_append(ctx
->tsdl
,
501 "/* The integer field class below was a trace IR boolean field class. */\n");
502 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
) {
504 g_string_append(ctx
->tsdl
,
505 "/* The integer field class below was a trace IR bit array field class. */\n");
509 append_member(ctx
, named_fc
->name
->str
, fc
);
514 void append_struct_field_class(struct ctx
*ctx
,
515 struct fs_sink_ctf_field_class_struct
*fc
)
517 g_string_append(ctx
->tsdl
, "struct {\n");
519 append_struct_field_class_members(ctx
, fc
);
520 append_end_block(ctx
);
521 g_string_append_printf(ctx
->tsdl
, " align(%u)",
526 void append_option_field_class(struct ctx
*ctx
,
527 struct fs_sink_ctf_field_class_option
*opt_fc
)
529 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
530 opt_fc
->tag_ref
->str
);
533 g_string_append(ctx
->tsdl
, "struct { } none;\n");
535 append_member(ctx
, "content", opt_fc
->content_fc
);
536 append_end_block(ctx
);
540 void append_variant_field_class(struct ctx
*ctx
,
541 struct fs_sink_ctf_field_class_variant
*var_fc
)
545 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
546 var_fc
->tag_ref
->str
);
549 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
550 struct fs_sink_ctf_named_field_class
*named_fc
=
551 fs_sink_ctf_field_class_variant_borrow_option_by_index(
555 append_member(ctx
, named_fc
->name
->str
, named_fc
->fc
);
558 append_end_block(ctx
);
562 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
)
565 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
:
566 append_bool_field_class(ctx
, (void *) fc
);
568 case FS_SINK_CTF_FIELD_CLASS_TYPE_BIT_ARRAY
:
569 append_bit_array_field_class(ctx
, (void *) fc
);
571 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
572 append_integer_field_class(ctx
, (void *) fc
);
574 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
575 append_float_field_class(ctx
, (void *) fc
);
577 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
578 append_string_field_class(ctx
, (void *) fc
);
580 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
581 append_struct_field_class(ctx
, (void *) fc
);
583 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
584 append_option_field_class(ctx
, (void *) fc
);
586 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
587 append_variant_field_class(ctx
, (void *) fc
);
595 void append_event_class(struct ctx
*ctx
, struct fs_sink_ctf_event_class
*ec
)
598 bt_event_class_log_level log_level
;
602 g_string_append(ctx
->tsdl
, "event {\n");
605 /* Event class properties */
607 g_string_append(ctx
->tsdl
, "name = ");
608 str
= bt_event_class_get_name(ec
->ir_ec
);
613 append_quoted_string(ctx
, str
);
614 g_string_append(ctx
->tsdl
, ";\n");
616 g_string_append_printf(ctx
->tsdl
, "stream_id = %" PRIu64
";\n",
617 bt_stream_class_get_id(ec
->sc
->ir_sc
));
619 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
620 bt_event_class_get_id(ec
->ir_ec
));
622 str
= bt_event_class_get_emf_uri(ec
->ir_ec
);
625 g_string_append(ctx
->tsdl
, "model.emf.uri = ");
626 append_quoted_string(ctx
, str
);
627 g_string_append(ctx
->tsdl
, ";\n");
630 if (bt_event_class_get_log_level(ec
->ir_ec
, &log_level
) ==
631 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
635 g_string_append(ctx
->tsdl
, "loglevel = ");
638 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
641 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
644 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
647 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
650 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
653 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
656 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
659 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
662 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
665 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
668 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
671 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
674 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
677 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
680 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
687 g_string_append_printf(ctx
->tsdl
, "%u;\n", level
);
690 /* Event specific context field class */
691 if (ec
->spec_context_fc
) {
693 g_string_append(ctx
->tsdl
, "context := ");
694 append_field_class(ctx
, ec
->spec_context_fc
);
695 g_string_append(ctx
->tsdl
, ";\n");
698 /* Event payload field class */
699 if (ec
->payload_fc
) {
701 g_string_append(ctx
->tsdl
, "fields := ");
702 append_field_class(ctx
, ec
->payload_fc
);
703 g_string_append(ctx
->tsdl
, ";\n");
706 append_end_block_semi_nl_nl(ctx
);
710 void append_stream_class(struct ctx
*ctx
,
711 struct fs_sink_ctf_stream_class
*sc
)
715 /* Default clock class */
716 if (sc
->default_clock_class
) {
718 int64_t offset_seconds
;
719 uint64_t offset_cycles
;
723 g_string_append(ctx
->tsdl
, "clock {\n");
725 BT_ASSERT(sc
->default_clock_class_name
->len
> 0);
727 g_string_append_printf(ctx
->tsdl
, "name = %s;\n",
728 sc
->default_clock_class_name
->str
);
729 descr
= bt_clock_class_get_description(sc
->default_clock_class
);
732 g_string_append(ctx
->tsdl
, "description = ");
733 append_quoted_string(ctx
, descr
);
734 g_string_append(ctx
->tsdl
, ";\n");
738 g_string_append_printf(ctx
->tsdl
, "freq = %" PRIu64
";\n",
739 bt_clock_class_get_frequency(sc
->default_clock_class
));
741 g_string_append_printf(ctx
->tsdl
, "precision = %" PRIu64
";\n",
742 bt_clock_class_get_precision(sc
->default_clock_class
));
743 bt_clock_class_get_offset(sc
->default_clock_class
,
744 &offset_seconds
, &offset_cycles
);
746 g_string_append_printf(ctx
->tsdl
, "offset_s = %" PRId64
";\n",
749 g_string_append_printf(ctx
->tsdl
, "offset = %" PRIu64
";\n",
752 g_string_append(ctx
->tsdl
, "absolute = ");
754 if (bt_clock_class_origin_is_unix_epoch(
755 sc
->default_clock_class
)) {
756 g_string_append(ctx
->tsdl
, "true");
758 g_string_append(ctx
->tsdl
, "false");
761 g_string_append(ctx
->tsdl
, ";\n");
762 uuid
= bt_clock_class_get_uuid(sc
->default_clock_class
);
765 g_string_append(ctx
->tsdl
, "uuid = ");
766 append_uuid(ctx
, uuid
);
767 g_string_append(ctx
->tsdl
, ";\n");
770 /* End clock class */
771 append_end_block_semi_nl_nl(ctx
);
776 g_string_append(ctx
->tsdl
, "stream {\n");
779 /* Stream class properties */
781 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
782 bt_stream_class_get_id(sc
->ir_sc
));
784 /* Packet context field class */
786 g_string_append(ctx
->tsdl
, "packet.context := struct {\n");
789 append_integer_field_class_from_props(ctx
, 64, 8, false,
790 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
791 NULL
, "packet_size", true);
793 append_integer_field_class_from_props(ctx
, 64, 8, false,
794 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
795 NULL
, "content_size", true);
797 if (sc
->packets_have_ts_begin
) {
799 append_integer_field_class_from_props(ctx
, 64, 8, false,
800 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
801 sc
->default_clock_class_name
->str
,
802 "timestamp_begin", true);
805 if (sc
->packets_have_ts_end
) {
807 append_integer_field_class_from_props(ctx
, 64, 8, false,
808 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
809 sc
->default_clock_class_name
->str
,
810 "timestamp_end", true);
813 if (sc
->has_discarded_events
) {
815 append_integer_field_class_from_props(ctx
, 64, 8, false,
816 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
817 NULL
, "events_discarded", true);
821 * Unconditionnally write the packet sequence number as, even if
822 * there's no possible discarded packets message, it's still
823 * useful information to have.
826 append_integer_field_class_from_props(ctx
, 64, 8, false,
827 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
828 NULL
, "packet_seq_num", true);
830 if (sc
->packet_context_fc
) {
831 append_struct_field_class_members(ctx
,
832 (void *) sc
->packet_context_fc
);
833 fs_sink_ctf_field_class_struct_align_at_least(
834 (void *) sc
->packet_context_fc
, 8);
837 /* End packet context field class */
838 append_end_block(ctx
);
839 g_string_append_printf(ctx
->tsdl
, " align(%u);\n\n",
840 sc
->packet_context_fc
? sc
->packet_context_fc
->alignment
: 8);
842 /* Event header field class */
844 g_string_append(ctx
->tsdl
, "event.header := struct {\n");
847 append_integer_field_class_from_props(ctx
, 64, 8, false,
848 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
851 if (sc
->default_clock_class
) {
853 append_integer_field_class_from_props(ctx
, 64, 8, false,
854 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
855 sc
->default_clock_class_name
->str
,
859 /* End event header field class */
860 append_end_block(ctx
);
861 g_string_append(ctx
->tsdl
, " align(8);\n");
863 /* Event common context field class */
864 if (sc
->event_common_context_fc
) {
866 g_string_append(ctx
->tsdl
, "event.context := ");
867 append_field_class(ctx
,
868 (void *) sc
->event_common_context_fc
);
869 g_string_append(ctx
->tsdl
, ";\n");
872 /* End stream class */
873 append_end_block_semi_nl_nl(ctx
);
876 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
877 append_event_class(ctx
, sc
->event_classes
->pdata
[i
]);
882 void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace
*trace
,
892 g_string_assign(tsdl
, "/* CTF 1.8 */\n\n");
893 g_string_append(tsdl
, "/* This was generated by a Babeltrace `sink.ctf.fs` component. */\n\n");
897 g_string_append(tsdl
, "trace {\n");
900 /* Trace class properties */
902 g_string_append(tsdl
, "major = 1;\n");
904 g_string_append(tsdl
, "minor = 8;\n");
906 g_string_append(tsdl
, "uuid = ");
907 append_uuid(&ctx
, trace
->uuid
);
908 g_string_append(tsdl
, ";\n");
910 g_string_append(tsdl
, "byte_order = ");
912 if (BYTE_ORDER
== LITTLE_ENDIAN
) {
913 g_string_append(tsdl
, "le");
915 g_string_append(tsdl
, "be");
918 g_string_append(tsdl
, ";\n");
920 /* Packet header field class */
922 g_string_append(tsdl
, "packet.header := struct {\n");
925 append_integer_field_class_from_props(&ctx
, 32, 8, false,
926 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
927 NULL
, "magic", true);
929 append_integer_field_class_from_props(&ctx
, 8, 8, false,
930 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
931 NULL
, "uuid[16]", true);
933 append_integer_field_class_from_props(&ctx
, 64, 8, false,
934 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
935 NULL
, "stream_id", true);
937 append_integer_field_class_from_props(&ctx
, 64, 8, false,
938 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
939 NULL
, "stream_instance_id", true);
941 /* End packet header field class */
942 append_end_block(&ctx
);
943 g_string_append(ctx
.tsdl
, " align(8);\n");
945 /* End trace class */
946 append_end_block_semi_nl_nl(&ctx
);
948 /* Trace environment */
949 count
= bt_trace_get_environment_entry_count(trace
->ir_trace
);
952 g_string_append(tsdl
, "env {\n");
955 for (i
= 0; i
< count
; i
++) {
959 bt_trace_borrow_environment_entry_by_index_const(
960 trace
->ir_trace
, i
, &name
, &val
);
962 g_string_append_printf(tsdl
, "%s = ", name
);
964 switch (bt_value_get_type(val
)) {
965 case BT_VALUE_TYPE_SIGNED_INTEGER
:
966 g_string_append_printf(tsdl
, "%" PRId64
,
967 bt_value_integer_signed_get(val
));
969 case BT_VALUE_TYPE_STRING
:
970 append_quoted_string(&ctx
, bt_value_string_get(val
));
975 * translate_trace_trace_ir_to_ctf_ir().
980 g_string_append(tsdl
, ";\n");
983 /* End trace class environment */
984 append_end_block_semi_nl_nl(&ctx
);
987 /* Stream classes and their event classes */
988 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
989 append_stream_class(&ctx
, trace
->stream_classes
->pdata
[i
]);