2 * Copyright 2018 - 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.
15 #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp)
16 #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level)
17 #define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC"
18 #include "plugins/comp-logging.h"
20 #include <babeltrace2/babeltrace.h>
21 #include "common/macros.h"
22 #include "common/assert.h"
28 #include "ctf-meta-visitors.h"
32 int find_mapped_clock_class(struct ctf_field_class
*fc
,
33 struct ctf_clock_class
**clock_class
,
34 struct meta_log_config
*log_cfg
)
44 case CTF_FIELD_CLASS_TYPE_INT
:
45 case CTF_FIELD_CLASS_TYPE_ENUM
:
47 struct ctf_field_class_int
*int_fc
= (void *) fc
;
49 if (int_fc
->mapped_clock_class
) {
50 if (*clock_class
&& *clock_class
!=
51 int_fc
->mapped_clock_class
) {
52 BT_COMP_LOGE("Stream class contains more than one "
53 "clock class: expected-cc-name=\"%s\", "
54 "other-cc-name=\"%s\"",
55 (*clock_class
)->name
->str
,
56 int_fc
->mapped_clock_class
->name
->str
);
61 *clock_class
= int_fc
->mapped_clock_class
;
66 case CTF_FIELD_CLASS_TYPE_STRUCT
:
68 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
70 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
71 struct ctf_named_field_class
*named_fc
=
72 ctf_field_class_struct_borrow_member_by_index(
75 ret
= find_mapped_clock_class(named_fc
->fc
,
76 clock_class
, log_cfg
);
84 case CTF_FIELD_CLASS_TYPE_VARIANT
:
86 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
88 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
89 struct ctf_named_field_class
*named_fc
=
90 ctf_field_class_variant_borrow_option_by_index(
93 ret
= find_mapped_clock_class(named_fc
->fc
,
94 clock_class
, log_cfg
);
102 case CTF_FIELD_CLASS_TYPE_ARRAY
:
103 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
105 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
107 ret
= find_mapped_clock_class(array_fc
->elem_fc
, clock_class
,
124 int update_stream_class_default_clock_class(
125 struct ctf_stream_class
*stream_class
,
126 struct meta_log_config
*log_cfg
)
129 struct ctf_clock_class
*clock_class
=
130 stream_class
->default_clock_class
;
133 ret
= find_mapped_clock_class(stream_class
->packet_context_fc
,
134 &clock_class
, log_cfg
);
139 ret
= find_mapped_clock_class(stream_class
->event_header_fc
,
140 &clock_class
, log_cfg
);
145 ret
= find_mapped_clock_class(stream_class
->event_common_context_fc
,
146 &clock_class
, log_cfg
);
151 for (i
= 0; i
< stream_class
->event_classes
->len
; i
++) {
152 struct ctf_event_class
*event_class
=
153 stream_class
->event_classes
->pdata
[i
];
155 ret
= find_mapped_clock_class(event_class
->spec_context_fc
,
156 &clock_class
, log_cfg
);
161 ret
= find_mapped_clock_class(event_class
->payload_fc
,
162 &clock_class
, log_cfg
);
168 if (!stream_class
->default_clock_class
) {
169 stream_class
->default_clock_class
= clock_class
;
177 int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class
*ctf_tc
,
178 struct meta_log_config
*log_cfg
)
182 struct ctf_clock_class
*clock_class
= NULL
;
184 ret
= find_mapped_clock_class(ctf_tc
->packet_header_fc
, &clock_class
,
195 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
196 struct ctf_stream_class
*sc
=
197 ctf_tc
->stream_classes
->pdata
[i
];
199 ret
= update_stream_class_default_clock_class(
200 ctf_tc
->stream_classes
->pdata
[i
], log_cfg
);
202 BT_COMP_LOGE("Stream class contains more than one "
203 "clock class: stream-class-id=%" PRIu64
,