2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 Philippe Proulx <pproulx@efficios.com>
7 #define BT_COMP_LOG_SELF_COMP (ctx->self_comp)
8 #define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
9 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRANSLATE-TRACE-IR-TO-CTF-IR"
10 #include "logging/comp-logging.h"
12 #include "translate-trace-ir-to-ctf-ir.h"
14 #include <babeltrace2/babeltrace.h>
15 #include "common/macros.h"
16 #include "common/common.h"
17 #include "common/assert.h"
24 #include "fs-sink-ctf-meta.h"
26 struct field_path_elem
{
27 uint64_t index_in_parent
;
31 const bt_field_class
*ir_fc
;
34 struct fs_sink_ctf_field_class
*parent_fc
;
38 bt_logging_level log_level
;
39 bt_self_component
*self_comp
;
42 struct fs_sink_ctf_stream_class
*cur_sc
;
45 struct fs_sink_ctf_event_class
*cur_ec
;
47 bt_field_path_scope cur_scope
;
50 * Array of `struct field_path_elem` */
55 struct field_path_elem
*cur_path_stack_at(struct ctx
*ctx
, uint64_t i
)
57 BT_ASSERT(i
< ctx
->cur_path
->len
);
58 return &g_array_index(ctx
->cur_path
, struct field_path_elem
, i
);
62 struct field_path_elem
*cur_path_stack_top(struct ctx
*ctx
)
64 BT_ASSERT(ctx
->cur_path
->len
> 0);
65 return cur_path_stack_at(ctx
, ctx
->cur_path
->len
- 1);
69 bool is_reserved_member_name(const char *name
, const char *reserved_name
)
71 bool is_reserved
= false;
73 if (strcmp(name
, reserved_name
) == 0) {
78 if (name
[0] == '_' && strcmp(&name
[1], reserved_name
) == 0) {
87 static const char *reserved_tsdl_keywords
[] = {
119 bool ist_valid_identifier(const char *name
)
123 bool ist_valid
= true;
125 /* Make sure the name is not a reserved keyword */
126 for (i
= 0; i
< sizeof(reserved_tsdl_keywords
) / sizeof(*reserved_tsdl_keywords
);
128 if (strcmp(name
, reserved_tsdl_keywords
[i
]) == 0) {
134 /* Make sure the name is not an empty string */
135 if (strlen(name
) == 0) {
140 /* Make sure the name starts with a letter or `_` */
141 if (!isalpha((unsigned char) name
[0]) && name
[0] != '_') {
146 /* Make sure the name only contains letters, digits, and `_` */
147 for (at
= name
; *at
!= '\0'; at
++) {
148 if (!isalnum((unsigned char) *at
) && *at
!= '_') {
159 bool must_protect_identifier(const char *name
)
162 bool must_protect
= false;
164 /* Protect a reserved keyword */
165 for (i
= 0; i
< sizeof(reserved_tsdl_keywords
) / sizeof(*reserved_tsdl_keywords
);
167 if (strcmp(name
, reserved_tsdl_keywords
[i
]) == 0) {
173 /* Protect an identifier which already starts with `_` */
174 if (name
[0] == '_') {
184 int cur_path_stack_push(struct ctx
*ctx
,
185 uint64_t index_in_parent
, const char *name
,
186 bool force_protect_name
, const bt_field_class
*ir_fc
,
187 struct fs_sink_ctf_field_class
*parent_fc
)
190 struct field_path_elem
*field_path_elem
;
192 g_array_set_size(ctx
->cur_path
, ctx
->cur_path
->len
+ 1);
193 field_path_elem
= cur_path_stack_top(ctx
);
194 field_path_elem
->index_in_parent
= index_in_parent
;
195 field_path_elem
->name
= g_string_new(NULL
);
198 if (force_protect_name
) {
199 g_string_assign(field_path_elem
->name
, "_");
202 g_string_append(field_path_elem
->name
, name
);
204 if (ctx
->cur_scope
== BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
) {
205 if (is_reserved_member_name(name
, "packet_size") ||
206 is_reserved_member_name(name
, "content_size") ||
207 is_reserved_member_name(name
, "timestamp_begin") ||
208 is_reserved_member_name(name
, "timestamp_end") ||
209 is_reserved_member_name(name
, "events_discarded") ||
210 is_reserved_member_name(name
, "packet_seq_num")) {
211 BT_COMP_LOGE("Unsupported reserved TSDL structure field class member "
212 "or variant field class option name: name=\"%s\"",
219 if (!ist_valid_identifier(field_path_elem
->name
->str
)) {
221 BT_COMP_LOGE("Unsupported non-TSDL structure field class member "
222 "or variant field class option name: name=\"%s\"",
223 field_path_elem
->name
->str
);
228 field_path_elem
->ir_fc
= ir_fc
;
229 field_path_elem
->parent_fc
= parent_fc
;
236 void cur_path_stack_pop(struct ctx
*ctx
)
238 struct field_path_elem
*field_path_elem
;
240 BT_ASSERT(ctx
->cur_path
->len
> 0);
241 field_path_elem
= cur_path_stack_top(ctx
);
243 if (field_path_elem
->name
) {
244 g_string_free(field_path_elem
->name
, TRUE
);
245 field_path_elem
->name
= NULL
;
248 g_array_set_size(ctx
->cur_path
, ctx
->cur_path
->len
- 1);
252 * Creates a relative field ref (a single name) from IR field path
253 * `tgt_ir_field_path`.
255 * This function tries to locate the target field class recursively from
256 * the top to the bottom of the context's current path using only the
257 * target field class's own name. This is because many CTF reading tools
258 * do not support a relative field ref with more than one element, for
259 * example `prev_struct.len`.
261 * Returns a negative value if this resolving operation failed.
264 int create_relative_field_ref(struct ctx
*ctx
,
265 const bt_field_path
*tgt_ir_field_path
, GString
*tgt_field_ref
,
266 struct fs_sink_ctf_field_class
**user_tgt_fc
)
269 struct fs_sink_ctf_field_class
*tgt_fc
= NULL
;
272 const char *tgt_fc_name
= NULL
;
273 struct field_path_elem
*field_path_elem
;
275 /* Get target field class's name */
276 switch (bt_field_path_get_root_scope(tgt_ir_field_path
)) {
277 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
278 BT_ASSERT(ctx
->cur_sc
);
279 tgt_fc
= ctx
->cur_sc
->packet_context_fc
;
281 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
282 BT_ASSERT(ctx
->cur_sc
);
283 tgt_fc
= ctx
->cur_sc
->event_common_context_fc
;
285 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
286 BT_ASSERT(ctx
->cur_ec
);
287 tgt_fc
= ctx
->cur_ec
->spec_context_fc
;
289 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
290 BT_ASSERT(ctx
->cur_ec
);
291 tgt_fc
= ctx
->cur_ec
->payload_fc
;
299 while (i
< bt_field_path_get_item_count(tgt_ir_field_path
)) {
300 const bt_field_path_item
*fp_item
=
301 bt_field_path_borrow_item_by_index_const(
302 tgt_ir_field_path
, i
);
303 struct fs_sink_ctf_named_field_class
*named_fc
= NULL
;
308 if (bt_field_path_item_get_type(fp_item
) ==
309 BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
) {
310 /* Not supported by CTF 1.8 */
315 switch (tgt_fc
->type
) {
316 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
317 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
318 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
319 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_index(
321 bt_field_path_item_index_get_index(fp_item
));
323 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
324 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
325 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
326 named_fc
= fs_sink_ctf_field_class_variant_borrow_option_by_index(
328 bt_field_path_item_index_get_index(fp_item
));
330 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
331 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
333 struct fs_sink_ctf_field_class_array_base
*array_base_fc
=
336 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
337 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
);
338 tgt_fc
= array_base_fc
->elem_fc
;
346 tgt_fc
= named_fc
->fc
;
347 tgt_fc_name
= named_fc
->name
->str
;
353 BT_ASSERT(tgt_fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_INT
);
354 BT_ASSERT(tgt_fc_name
);
356 /* Find target field class having this name in current context */
357 for (si
= ctx
->cur_path
->len
- 1; si
>= 0; si
--) {
358 struct fs_sink_ctf_field_class
*fc
;
359 struct fs_sink_ctf_field_class_struct
*struct_fc
= NULL
;
360 struct fs_sink_ctf_field_class_variant
*var_fc
= NULL
;
361 struct fs_sink_ctf_named_field_class
*named_fc
;
364 field_path_elem
= cur_path_stack_at(ctx
, (uint64_t) si
);
365 fc
= field_path_elem
->parent_fc
;
367 /* Reached stack's bottom */
373 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
374 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
376 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
377 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
380 /* Not supported by TSDL 1.8 */
385 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
) {
386 struct_fc
= (void *) fc
;
387 len
= struct_fc
->members
->len
;
389 var_fc
= (void *) fc
;
390 len
= var_fc
->options
->len
;
393 for (i
= 0; i
< len
; i
++) {
394 if (fc
->type
== FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
) {
395 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_index(
398 named_fc
= fs_sink_ctf_field_class_variant_borrow_option_by_index(
402 if (strcmp(named_fc
->name
->str
, tgt_fc_name
) == 0) {
403 if (named_fc
->fc
== tgt_fc
) {
404 g_string_assign(tgt_field_ref
,
408 *user_tgt_fc
= tgt_fc
;
412 * Using only the target field
413 * class's name, we're not
414 * reaching the target field
415 * class. This is not supported
431 * Creates an absolute field ref from IR field path `tgt_ir_field_path`.
433 * Returns a negative value if this resolving operation failed.
436 int create_absolute_field_ref(struct ctx
*ctx
,
437 const bt_field_path
*tgt_ir_field_path
, GString
*tgt_field_ref
,
438 struct fs_sink_ctf_field_class
**user_tgt_fc
)
441 struct fs_sink_ctf_field_class
*fc
= NULL
;
444 switch (bt_field_path_get_root_scope(tgt_ir_field_path
)) {
445 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
446 BT_ASSERT(ctx
->cur_sc
);
447 fc
= ctx
->cur_sc
->packet_context_fc
;
448 g_string_assign(tgt_field_ref
, "stream.packet.context");
450 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
451 BT_ASSERT(ctx
->cur_sc
);
452 fc
= ctx
->cur_sc
->event_common_context_fc
;
453 g_string_assign(tgt_field_ref
, "stream.event.context");
455 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
456 BT_ASSERT(ctx
->cur_ec
);
457 fc
= ctx
->cur_ec
->spec_context_fc
;
458 g_string_assign(tgt_field_ref
, "event.context");
460 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
461 BT_ASSERT(ctx
->cur_ec
);
462 fc
= ctx
->cur_ec
->payload_fc
;
463 g_string_assign(tgt_field_ref
, "event.fields");
471 for (i
= 0; i
< bt_field_path_get_item_count(tgt_ir_field_path
); i
++) {
472 const bt_field_path_item
*fp_item
=
473 bt_field_path_borrow_item_by_index_const(
474 tgt_ir_field_path
, i
);
475 struct fs_sink_ctf_named_field_class
*named_fc
= NULL
;
477 if (bt_field_path_item_get_type(fp_item
) !=
478 BT_FIELD_PATH_ITEM_TYPE_INDEX
) {
479 /* Not supported by TSDL 1.8 */
485 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
486 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
487 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
488 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_index(
490 bt_field_path_item_index_get_index(fp_item
));
492 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
493 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
494 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
495 named_fc
= fs_sink_ctf_field_class_variant_borrow_option_by_index(
497 bt_field_path_item_index_get_index(fp_item
));
504 g_string_append_c(tgt_field_ref
, '.');
505 g_string_append(tgt_field_ref
, named_fc
->name
->str
);
518 * Resolves a target field class located at `tgt_ir_field_path`, writing
519 * the resolved field ref to `tgt_field_ref` and setting
520 * `*create_before` according to whether or not the target field must be
521 * created immediately before (in which case `tgt_field_ref` is
525 void resolve_field_class(struct ctx
*ctx
,
526 const bt_field_path
*tgt_ir_field_path
,
527 GString
*tgt_field_ref
, bool *create_before
,
528 struct fs_sink_ctf_field_class
**user_tgt_fc
)
531 bt_field_path_scope tgt_scope
;
533 *create_before
= false;
535 if (!tgt_ir_field_path
) {
536 *create_before
= true;
540 tgt_scope
= bt_field_path_get_root_scope(tgt_ir_field_path
);
542 if (tgt_scope
== ctx
->cur_scope
) {
544 * Try, in this order:
546 * 1. Use a relative path, using only the target field
547 * class's name. This is what is the most commonly
548 * supported by popular CTF reading tools.
550 * 2. Use an absolute path. This could fail if there's
551 * an array field class from the current root's field
552 * class to the target field class.
554 * 3. Create the target field class before the
555 * requesting field class (fallback).
557 ret
= create_relative_field_ref(ctx
, tgt_ir_field_path
,
558 tgt_field_ref
, user_tgt_fc
);
560 ret
= create_absolute_field_ref(ctx
, tgt_ir_field_path
,
561 tgt_field_ref
, user_tgt_fc
);
563 *create_before
= true;
568 ret
= create_absolute_field_ref(ctx
, tgt_ir_field_path
,
569 tgt_field_ref
, user_tgt_fc
);
571 /* It must always work in previous scopes */
580 int translate_field_class(struct ctx
*ctx
);
583 void append_to_parent_field_class(struct ctx
*ctx
,
584 struct fs_sink_ctf_field_class
*fc
)
586 struct fs_sink_ctf_field_class
*parent_fc
=
587 cur_path_stack_top(ctx
)->parent_fc
;
589 switch (parent_fc
->type
) {
590 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
591 fs_sink_ctf_field_class_struct_append_member((void *) parent_fc
,
592 cur_path_stack_top(ctx
)->name
->str
, fc
);
594 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
596 struct fs_sink_ctf_field_class_option
*opt_fc
=
599 BT_ASSERT(!opt_fc
->content_fc
);
600 opt_fc
->content_fc
= fc
;
601 opt_fc
->base
.alignment
= fc
->alignment
;
604 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
605 fs_sink_ctf_field_class_variant_append_option((void *) parent_fc
,
606 cur_path_stack_top(ctx
)->name
->str
, fc
);
608 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
609 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
611 struct fs_sink_ctf_field_class_array_base
*array_base_fc
=
614 BT_ASSERT(!array_base_fc
->elem_fc
);
615 array_base_fc
->elem_fc
= fc
;
616 array_base_fc
->base
.alignment
= fc
->alignment
;
625 void update_parent_field_class_alignment(struct ctx
*ctx
,
626 unsigned int alignment
)
628 struct fs_sink_ctf_field_class
*parent_fc
=
629 cur_path_stack_top(ctx
)->parent_fc
;
631 switch (parent_fc
->type
) {
632 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
633 fs_sink_ctf_field_class_struct_align_at_least(
634 (void *) parent_fc
, alignment
);
636 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
637 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
639 struct fs_sink_ctf_field_class_array_base
*array_base_fc
=
642 array_base_fc
->base
.alignment
= alignment
;
651 int translate_structure_field_class_members(struct ctx
*ctx
,
652 struct fs_sink_ctf_field_class_struct
*struct_fc
,
653 const bt_field_class
*ir_fc
)
658 for (i
= 0; i
< bt_field_class_structure_get_member_count(ir_fc
); i
++) {
659 const bt_field_class_structure_member
*member
;
661 const bt_field_class
*memb_ir_fc
;
664 bt_field_class_structure_borrow_member_by_index_const(
666 name
= bt_field_class_structure_member_get_name(member
);
667 memb_ir_fc
= bt_field_class_structure_member_borrow_field_class_const(
669 ret
= cur_path_stack_push(ctx
, i
, name
, true, memb_ir_fc
,
672 BT_COMP_LOGE("Cannot translate structure field class member: "
673 "name=\"%s\"", name
);
677 ret
= translate_field_class(ctx
);
679 BT_COMP_LOGE("Cannot translate structure field class member: "
680 "name=\"%s\"", name
);
684 cur_path_stack_pop(ctx
);
692 int translate_structure_field_class(struct ctx
*ctx
)
695 struct fs_sink_ctf_field_class_struct
*fc
=
696 fs_sink_ctf_field_class_struct_create_empty(
697 cur_path_stack_top(ctx
)->ir_fc
,
698 cur_path_stack_top(ctx
)->index_in_parent
);
701 append_to_parent_field_class(ctx
, (void *) fc
);
702 ret
= translate_structure_field_class_members(ctx
, fc
, fc
->base
.ir_fc
);
707 update_parent_field_class_alignment(ctx
, fc
->base
.alignment
);
714 * This function protects a given variant FC option name (with the `_`
715 * prefix) if required. On success, `name_buf->str` contains the variant
716 * FC option name to use (original option name or protected if
719 * One of the goals of `sink.ctf.fs` is to write a CTF trace which is as
720 * close as possible to an original CTF trace as decoded by
723 * This scenario is valid in CTF 1.8:
735 * Once in trace IR, the enumeration FC mapping names and variant FC
736 * option names are kept as is. For this reason, we don't want to
737 * protect the variant FC option names here (by prepending `_`): this
738 * would make the variant FC option name and the enumeration FC mapping
741 * This scenario is also valid in CTF 1.8:
753 * Once in trace IR, the enumeration FC mapping names are kept as is,
754 * but the `_HELLO` variant FC option name becomes `HELLO` (unprotected
755 * for presentation, as recommended by CTF 1.8). When going back to
756 * TSDL, we need to protect `HELLO` so that it becomes `_HELLO` to match
757 * the corresponding enumeration FC mapping name.
759 * This scenario is also valid in CTF 1.8:
771 * Once in trace IR, the enumeration FC mapping names are kept as is,
772 * but the `__HELLO` variant FC option name becomes `_HELLO`
773 * (unprotected). When going back to TSDL, we need to protect `_HELLO`
774 * so that it becomes `__HELLO` to match the corresponding enumeration
777 * `src.ctf.fs` always uses the _same_ integer range sets for a selector
778 * FC mapping and a corresponding variant FC option. We can use that
779 * fact to find the original variant FC option names by matching variant
780 * FC options and enumeration FC mappings by range set.
783 int maybe_protect_variant_option_name(const bt_field_class
*ir_var_fc
,
784 const bt_field_class
*ir_tag_fc
, uint64_t opt_i
,
789 bt_field_class_type ir_var_fc_type
;
790 const void *opt_ranges
= NULL
;
791 const char *mapping_label
= NULL
;
792 const char *ir_opt_name
;
793 const bt_field_class_variant_option
*base_var_opt
;
794 bool force_protect
= false;
796 ir_var_fc_type
= bt_field_class_get_type(ir_var_fc
);
797 base_var_opt
= bt_field_class_variant_borrow_option_by_index_const(
799 BT_ASSERT(base_var_opt
);
800 ir_opt_name
= bt_field_class_variant_option_get_name(base_var_opt
);
801 BT_ASSERT(ir_opt_name
);
804 * Check if the variant FC option name is required to be
805 * protected (reserved TSDL keyword or starts with `_`). In that
806 * case, the name of the selector FC mapping we find must match
807 * exactly the protected name.
809 force_protect
= must_protect_identifier(ir_opt_name
);
811 g_string_assign(name_buf
, "_");
812 g_string_append(name_buf
, ir_opt_name
);
814 g_string_assign(name_buf
, ir_opt_name
);
817 /* Borrow option's ranges */
818 if (ir_var_fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
) {
819 /* No ranges: we're done */
821 } if (ir_var_fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
) {
822 const bt_field_class_variant_with_selector_field_integer_unsigned_option
*var_opt
=
823 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
826 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
829 const bt_field_class_variant_with_selector_field_integer_signed_option
*var_opt
=
830 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
833 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
837 /* Find corresponding mapping by range set in selector FC */
838 for (i
= 0; i
< bt_field_class_enumeration_get_mapping_count(ir_tag_fc
);
840 if (ir_var_fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
) {
841 const bt_field_class_enumeration_mapping
*mapping_base
;
842 const bt_field_class_enumeration_unsigned_mapping
*mapping
;
843 const bt_integer_range_set_unsigned
*mapping_ranges
;
845 mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
847 mapping_ranges
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
850 if (bt_integer_range_set_unsigned_is_equal(opt_ranges
,
852 /* We have a winner */
854 bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
857 bt_field_class_enumeration_mapping_get_label(
862 const bt_field_class_enumeration_mapping
*mapping_base
;
863 const bt_field_class_enumeration_signed_mapping
*mapping
;
864 const bt_integer_range_set_signed
*mapping_ranges
;
866 mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
868 mapping_ranges
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
871 if (bt_integer_range_set_signed_is_equal(opt_ranges
,
873 /* We have a winner */
875 bt_field_class_enumeration_signed_mapping_as_mapping_const(
878 bt_field_class_enumeration_mapping_get_label(
885 if (!mapping_label
) {
886 /* Range set not found: invalid selector for CTF 1.8 */
892 * If the enumeration FC mapping name is not the same as the
893 * variant FC option name and we didn't protect already, try
894 * protecting the option name and check again.
896 if (strcmp(mapping_label
, name_buf
->str
) != 0) {
902 if (mapping_label
[0] == '\0') {
907 g_string_assign(name_buf
, "_");
908 g_string_append(name_buf
, ir_opt_name
);
910 if (strcmp(mapping_label
, name_buf
->str
) != 0) {
921 int translate_option_field_class(struct ctx
*ctx
)
923 struct fs_sink_ctf_field_class_option
*fc
=
924 fs_sink_ctf_field_class_option_create_empty(
925 cur_path_stack_top(ctx
)->ir_fc
,
926 cur_path_stack_top(ctx
)->index_in_parent
);
927 const bt_field_class
*content_ir_fc
=
928 bt_field_class_option_borrow_field_class_const(fc
->base
.ir_fc
);
934 * CTF 1.8 does not support the option field class type. To
935 * write something anyway, this component translates this type
936 * to a variant field class where the options are:
938 * * An empty structure field class.
939 * * The optional field class itself.
941 * The "tag" is always generated/before in that case (an 8-bit
942 * unsigned enumeration field class).
944 append_to_parent_field_class(ctx
, (void *) fc
);
945 ret
= cur_path_stack_push(ctx
, UINT64_C(-1), NULL
, false, content_ir_fc
,
948 BT_COMP_LOGE_STR("Cannot translate option field class content.");
952 ret
= translate_field_class(ctx
);
954 BT_COMP_LOGE_STR("Cannot translate option field class content.");
958 cur_path_stack_pop(ctx
);
959 update_parent_field_class_alignment(ctx
, fc
->base
.alignment
);
966 int translate_variant_field_class(struct ctx
*ctx
)
970 struct fs_sink_ctf_field_class_variant
*fc
=
971 fs_sink_ctf_field_class_variant_create_empty(
972 cur_path_stack_top(ctx
)->ir_fc
,
973 cur_path_stack_top(ctx
)->index_in_parent
);
974 bt_field_class_type ir_fc_type
;
975 const bt_field_path
*ir_selector_field_path
= NULL
;
976 struct fs_sink_ctf_field_class
*tgt_fc
= NULL
;
977 GString
*name_buf
= g_string_new(NULL
);
978 bt_value
*prot_opt_names
= bt_value_array_create();
983 BT_ASSERT(prot_opt_names
);
984 ir_fc_type
= bt_field_class_get_type(fc
->base
.ir_fc
);
985 opt_count
= bt_field_class_variant_get_option_count(fc
->base
.ir_fc
);
987 if (bt_field_class_type_is(ir_fc_type
,
988 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD
)) {
989 ir_selector_field_path
= bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
991 BT_ASSERT(ir_selector_field_path
);
994 /* Resolve tag field class before appending to parent */
995 resolve_field_class(ctx
, ir_selector_field_path
, fc
->tag_ref
,
996 &fc
->tag_is_before
, &tgt_fc
);
998 if (ir_selector_field_path
&& tgt_fc
) {
999 uint64_t mapping_count
;
1000 uint64_t option_count
;
1002 /* CTF 1.8: selector FC must be an enumeration FC */
1003 bt_field_class_type type
= bt_field_class_get_type(
1006 if (!bt_field_class_type_is(type
,
1007 BT_FIELD_CLASS_TYPE_ENUMERATION
)) {
1008 fc
->tag_is_before
= true;
1013 * Call maybe_protect_variant_option_name() for each
1014 * option below. In that case we also want selector FC
1015 * to contain as many mappings as the variant FC has
1018 mapping_count
= bt_field_class_enumeration_get_mapping_count(
1020 option_count
= bt_field_class_variant_get_option_count(
1023 if (mapping_count
!= option_count
) {
1024 fc
->tag_is_before
= true;
1029 * No compatible selector field class for CTF 1.8:
1030 * create the appropriate selector field class.
1032 fc
->tag_is_before
= true;
1038 * First pass: detect any option name clash with option name
1039 * protection. In that case, we don't fail: just create the
1040 * selector field class before the variant field class.
1042 * After this, `prot_opt_names` contains the final option names,
1043 * potentially protected if needed. They can still be invalid
1044 * TSDL identifiers however; this will be checked by
1045 * cur_path_stack_push().
1047 for (i
= 0; i
< opt_count
; i
++) {
1048 if (!fc
->tag_is_before
) {
1049 BT_ASSERT(tgt_fc
->ir_fc
);
1050 ret
= maybe_protect_variant_option_name(fc
->base
.ir_fc
,
1051 tgt_fc
->ir_fc
, i
, name_buf
);
1053 fc
->tag_is_before
= true;
1057 ret
= bt_value_array_append_string_element(prot_opt_names
,
1064 for (i
= 0; i
< opt_count
; i
++) {
1066 const bt_value
*opt_name_a
=
1067 bt_value_array_borrow_element_by_index_const(
1070 for (j
= 0; j
< opt_count
; j
++) {
1071 const bt_value
*opt_name_b
;
1078 bt_value_array_borrow_element_by_index_const(
1080 if (bt_value_is_equal(opt_name_a
, opt_name_b
)) {
1082 * Variant FC option names are not
1083 * unique when protected.
1085 fc
->tag_is_before
= true;
1086 goto append_to_parent
;
1092 append_to_parent_field_class(ctx
, (void *) fc
);
1094 for (i
= 0; i
< opt_count
; i
++) {
1095 const bt_field_class_variant_option
*opt
;
1096 const bt_field_class
*opt_ir_fc
;
1097 const bt_value
*prot_opt_name_val
=
1098 bt_value_array_borrow_element_by_index_const(
1100 const char *prot_opt_name
= bt_value_string_get(
1103 BT_ASSERT(prot_opt_name
);
1104 opt
= bt_field_class_variant_borrow_option_by_index_const(
1106 opt_ir_fc
= bt_field_class_variant_option_borrow_field_class_const(
1110 * We don't ask cur_path_stack_push() to protect the
1111 * option name because it's already protected at this
1114 ret
= cur_path_stack_push(ctx
, i
, prot_opt_name
, false,
1115 opt_ir_fc
, (void *) fc
);
1117 BT_COMP_LOGE("Cannot translate variant field class option: "
1118 "name=\"%s\"", prot_opt_name
);
1122 ret
= translate_field_class(ctx
);
1124 BT_COMP_LOGE("Cannot translate variant field class option: "
1125 "name=\"%s\"", prot_opt_name
);
1129 cur_path_stack_pop(ctx
);
1134 g_string_free(name_buf
, TRUE
);
1137 bt_value_put_ref(prot_opt_names
);
1142 int translate_static_array_field_class(struct ctx
*ctx
)
1144 struct fs_sink_ctf_field_class_array
*fc
=
1145 fs_sink_ctf_field_class_array_create_empty(
1146 cur_path_stack_top(ctx
)->ir_fc
,
1147 cur_path_stack_top(ctx
)->index_in_parent
);
1148 const bt_field_class
*elem_ir_fc
=
1149 bt_field_class_array_borrow_element_field_class_const(
1150 fc
->base
.base
.ir_fc
);
1154 append_to_parent_field_class(ctx
, (void *) fc
);
1155 ret
= cur_path_stack_push(ctx
, UINT64_C(-1), NULL
, false, elem_ir_fc
,
1158 BT_COMP_LOGE_STR("Cannot translate static array field class element.");
1162 ret
= translate_field_class(ctx
);
1164 BT_COMP_LOGE_STR("Cannot translate static array field class element.");
1168 cur_path_stack_pop(ctx
);
1169 update_parent_field_class_alignment(ctx
, fc
->base
.base
.alignment
);
1176 int translate_dynamic_array_field_class(struct ctx
*ctx
)
1178 struct fs_sink_ctf_field_class_sequence
*fc
=
1179 fs_sink_ctf_field_class_sequence_create_empty(
1180 cur_path_stack_top(ctx
)->ir_fc
,
1181 cur_path_stack_top(ctx
)->index_in_parent
);
1182 const bt_field_class
*elem_ir_fc
=
1183 bt_field_class_array_borrow_element_field_class_const(
1184 fc
->base
.base
.ir_fc
);
1189 /* Resolve length field class before appending to parent */
1190 if (bt_field_class_get_type(cur_path_stack_top(ctx
)->ir_fc
) ==
1191 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
) {
1192 resolve_field_class(ctx
,
1193 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
1194 fc
->base
.base
.ir_fc
),
1195 fc
->length_ref
, &fc
->length_is_before
, NULL
);
1198 append_to_parent_field_class(ctx
, (void *) fc
);
1199 ret
= cur_path_stack_push(ctx
, UINT64_C(-1), NULL
, false, elem_ir_fc
,
1202 BT_COMP_LOGE_STR("Cannot translate dynamic array field class element.");
1206 ret
= translate_field_class(ctx
);
1208 BT_COMP_LOGE_STR("Cannot translate dynamic array field class element.");
1212 cur_path_stack_pop(ctx
);
1213 update_parent_field_class_alignment(ctx
, fc
->base
.base
.alignment
);
1220 int translate_bool_field_class(struct ctx
*ctx
)
1222 struct fs_sink_ctf_field_class_bool
*fc
=
1223 fs_sink_ctf_field_class_bool_create(
1224 cur_path_stack_top(ctx
)->ir_fc
,
1225 cur_path_stack_top(ctx
)->index_in_parent
);
1228 append_to_parent_field_class(ctx
, (void *) fc
);
1233 int translate_bit_array_field_class(struct ctx
*ctx
)
1235 struct fs_sink_ctf_field_class_bit_array
*fc
=
1236 fs_sink_ctf_field_class_bit_array_create(
1237 cur_path_stack_top(ctx
)->ir_fc
,
1238 cur_path_stack_top(ctx
)->index_in_parent
);
1241 append_to_parent_field_class(ctx
, (void *) fc
);
1246 int translate_integer_field_class(struct ctx
*ctx
)
1248 struct fs_sink_ctf_field_class_int
*fc
=
1249 fs_sink_ctf_field_class_int_create(
1250 cur_path_stack_top(ctx
)->ir_fc
,
1251 cur_path_stack_top(ctx
)->index_in_parent
);
1254 append_to_parent_field_class(ctx
, (void *) fc
);
1259 int translate_real_field_class(struct ctx
*ctx
)
1261 struct fs_sink_ctf_field_class_float
*fc
=
1262 fs_sink_ctf_field_class_float_create(
1263 cur_path_stack_top(ctx
)->ir_fc
,
1264 cur_path_stack_top(ctx
)->index_in_parent
);
1267 append_to_parent_field_class(ctx
, (void *) fc
);
1272 int translate_string_field_class(struct ctx
*ctx
)
1274 struct fs_sink_ctf_field_class_string
*fc
=
1275 fs_sink_ctf_field_class_string_create(
1276 cur_path_stack_top(ctx
)->ir_fc
,
1277 cur_path_stack_top(ctx
)->index_in_parent
);
1280 append_to_parent_field_class(ctx
, (void *) fc
);
1285 * Translates a field class, recursively.
1287 * The field class's IR field class, parent field class, and index
1288 * within its parent are in the context's current path's top element
1289 * (cur_path_stack_top()).
1292 int translate_field_class(struct ctx
*ctx
)
1295 bt_field_class_type ir_fc_type
=
1296 bt_field_class_get_type(cur_path_stack_top(ctx
)->ir_fc
);
1298 if (ir_fc_type
== BT_FIELD_CLASS_TYPE_BOOL
) {
1299 ret
= translate_bool_field_class(ctx
);
1300 } else if (ir_fc_type
== BT_FIELD_CLASS_TYPE_BIT_ARRAY
) {
1301 ret
= translate_bit_array_field_class(ctx
);
1302 } else if (bt_field_class_type_is(ir_fc_type
,
1303 BT_FIELD_CLASS_TYPE_INTEGER
)) {
1304 ret
= translate_integer_field_class(ctx
);
1305 } else if (bt_field_class_type_is(ir_fc_type
,
1306 BT_FIELD_CLASS_TYPE_REAL
)) {
1307 ret
= translate_real_field_class(ctx
);
1308 } else if (ir_fc_type
== BT_FIELD_CLASS_TYPE_STRING
) {
1309 ret
= translate_string_field_class(ctx
);
1310 } else if (ir_fc_type
== BT_FIELD_CLASS_TYPE_STRUCTURE
) {
1311 ret
= translate_structure_field_class(ctx
);
1312 } else if (ir_fc_type
== BT_FIELD_CLASS_TYPE_STATIC_ARRAY
) {
1313 ret
= translate_static_array_field_class(ctx
);
1314 } else if (bt_field_class_type_is(ir_fc_type
,
1315 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
)) {
1316 ret
= translate_dynamic_array_field_class(ctx
);
1317 } else if (bt_field_class_type_is(ir_fc_type
,
1318 BT_FIELD_CLASS_TYPE_OPTION
)) {
1319 ret
= translate_option_field_class(ctx
);
1320 } else if (bt_field_class_type_is(ir_fc_type
,
1321 BT_FIELD_CLASS_TYPE_VARIANT
)) {
1322 ret
= translate_variant_field_class(ctx
);
1331 int set_field_ref(struct fs_sink_ctf_field_class
*fc
, const char *fc_name
,
1332 struct fs_sink_ctf_field_class
*parent_fc
)
1335 GString
*field_ref
= NULL
;
1337 const char *tgt_type
;
1338 struct fs_sink_ctf_field_class_struct
*parent_struct_fc
=
1341 unsigned int suffix
= 0;
1343 if (!fc_name
|| !parent_fc
||
1344 parent_fc
->type
!= FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
) {
1351 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
1354 * CTF 1.8 does not support the option field class type.
1355 * To write something anyway, this component translates
1356 * this type to a variant field class where the options
1359 * * An empty structure field class.
1360 * * The optional field class itself.
1362 * Because the option field class becomes a CTF variant
1363 * field class, we use the term "tag" too here.
1365 * The "tag" is always generated/before in that case (an
1366 * 8-bit unsigned enumeration field class).
1368 struct fs_sink_ctf_field_class_option
*opt_fc
= (void *) fc
;
1370 field_ref
= opt_fc
->tag_ref
;
1375 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
1377 struct fs_sink_ctf_field_class_sequence
*seq_fc
= (void *) fc
;
1379 field_ref
= seq_fc
->length_ref
;
1380 is_before
= seq_fc
->length_is_before
;
1384 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
1386 struct fs_sink_ctf_field_class_variant
*var_fc
= (void *) fc
;
1388 field_ref
= var_fc
->tag_ref
;
1389 is_before
= var_fc
->tag_is_before
;
1397 BT_ASSERT(field_ref
);
1403 /* Initial field ref */
1404 g_string_printf(field_ref
, "__%s_%s", fc_name
, tgt_type
);
1407 * Make sure field ref does not clash with an existing field
1408 * class name within the same parent structure field class.
1411 bool name_ok
= true;
1413 for (i
= 0; i
< parent_struct_fc
->members
->len
; i
++) {
1414 struct fs_sink_ctf_named_field_class
*named_fc
=
1415 fs_sink_ctf_field_class_struct_borrow_member_by_index(
1416 parent_struct_fc
, i
);
1418 if (strcmp(field_ref
->str
, named_fc
->name
->str
) == 0) {
1426 /* No clash: we're done */
1430 /* Append suffix and try again */
1431 g_string_printf(field_ref
, "__%s_%s_%u", fc_name
, tgt_type
,
1441 * This function recursively sets field refs of sequence and variant
1442 * field classes when they are immediately before, avoiding name clashes
1443 * with existing field class names.
1445 * It can fail at this point if, for example, a sequence field class of
1446 * which to set the length's field ref has something else than a
1447 * structure field class as its parent: in this case, there's no
1448 * location to place the length field class immediately before the
1449 * sequence field class.
1452 int set_field_refs(struct fs_sink_ctf_field_class
* const fc
,
1453 const char *fc_name
, struct fs_sink_ctf_field_class
*parent_fc
)
1456 enum fs_sink_ctf_field_class_type fc_type
;
1462 case FS_SINK_CTF_FIELD_CLASS_TYPE_OPTION
:
1464 struct fs_sink_ctf_field_class_option
*opt_fc
= (void *) fc
;
1466 ret
= set_field_ref(fc
, fc_name
, parent_fc
);
1471 ret
= set_field_refs(opt_fc
->content_fc
, NULL
, fc
);
1478 case FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
:
1479 case FS_SINK_CTF_FIELD_CLASS_TYPE_VARIANT
:
1483 struct fs_sink_ctf_field_class_struct
*struct_fc
= NULL
;
1484 struct fs_sink_ctf_field_class_variant
*var_fc
= NULL
;
1485 struct fs_sink_ctf_named_field_class
*named_fc
;
1487 if (fc_type
== FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
) {
1488 struct_fc
= (void *) fc
;
1489 len
= struct_fc
->members
->len
;
1491 var_fc
= (void *) fc
;
1492 len
= var_fc
->options
->len
;
1493 ret
= set_field_ref(fc
, fc_name
, parent_fc
);
1499 for (i
= 0; i
< len
; i
++) {
1500 if (fc_type
== FS_SINK_CTF_FIELD_CLASS_TYPE_STRUCT
) {
1501 named_fc
= fs_sink_ctf_field_class_struct_borrow_member_by_index(
1504 named_fc
= fs_sink_ctf_field_class_variant_borrow_option_by_index(
1508 ret
= set_field_refs(named_fc
->fc
, named_fc
->name
->str
,
1517 case FS_SINK_CTF_FIELD_CLASS_TYPE_ARRAY
:
1518 case FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
:
1520 struct fs_sink_ctf_field_class_array_base
*array_base_fc
=
1523 if (fc_type
== FS_SINK_CTF_FIELD_CLASS_TYPE_SEQUENCE
) {
1524 ret
= set_field_ref(fc
, fc_name
, parent_fc
);
1530 ret
= set_field_refs(array_base_fc
->elem_fc
, NULL
, fc
);
1546 * This function translates a root scope trace IR field class to
1547 * a CTF IR field class.
1549 * The resulting CTF IR field class is written to `*fc` so that it
1550 * exists as the parent object's (stream class or event class) true root
1551 * field class during the recursive translation for resolving purposes.
1552 * This is also why this function creates the empty structure field
1553 * class and then calls translate_structure_field_class_members() to
1557 int translate_scope_field_class(struct ctx
*ctx
, bt_field_path_scope scope
,
1558 struct fs_sink_ctf_field_class
**fc
,
1559 const bt_field_class
*ir_fc
)
1567 BT_ASSERT(bt_field_class_get_type(ir_fc
) ==
1568 BT_FIELD_CLASS_TYPE_STRUCTURE
);
1570 *fc
= (void *) fs_sink_ctf_field_class_struct_create_empty(
1571 ir_fc
, UINT64_C(-1));
1573 ctx
->cur_scope
= scope
;
1574 BT_ASSERT(ctx
->cur_path
->len
== 0);
1575 ret
= cur_path_stack_push(ctx
, UINT64_C(-1), NULL
, false, ir_fc
, NULL
);
1577 BT_COMP_LOGE("Cannot translate scope structure field class: "
1582 ret
= translate_structure_field_class_members(ctx
, (void *) *fc
, ir_fc
);
1584 BT_COMP_LOGE("Cannot translate scope structure field class: "
1589 cur_path_stack_pop(ctx
);
1591 /* Set field refs for preceding targets */
1592 ret
= set_field_refs(*fc
, NULL
, NULL
);
1599 void ctx_init(struct ctx
*ctx
, struct fs_sink_comp
*fs_sink
)
1601 memset(ctx
, 0, sizeof(struct ctx
));
1602 ctx
->cur_path
= g_array_new(FALSE
, TRUE
,
1603 sizeof(struct field_path_elem
));
1604 BT_ASSERT(ctx
->cur_path
);
1605 ctx
->log_level
= fs_sink
->log_level
;
1606 ctx
->self_comp
= fs_sink
->self_comp
;
1610 void ctx_fini(struct ctx
*ctx
)
1612 if (ctx
->cur_path
) {
1613 g_array_free(ctx
->cur_path
, TRUE
);
1614 ctx
->cur_path
= NULL
;
1619 int translate_event_class(struct fs_sink_comp
*fs_sink
,
1620 struct fs_sink_ctf_stream_class
*sc
,
1621 const bt_event_class
*ir_ec
,
1622 struct fs_sink_ctf_event_class
**out_ec
)
1626 struct fs_sink_ctf_event_class
*ec
;
1631 ctx_init(&ctx
, fs_sink
);
1632 ec
= fs_sink_ctf_event_class_create(sc
, ir_ec
);
1636 ret
= translate_scope_field_class(&ctx
, BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
,
1637 &ec
->spec_context_fc
,
1638 bt_event_class_borrow_specific_context_field_class_const(
1644 ret
= translate_scope_field_class(&ctx
, BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
,
1646 bt_event_class_borrow_payload_field_class_const(ir_ec
));
1658 int try_translate_event_class_trace_ir_to_ctf_ir(
1659 struct fs_sink_comp
*fs_sink
,
1660 struct fs_sink_ctf_stream_class
*sc
,
1661 const bt_event_class
*ir_ec
,
1662 struct fs_sink_ctf_event_class
**out_ec
)
1669 /* Check in hash table first */
1670 *out_ec
= g_hash_table_lookup(sc
->event_classes_from_ir
, ir_ec
);
1671 if (G_LIKELY(*out_ec
)) {
1675 ret
= translate_event_class(fs_sink
, sc
, ir_ec
, out_ec
);
1682 bool default_clock_class_name_exists(struct fs_sink_ctf_trace
*trace
,
1685 bool exists
= false;
1688 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
1689 struct fs_sink_ctf_stream_class
*sc
=
1690 trace
->stream_classes
->pdata
[i
];
1692 if (sc
->default_clock_class_name
->len
== 0) {
1693 /* No default clock class */
1697 if (strcmp(sc
->default_clock_class_name
->str
, name
) == 0) {
1708 void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class
*sc
)
1710 unsigned int suffix
= 0;
1713 g_string_assign(sc
->default_clock_class_name
, "");
1714 sprintf(buf
, "default");
1716 while (default_clock_class_name_exists(sc
->trace
, buf
)) {
1717 sprintf(buf
, "default%u", suffix
);
1721 g_string_assign(sc
->default_clock_class_name
, buf
);
1725 int translate_stream_class(struct fs_sink_comp
*fs_sink
,
1726 struct fs_sink_ctf_trace
*trace
,
1727 const bt_stream_class
*ir_sc
,
1728 struct fs_sink_ctf_stream_class
**out_sc
)
1735 ctx_init(&ctx
, fs_sink
);
1736 *out_sc
= fs_sink_ctf_stream_class_create(trace
, ir_sc
);
1739 /* Set default clock class's protected name, if any */
1740 if ((*out_sc
)->default_clock_class
) {
1741 const char *name
= bt_clock_class_get_name(
1742 (*out_sc
)->default_clock_class
);
1745 /* Try original name, protected */
1746 g_string_assign((*out_sc
)->default_clock_class_name
,
1749 if (must_protect_identifier(name
)) {
1751 (*out_sc
)->default_clock_class_name
,
1755 g_string_assign((*out_sc
)->default_clock_class_name
,
1757 if (!ist_valid_identifier(
1758 (*out_sc
)->default_clock_class_name
->str
)) {
1759 /* Invalid: create a new name */
1760 make_unique_default_clock_class_name(*out_sc
);
1763 /* No name: create a name */
1764 make_unique_default_clock_class_name(*out_sc
);
1768 ctx
.cur_sc
= *out_sc
;
1769 ret
= translate_scope_field_class(&ctx
, BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
,
1770 &(*out_sc
)->packet_context_fc
,
1771 bt_stream_class_borrow_packet_context_field_class_const(ir_sc
));
1776 if ((*out_sc
)->packet_context_fc
) {
1778 * Make sure the structure field class's alignment is
1779 * enough: 8 is what we use for our own special members
1780 * in the packet context.
1782 fs_sink_ctf_field_class_struct_align_at_least(
1783 (void *) (*out_sc
)->packet_context_fc
, 8);
1786 ret
= translate_scope_field_class(&ctx
, BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
,
1787 &(*out_sc
)->event_common_context_fc
,
1788 bt_stream_class_borrow_event_common_context_field_class_const(
1797 fs_sink_ctf_stream_class_destroy(*out_sc
);
1806 int try_translate_stream_class_trace_ir_to_ctf_ir(
1807 struct fs_sink_comp
*fs_sink
,
1808 struct fs_sink_ctf_trace
*trace
,
1809 const bt_stream_class
*ir_sc
,
1810 struct fs_sink_ctf_stream_class
**out_sc
)
1818 for (i
= 0; i
< trace
->stream_classes
->len
; i
++) {
1819 *out_sc
= trace
->stream_classes
->pdata
[i
];
1821 if ((*out_sc
)->ir_sc
== ir_sc
) {
1826 ret
= translate_stream_class(fs_sink
, trace
, ir_sc
, out_sc
);
1833 struct fs_sink_ctf_trace
*translate_trace_trace_ir_to_ctf_ir(
1834 struct fs_sink_comp
*fs_sink
, const bt_trace
*ir_trace
)
1838 struct fs_sink_ctf_trace
*trace
= NULL
;
1840 /* Check that trace's environment is TSDL-compatible */
1841 count
= bt_trace_get_environment_entry_count(ir_trace
);
1842 for (i
= 0; i
< count
; i
++) {
1844 const bt_value
*val
;
1846 bt_trace_borrow_environment_entry_by_index_const(
1847 ir_trace
, i
, &name
, &val
);
1849 if (!ist_valid_identifier(name
)) {
1850 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, fs_sink
->log_level
,
1852 "Unsupported trace class's environment entry name: "
1853 "name=\"%s\"", name
);
1857 switch (bt_value_get_type(val
)) {
1858 case BT_VALUE_TYPE_SIGNED_INTEGER
:
1859 case BT_VALUE_TYPE_STRING
:
1862 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, fs_sink
->log_level
,
1864 "Unsupported trace class's environment entry value type: "
1866 bt_common_value_type_string(
1867 bt_value_get_type(val
)));
1872 trace
= fs_sink_ctf_trace_create(ir_trace
);