2 * SPDX-License-Identifier: MIT
4 * Copyright 2018 Philippe Proulx <pproulx@efficios.com>
7 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
8 #define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class)
9 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
10 #define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC"
11 #include "logging/comp-logging.h"
13 #include <babeltrace2/babeltrace.h>
14 #include "common/macros.h"
15 #include "common/assert.h"
21 #include "ctf-meta-visitors.h"
25 int find_mapped_clock_class(struct ctf_field_class
*fc
,
26 struct ctf_clock_class
**clock_class
,
27 struct meta_log_config
*log_cfg
)
37 case CTF_FIELD_CLASS_TYPE_INT
:
38 case CTF_FIELD_CLASS_TYPE_ENUM
:
40 struct ctf_field_class_int
*int_fc
= (void *) fc
;
42 if (int_fc
->mapped_clock_class
) {
43 if (*clock_class
&& *clock_class
!=
44 int_fc
->mapped_clock_class
) {
45 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class contains more than one "
46 "clock class: expected-cc-name=\"%s\", "
47 "other-cc-name=\"%s\"",
48 (*clock_class
)->name
->str
,
49 int_fc
->mapped_clock_class
->name
->str
);
54 *clock_class
= int_fc
->mapped_clock_class
;
59 case CTF_FIELD_CLASS_TYPE_STRUCT
:
61 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
63 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
64 struct ctf_named_field_class
*named_fc
=
65 ctf_field_class_struct_borrow_member_by_index(
68 ret
= find_mapped_clock_class(named_fc
->fc
,
69 clock_class
, log_cfg
);
77 case CTF_FIELD_CLASS_TYPE_VARIANT
:
79 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
81 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
82 struct ctf_named_field_class
*named_fc
=
83 ctf_field_class_variant_borrow_option_by_index(
86 ret
= find_mapped_clock_class(named_fc
->fc
,
87 clock_class
, log_cfg
);
95 case CTF_FIELD_CLASS_TYPE_ARRAY
:
96 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
98 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
100 ret
= find_mapped_clock_class(array_fc
->elem_fc
, clock_class
,
117 int update_stream_class_default_clock_class(
118 struct ctf_stream_class
*stream_class
,
119 struct meta_log_config
*log_cfg
)
122 struct ctf_clock_class
*clock_class
=
123 stream_class
->default_clock_class
;
126 ret
= find_mapped_clock_class(stream_class
->packet_context_fc
,
127 &clock_class
, log_cfg
);
132 ret
= find_mapped_clock_class(stream_class
->event_header_fc
,
133 &clock_class
, log_cfg
);
138 ret
= find_mapped_clock_class(stream_class
->event_common_context_fc
,
139 &clock_class
, log_cfg
);
144 for (i
= 0; i
< stream_class
->event_classes
->len
; i
++) {
145 struct ctf_event_class
*event_class
=
146 stream_class
->event_classes
->pdata
[i
];
148 ret
= find_mapped_clock_class(event_class
->spec_context_fc
,
149 &clock_class
, log_cfg
);
154 ret
= find_mapped_clock_class(event_class
->payload_fc
,
155 &clock_class
, log_cfg
);
161 if (!stream_class
->default_clock_class
) {
162 stream_class
->default_clock_class
= clock_class
;
170 int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class
*ctf_tc
,
171 struct meta_log_config
*log_cfg
)
175 struct ctf_clock_class
*clock_class
= NULL
;
177 ret
= find_mapped_clock_class(ctf_tc
->packet_header_fc
, &clock_class
,
188 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
189 struct ctf_stream_class
*sc
=
190 ctf_tc
->stream_classes
->pdata
[i
];
192 ret
= update_stream_class_default_clock_class(
193 ctf_tc
->stream_classes
->pdata
[i
], log_cfg
);
195 _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class contains more than one "
196 "clock class: stream-class-id=%" PRIu64
,