Commit | Line | Data |
---|---|---|
44c440bc | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
44c440bc | 3 | * |
0235b0db | 4 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> |
44c440bc PP |
5 | */ |
6 | ||
c802cacb SM |
7 | #include <glib.h> |
8 | #include <inttypes.h> | |
9 | #include <stdint.h> | |
10 | #include <string.h> | |
11 | ||
12 | #include <babeltrace2/babeltrace.h> | |
13 | ||
4164020e | 14 | #define BT_COMP_LOG_SELF_COMP (log_cfg->self_comp) |
50f6fce8 | 15 | #define BT_COMP_LOG_SELF_COMP_CLASS (log_cfg->self_comp_class) |
4164020e SM |
16 | #define BT_LOG_OUTPUT_LEVEL (log_cfg->log_level) |
17 | #define BT_LOG_TAG "PLUGIN/CTF/META/UPDATE-DEF-CC" | |
c802cacb | 18 | #include "logging.hpp" |
d9c39b0a | 19 | #include "logging/comp-logging.h" |
44c440bc | 20 | |
578e048b | 21 | #include "common/assert.h" |
c802cacb | 22 | #include "common/macros.h" |
44c440bc | 23 | |
087cd0f5 | 24 | #include "ctf-meta-visitors.hpp" |
44c440bc | 25 | |
4164020e SM |
26 | static inline int find_mapped_clock_class(struct ctf_field_class *fc, |
27 | struct ctf_clock_class **clock_class, | |
28 | struct meta_log_config *log_cfg) | |
44c440bc | 29 | { |
4164020e SM |
30 | int ret = 0; |
31 | uint64_t i; | |
32 | ||
33 | if (!fc) { | |
34 | goto end; | |
35 | } | |
36 | ||
37 | switch (fc->type) { | |
38 | case CTF_FIELD_CLASS_TYPE_INT: | |
39 | case CTF_FIELD_CLASS_TYPE_ENUM: | |
40 | { | |
41 | struct ctf_field_class_int *int_fc = ctf_field_class_as_int(fc); | |
42 | ||
43 | if (int_fc->mapped_clock_class) { | |
44 | if (*clock_class && *clock_class != 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); | |
50 | ret = -1; | |
51 | goto end; | |
52 | } | |
53 | ||
54 | *clock_class = int_fc->mapped_clock_class; | |
55 | } | |
56 | ||
57 | break; | |
58 | } | |
59 | case CTF_FIELD_CLASS_TYPE_STRUCT: | |
60 | { | |
61 | struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc); | |
62 | ||
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(struct_fc, i); | |
66 | ||
67 | ret = find_mapped_clock_class(named_fc->fc, clock_class, log_cfg); | |
68 | if (ret) { | |
69 | goto end; | |
70 | } | |
71 | } | |
72 | ||
73 | break; | |
74 | } | |
75 | case CTF_FIELD_CLASS_TYPE_VARIANT: | |
76 | { | |
77 | struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); | |
78 | ||
79 | for (i = 0; i < var_fc->options->len; i++) { | |
80 | struct ctf_named_field_class *named_fc = | |
81 | ctf_field_class_variant_borrow_option_by_index(var_fc, i); | |
82 | ||
83 | ret = find_mapped_clock_class(named_fc->fc, clock_class, log_cfg); | |
84 | if (ret) { | |
85 | goto end; | |
86 | } | |
87 | } | |
88 | ||
89 | break; | |
90 | } | |
91 | case CTF_FIELD_CLASS_TYPE_ARRAY: | |
92 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
93 | { | |
94 | struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); | |
95 | ||
96 | ret = find_mapped_clock_class(array_fc->elem_fc, clock_class, log_cfg); | |
97 | if (ret) { | |
98 | goto end; | |
99 | } | |
100 | ||
101 | break; | |
102 | } | |
103 | default: | |
104 | break; | |
105 | } | |
44c440bc PP |
106 | |
107 | end: | |
4164020e | 108 | return ret; |
44c440bc PP |
109 | } |
110 | ||
4164020e SM |
111 | static inline int update_stream_class_default_clock_class(struct ctf_stream_class *stream_class, |
112 | struct meta_log_config *log_cfg) | |
44c440bc | 113 | { |
4164020e SM |
114 | int ret = 0; |
115 | struct ctf_clock_class *clock_class = stream_class->default_clock_class; | |
116 | uint64_t i; | |
117 | ||
118 | ret = find_mapped_clock_class(stream_class->packet_context_fc, &clock_class, log_cfg); | |
119 | if (ret) { | |
120 | goto end; | |
121 | } | |
122 | ||
123 | ret = find_mapped_clock_class(stream_class->event_header_fc, &clock_class, log_cfg); | |
124 | if (ret) { | |
125 | goto end; | |
126 | } | |
127 | ||
128 | ret = find_mapped_clock_class(stream_class->event_common_context_fc, &clock_class, log_cfg); | |
129 | if (ret) { | |
130 | goto end; | |
131 | } | |
132 | ||
133 | for (i = 0; i < stream_class->event_classes->len; i++) { | |
134 | struct ctf_event_class *event_class = | |
135 | (ctf_event_class *) stream_class->event_classes->pdata[i]; | |
136 | ||
137 | ret = find_mapped_clock_class(event_class->spec_context_fc, &clock_class, log_cfg); | |
138 | if (ret) { | |
139 | goto end; | |
140 | } | |
141 | ||
142 | ret = find_mapped_clock_class(event_class->payload_fc, &clock_class, log_cfg); | |
143 | if (ret) { | |
144 | goto end; | |
145 | } | |
146 | } | |
147 | ||
148 | if (!stream_class->default_clock_class) { | |
149 | stream_class->default_clock_class = clock_class; | |
150 | } | |
44c440bc PP |
151 | |
152 | end: | |
4164020e | 153 | return ret; |
44c440bc PP |
154 | } |
155 | ||
0746848c | 156 | int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class *ctf_tc, |
4164020e | 157 | struct meta_log_config *log_cfg) |
44c440bc | 158 | { |
4164020e SM |
159 | uint64_t i; |
160 | int ret = 0; | |
161 | struct ctf_clock_class *clock_class = NULL; | |
162 | ||
163 | ret = find_mapped_clock_class(ctf_tc->packet_header_fc, &clock_class, log_cfg); | |
164 | if (ret) { | |
165 | goto end; | |
166 | } | |
167 | ||
168 | if (clock_class) { | |
169 | ret = -1; | |
170 | goto end; | |
171 | } | |
172 | ||
173 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
174 | struct ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; | |
175 | ||
176 | ret = update_stream_class_default_clock_class( | |
177 | (ctf_stream_class *) ctf_tc->stream_classes->pdata[i], log_cfg); | |
178 | if (ret) { | |
179 | _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class contains more than one " | |
180 | "clock class: stream-class-id=%" PRIu64, | |
181 | sc->id); | |
182 | goto end; | |
183 | } | |
184 | } | |
44c440bc PP |
185 | |
186 | end: | |
4164020e | 187 | return ret; |
44c440bc | 188 | } |