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_integer_field_class(struct ctx
*ctx
,
200 struct fs_sink_ctf_field_class_int
*fc
)
202 const bt_field_class
*ir_fc
= fc
->base
.base
.ir_fc
;
203 bt_field_class_type type
= bt_field_class_get_type(ir_fc
);
204 bool is_signed
= type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
||
205 type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
;
207 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
208 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
209 g_string_append(ctx
->tsdl
, "enum : ");
212 append_integer_field_class_from_props(ctx
, fc
->base
.size
,
213 fc
->base
.base
.alignment
, is_signed
,
214 bt_field_class_integer_get_preferred_display_base(ir_fc
),
217 if (type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
||
218 type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
221 g_string_append(ctx
->tsdl
, " {\n");
224 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_fc
); i
++) {
226 const bt_field_class_enumeration_mapping
*mapping
;
227 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
228 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
229 const bt_integer_range_set
*ranges
;
230 const bt_integer_range_set_unsigned
*u_ranges
;
231 const bt_integer_range_set_signed
*s_ranges
;
232 uint64_t range_count
;
236 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
238 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
240 s_ranges
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
242 ranges
= bt_integer_range_set_signed_as_range_set_const(
245 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
247 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
249 u_ranges
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
251 ranges
= bt_integer_range_set_unsigned_as_range_set_const(
255 label
= bt_field_class_enumeration_mapping_get_label(
257 range_count
= bt_integer_range_set_get_range_count(
260 for (range_i
= 0; range_i
< range_count
; range_i
++) {
262 g_string_append(ctx
->tsdl
, "\"");
263 append_quoted_string_content(ctx
, label
);
264 g_string_append(ctx
->tsdl
, "\" = ");
267 const bt_integer_range_signed
*range
;
268 int64_t lower
, upper
;
270 range
= bt_integer_range_set_signed_borrow_range_by_index_const(
272 lower
= bt_integer_range_signed_get_lower(
274 upper
= bt_integer_range_signed_get_upper(
277 if (lower
== upper
) {
278 g_string_append_printf(
279 ctx
->tsdl
, "%" PRId64
,
282 g_string_append_printf(
283 ctx
->tsdl
, "%" PRId64
" ... %" PRId64
,
287 const bt_integer_range_unsigned
*range
;
288 uint64_t lower
, upper
;
290 range
= bt_integer_range_set_unsigned_borrow_range_by_index_const(
292 lower
= bt_integer_range_unsigned_get_lower(
294 upper
= bt_integer_range_unsigned_get_upper(
297 if (lower
== upper
) {
298 g_string_append_printf(
299 ctx
->tsdl
, "%" PRIu64
,
302 g_string_append_printf(
303 ctx
->tsdl
, "%" PRIu64
" ... %" PRIu64
,
308 g_string_append(ctx
->tsdl
, ",\n");
312 append_end_block(ctx
);
317 void append_float_field_class(struct ctx
*ctx
,
318 struct fs_sink_ctf_field_class_float
*fc
)
320 unsigned int mant_dig
, exp_dig
;
322 if (bt_field_class_real_is_single_precision(fc
->base
.base
.ir_fc
)) {
330 g_string_append_printf(ctx
->tsdl
,
331 "floating_point { mant_dig = %u; exp_dig = %u; align = %u; }",
332 mant_dig
, exp_dig
, fc
->base
.base
.alignment
);
336 void append_string_field_class(struct ctx
*ctx
,
337 struct fs_sink_ctf_field_class_float
*fc
)
339 g_string_append(ctx
->tsdl
, "string { encoding = UTF8; }");
343 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
);
346 void append_member(struct ctx
*ctx
, const char *name
,
347 struct fs_sink_ctf_field_class
*fc
)
349 GString
*lengths
= NULL
;
350 const char *lengths_str
= "";
354 while (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
||
355 fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
357 lengths
= g_string_new(NULL
);
361 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
) {
362 struct fs_sink_ctf_field_class_array
*array_fc
=
365 g_string_append_printf(lengths
, "[%" PRIu64
"]",
367 fc
= array_fc
->base
.elem_fc
;
369 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
372 g_string_append_printf(lengths
, "[%s]",
373 seq_fc
->length_ref
->str
);
374 fc
= seq_fc
->base
.elem_fc
;
378 append_field_class(ctx
, fc
);
381 lengths_str
= lengths
->str
;
384 g_string_append_printf(ctx
->tsdl
, " %s%s;\n", name
, lengths_str
);
387 g_string_free(lengths
, TRUE
);
392 void append_struct_field_class_members(struct ctx
*ctx
,
393 struct fs_sink_ctf_field_class_struct
*struct_fc
)
397 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
398 struct fs_sink_ctf_named_field_class
*named_fc
=
399 fs_sink_ctf_field_class_struct_borrow_member_by_index(
401 struct fs_sink_ctf_field_class
*fc
= named_fc
->fc
;
404 * For sequence, option, and variant field classes, if
405 * the length/tag field class is generated before, write
406 * it now before the dependent field class.
408 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
409 struct fs_sink_ctf_field_class_sequence
*seq_fc
=
412 if (seq_fc
->length_is_before
) {
414 append_integer_field_class_from_props(ctx
,
416 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
417 NULL
, seq_fc
->length_ref
->str
, true);
419 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
) {
420 struct fs_sink_ctf_field_class_option
*opt_fc
=
424 * CTF 1.8 does not support the option field
425 * class type. To write something anyway, this
426 * component translates this type to a variant
427 * field class where the options are:
429 * * An empty structure field class.
430 * * The optional field class itself.
432 * The "tag" is always generated/before in that
433 * case (an 8-bit unsigned enumeration field
437 g_string_append(ctx
->tsdl
,
438 "/* The enumeration and variant field classes "
439 "below were a trace IR option field class. */\n");
441 g_string_append(ctx
->tsdl
, "enum : ");
442 append_integer_field_class_from_props(ctx
,
444 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
446 g_string_append(ctx
->tsdl
, " {\n");
449 g_string_append(ctx
->tsdl
, "none = 0,\n");
451 g_string_append(ctx
->tsdl
, "content = 1,\n");
452 append_end_block(ctx
);
453 g_string_append_printf(ctx
->tsdl
, " %s;\n",
454 opt_fc
->tag_ref
->str
);
455 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
) {
456 struct fs_sink_ctf_field_class_variant
*var_fc
=
459 if (var_fc
->tag_is_before
) {
461 g_string_append(ctx
->tsdl
, "enum : ");
462 append_integer_field_class_from_props(ctx
,
464 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
466 g_string_append(ctx
->tsdl
, " {\n");
469 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
470 struct fs_sink_ctf_named_field_class
*named_fc
=
471 fs_sink_ctf_field_class_variant_borrow_option_by_index(
475 g_string_append_printf(ctx
->tsdl
,
476 "\"%s\" = %" PRIu64
",\n",
477 named_fc
->name
->str
, i
);
480 append_end_block(ctx
);
481 g_string_append_printf(ctx
->tsdl
, " %s;\n",
482 var_fc
->tag_ref
->str
);
484 } else if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
) {
486 g_string_append(ctx
->tsdl
,
487 "/* The integer field class below was a trace IR boolean field class. */\n");
491 append_member(ctx
, named_fc
->name
->str
, fc
);
496 void append_struct_field_class(struct ctx
*ctx
,
497 struct fs_sink_ctf_field_class_struct
*fc
)
499 g_string_append(ctx
->tsdl
, "struct {\n");
501 append_struct_field_class_members(ctx
, fc
);
502 append_end_block(ctx
);
503 g_string_append_printf(ctx
->tsdl
, " align(%u)",
508 void append_option_field_class(struct ctx
*ctx
,
509 struct fs_sink_ctf_field_class_option
*opt_fc
)
511 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
512 opt_fc
->tag_ref
->str
);
515 g_string_append(ctx
->tsdl
, "struct { } none;\n");
517 append_member(ctx
, "content", opt_fc
->content_fc
);
518 append_end_block(ctx
);
522 void append_variant_field_class(struct ctx
*ctx
,
523 struct fs_sink_ctf_field_class_variant
*var_fc
)
527 g_string_append_printf(ctx
->tsdl
, "variant <%s> {\n",
528 var_fc
->tag_ref
->str
);
531 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
532 struct fs_sink_ctf_named_field_class
*named_fc
=
533 fs_sink_ctf_field_class_variant_borrow_option_by_index(
537 append_member(ctx
, named_fc
->name
->str
, named_fc
->fc
);
540 append_end_block(ctx
);
544 void append_field_class(struct ctx
*ctx
, struct fs_sink_ctf_field_class
*fc
)
547 case FS_SINK_CTF_FIELD_CLASS_TYPE_BOOL
:
548 append_bool_field_class(ctx
, (void *) fc
);
550 case FS_SINK_CTF_FIELD_CLASS_TYPE_INT
:
551 append_integer_field_class(ctx
, (void *) fc
);
553 case FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT
:
554 append_float_field_class(ctx
, (void *) fc
);
556 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRING
:
557 append_string_field_class(ctx
, (void *) fc
);
559 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
560 append_struct_field_class(ctx
, (void *) fc
);
562 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
563 append_option_field_class(ctx
, (void *) fc
);
565 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
566 append_variant_field_class(ctx
, (void *) fc
);
574 void append_event_class(struct ctx
*ctx
, struct fs_sink_ctf_event_class
*ec
)
577 bt_event_class_log_level log_level
;
581 g_string_append(ctx
->tsdl
, "event {\n");
584 /* Event class properties */
586 g_string_append(ctx
->tsdl
, "name = ");
587 str
= bt_event_class_get_name(ec
->ir_ec
);
592 append_quoted_string(ctx
, str
);
593 g_string_append(ctx
->tsdl
, ";\n");
595 g_string_append_printf(ctx
->tsdl
, "stream_id = %" PRIu64
";\n",
596 bt_stream_class_get_id(ec
->sc
->ir_sc
));
598 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
599 bt_event_class_get_id(ec
->ir_ec
));
601 str
= bt_event_class_get_emf_uri(ec
->ir_ec
);
604 g_string_append(ctx
->tsdl
, "model.emf.uri = ");
605 append_quoted_string(ctx
, str
);
606 g_string_append(ctx
->tsdl
, ";\n");
609 if (bt_event_class_get_log_level(ec
->ir_ec
, &log_level
) ==
610 BT_PROPERTY_AVAILABILITY_AVAILABLE
) {
614 g_string_append(ctx
->tsdl
, "loglevel = ");
617 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
620 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
623 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
626 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
629 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
632 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
635 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
638 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
641 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
644 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
647 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
650 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
653 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
656 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
659 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
666 g_string_append_printf(ctx
->tsdl
, "%u;\n", level
);
669 /* Event specific context field class */
670 if (ec
->spec_context_fc
) {
672 g_string_append(ctx
->tsdl
, "context := ");
673 append_field_class(ctx
, ec
->spec_context_fc
);
674 g_string_append(ctx
->tsdl
, ";\n");
677 /* Event payload field class */
678 if (ec
->payload_fc
) {
680 g_string_append(ctx
->tsdl
, "fields := ");
681 append_field_class(ctx
, ec
->payload_fc
);
682 g_string_append(ctx
->tsdl
, ";\n");
685 append_end_block_semi_nl_nl(ctx
);
689 void append_stream_class(struct ctx
*ctx
,
690 struct fs_sink_ctf_stream_class
*sc
)
694 /* Default clock class */
695 if (sc
->default_clock_class
) {
697 int64_t offset_seconds
;
698 uint64_t offset_cycles
;
702 g_string_append(ctx
->tsdl
, "clock {\n");
704 BT_ASSERT(sc
->default_clock_class_name
->len
> 0);
706 g_string_append_printf(ctx
->tsdl
, "name = %s;\n",
707 sc
->default_clock_class_name
->str
);
708 descr
= bt_clock_class_get_description(sc
->default_clock_class
);
711 g_string_append(ctx
->tsdl
, "description = ");
712 append_quoted_string(ctx
, descr
);
713 g_string_append(ctx
->tsdl
, ";\n");
717 g_string_append_printf(ctx
->tsdl
, "freq = %" PRIu64
";\n",
718 bt_clock_class_get_frequency(sc
->default_clock_class
));
720 g_string_append_printf(ctx
->tsdl
, "precision = %" PRIu64
";\n",
721 bt_clock_class_get_precision(sc
->default_clock_class
));
722 bt_clock_class_get_offset(sc
->default_clock_class
,
723 &offset_seconds
, &offset_cycles
);
725 g_string_append_printf(ctx
->tsdl
, "offset_s = %" PRId64
";\n",
728 g_string_append_printf(ctx
->tsdl
, "offset = %" PRIu64
";\n",
731 g_string_append(ctx
->tsdl
, "absolute = ");
733 if (bt_clock_class_origin_is_unix_epoch(
734 sc
->default_clock_class
)) {
735 g_string_append(ctx
->tsdl
, "true");
737 g_string_append(ctx
->tsdl
, "false");
740 g_string_append(ctx
->tsdl
, ";\n");
741 uuid
= bt_clock_class_get_uuid(sc
->default_clock_class
);
744 g_string_append(ctx
->tsdl
, "uuid = ");
745 append_uuid(ctx
, uuid
);
746 g_string_append(ctx
->tsdl
, ";\n");
749 /* End clock class */
750 append_end_block_semi_nl_nl(ctx
);
755 g_string_append(ctx
->tsdl
, "stream {\n");
758 /* Stream class properties */
760 g_string_append_printf(ctx
->tsdl
, "id = %" PRIu64
";\n",
761 bt_stream_class_get_id(sc
->ir_sc
));
763 /* Packet context field class */
765 g_string_append(ctx
->tsdl
, "packet.context := struct {\n");
768 append_integer_field_class_from_props(ctx
, 64, 8, false,
769 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
770 NULL
, "packet_size", true);
772 append_integer_field_class_from_props(ctx
, 64, 8, false,
773 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
774 NULL
, "content_size", true);
776 if (sc
->packets_have_ts_begin
) {
778 append_integer_field_class_from_props(ctx
, 64, 8, false,
779 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
780 sc
->default_clock_class_name
->str
,
781 "timestamp_begin", true);
784 if (sc
->packets_have_ts_end
) {
786 append_integer_field_class_from_props(ctx
, 64, 8, false,
787 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
788 sc
->default_clock_class_name
->str
,
789 "timestamp_end", true);
792 if (sc
->has_discarded_events
) {
794 append_integer_field_class_from_props(ctx
, 64, 8, false,
795 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
796 NULL
, "events_discarded", true);
800 * Unconditionnally write the packet sequence number as, even if
801 * there's no possible discarded packets message, it's still
802 * useful information to have.
805 append_integer_field_class_from_props(ctx
, 64, 8, false,
806 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
807 NULL
, "packet_seq_num", true);
809 if (sc
->packet_context_fc
) {
810 append_struct_field_class_members(ctx
,
811 (void *) sc
->packet_context_fc
);
812 fs_sink_ctf_field_class_struct_align_at_least(
813 (void *) sc
->packet_context_fc
, 8);
816 /* End packet context field class */
817 append_end_block(ctx
);
818 g_string_append_printf(ctx
->tsdl
, " align(%u);\n\n",
819 sc
->packet_context_fc
? sc
->packet_context_fc
->alignment
: 8);
821 /* Event header field class */
823 g_string_append(ctx
->tsdl
, "event.header := struct {\n");
826 append_integer_field_class_from_props(ctx
, 64, 8, false,
827 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
830 if (sc
->default_clock_class
) {
832 append_integer_field_class_from_props(ctx
, 64, 8, false,
833 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
834 sc
->default_clock_class_name
->str
,
838 /* End event header field class */
839 append_end_block(ctx
);
840 g_string_append(ctx
->tsdl
, " align(8);\n");
842 /* Event common context field class */
843 if (sc
->event_common_context_fc
) {
845 g_string_append(ctx
->tsdl
, "event.context := ");
846 append_field_class(ctx
,
847 (void *) sc
->event_common_context_fc
);
848 g_string_append(ctx
->tsdl
, ";\n");
851 /* End stream class */
852 append_end_block_semi_nl_nl(ctx
);
855 for (i
= 0; i
< sc
->event_classes
->len
; i
++) {
856 append_event_class(ctx
, sc
->event_classes
->pdata
[i
]);
861 void translate_trace_ctf_ir_to_tsdl(struct fs_sink_ctf_trace
*trace
,
871 g_string_assign(tsdl
, "/* CTF 1.8 */\n\n");
872 g_string_append(tsdl
, "/* This was generated by a Babeltrace `sink.ctf.fs` component. */\n\n");
876 g_string_append(tsdl
, "trace {\n");
879 /* Trace class properties */
881 g_string_append(tsdl
, "major = 1;\n");
883 g_string_append(tsdl
, "minor = 8;\n");
885 g_string_append(tsdl
, "uuid = ");
886 append_uuid(&ctx
, trace
->uuid
);
887 g_string_append(tsdl
, ";\n");
889 g_string_append(tsdl
, "byte_order = ");
891 if (BYTE_ORDER
== LITTLE_ENDIAN
) {
892 g_string_append(tsdl
, "le");
894 g_string_append(tsdl
, "be");
897 g_string_append(tsdl
, ";\n");
899 /* Packet header field class */
901 g_string_append(tsdl
, "packet.header := struct {\n");
904 append_integer_field_class_from_props(&ctx
, 32, 8, false,
905 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL
,
906 NULL
, "magic", true);
908 append_integer_field_class_from_props(&ctx
, 8, 8, false,
909 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
910 NULL
, "uuid[16]", true);
912 append_integer_field_class_from_props(&ctx
, 64, 8, false,
913 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
914 NULL
, "stream_id", true);
916 append_integer_field_class_from_props(&ctx
, 64, 8, false,
917 BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL
,
918 NULL
, "stream_instance_id", true);
920 /* End packet header field class */
921 append_end_block(&ctx
);
922 g_string_append(ctx
.tsdl
, " align(8);\n");
924 /* End trace class */
925 append_end_block_semi_nl_nl(&ctx
);
927 /* Trace environment */
928 count
= bt_trace_get_environment_entry_count(trace
->ir_trace
);
931 g_string_append(tsdl
, "env {\n");
934 for (i
= 0; i
< count
; i
++) {
938 bt_trace_borrow_environment_entry_by_index_const(
939 trace
->ir_trace
, i
, &name
, &val
);
941 g_string_append_printf(tsdl
, "%s = ", name
);
943 switch (bt_value_get_type(val
)) {
944 case BT_VALUE_TYPE_SIGNED_INTEGER
:
945 g_string_append_printf(tsdl
, "%" PRId64
,
946 bt_value_integer_signed_get(val
));
948 case BT_VALUE_TYPE_STRING
:
949 append_quoted_string(&ctx
, bt_value_string_get(val
));
954 * translate_trace_trace_ir_to_ctf_ir().
959 g_string_append(tsdl
, ";\n");
962 /* End trace class environment */
963 append_end_block_semi_nl_nl(&ctx
);
966 /* Stream classes and their event classes */
967 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
968 append_stream_class(&ctx
, trace
->stream_classes
->pdata
[i
]);