Commit | Line | Data |
---|---|---|
ca9f27f3 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
ca9f27f3 FD |
3 | * |
4 | * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation | |
5 | * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
7 | * | |
0235b0db | 8 | * Babeltrace - Trace IR metadata object copy |
ca9f27f3 FD |
9 | */ |
10 | ||
91bc8451 | 11 | #define BT_COMP_LOG_SELF_COMP self_comp |
3a3d15f3 | 12 | #define BT_LOG_OUTPUT_LEVEL log_level |
350ad6c1 | 13 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-COPY" |
d9c39b0a | 14 | #include "logging/comp-logging.h" |
ca9f27f3 FD |
15 | |
16 | #include <inttypes.h> | |
17 | #include <stdint.h> | |
18 | ||
578e048b | 19 | #include "common/assert.h" |
ca9f27f3 FD |
20 | |
21 | #include "trace-ir-metadata-copy.h" | |
22 | #include "trace-ir-metadata-field-class-copy.h" | |
23 | #include "utils.h" | |
24 | ||
3b34b490 FD |
25 | enum debug_info_trace_ir_mapping_status copy_trace_class_content( |
26 | struct trace_ir_maps *ir_maps, | |
27 | const bt_trace_class *in_trace_class, | |
28 | bt_trace_class *out_trace_class, | |
db5d746d | 29 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 30 | { |
3b34b490 | 31 | enum debug_info_trace_ir_mapping_status status; |
db5d746d | 32 | uint64_t sc_number, sc_idx; |
3b34b490 | 33 | |
91bc8451 | 34 | BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
bc463d34 | 35 | in_trace_class, out_trace_class); |
ca9f27f3 | 36 | |
ce45f74a PP |
37 | /* |
38 | * Safe to use the same value object because it's frozen at this | |
39 | * point. | |
40 | */ | |
41 | bt_trace_class_set_user_attributes(out_trace_class, | |
42 | bt_trace_class_borrow_user_attributes_const(in_trace_class)); | |
43 | ||
ca9f27f3 FD |
44 | /* Use the same stream class ids as in the origin trace class. */ |
45 | bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class, | |
bc463d34 | 46 | BT_FALSE); |
db5d746d FD |
47 | |
48 | /* Copy stream classes contained in the trace class. */ | |
49 | sc_number = bt_trace_class_get_stream_class_count(in_trace_class); | |
50 | for (sc_idx = 0; sc_idx < sc_number; sc_idx++) { | |
51 | bt_stream_class *out_stream_class; | |
52 | const bt_stream_class *in_stream_class = | |
53 | bt_trace_class_borrow_stream_class_by_index_const( | |
54 | in_trace_class, sc_idx); | |
55 | ||
56 | out_stream_class = trace_ir_mapping_borrow_mapped_stream_class( | |
57 | ir_maps, in_stream_class); | |
58 | if (!out_stream_class) { | |
3b34b490 | 59 | out_stream_class = trace_ir_mapping_create_new_mapped_stream_class( |
db5d746d | 60 | ir_maps, in_stream_class); |
3b34b490 FD |
61 | if (!out_stream_class) { |
62 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
63 | goto end; | |
64 | } | |
db5d746d FD |
65 | } |
66 | } | |
67 | ||
91bc8451 | 68 | BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
bc463d34 | 69 | in_trace_class, out_trace_class); |
3b34b490 FD |
70 | |
71 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
72 | end: | |
73 | return status; | |
ca9f27f3 FD |
74 | } |
75 | ||
76 | static | |
3b34b490 FD |
77 | enum debug_info_trace_ir_mapping_status copy_clock_class_content( |
78 | const bt_clock_class *in_clock_class, | |
91bc8451 PP |
79 | bt_clock_class *out_clock_class, bt_logging_level log_level, |
80 | bt_self_component *self_comp) | |
ca9f27f3 | 81 | { |
3b34b490 | 82 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
83 | const char *clock_class_name, *clock_class_description; |
84 | int64_t seconds; | |
85 | uint64_t cycles; | |
86 | bt_uuid in_uuid; | |
ca9f27f3 | 87 | |
91bc8451 | 88 | BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
bc463d34 | 89 | in_clock_class, out_clock_class); |
ca9f27f3 FD |
90 | |
91 | clock_class_name = bt_clock_class_get_name(in_clock_class); | |
92 | ||
93 | if (clock_class_name) { | |
3b34b490 FD |
94 | enum bt_clock_class_set_name_status set_name_status = |
95 | bt_clock_class_set_name(out_clock_class, clock_class_name); | |
96 | if (set_name_status != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { | |
97 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
98 | "Error setting clock class' name: " | |
99 | "cc-addr=%p, name=%s", out_clock_class, | |
100 | clock_class_name); | |
101 | status = (int) set_name_status; | |
102 | goto end; | |
ca9f27f3 FD |
103 | } |
104 | } | |
105 | ||
ce45f74a PP |
106 | /* |
107 | * Safe to use the same value object because it's frozen at this | |
108 | * point. | |
109 | */ | |
110 | bt_clock_class_set_user_attributes(out_clock_class, | |
111 | bt_clock_class_borrow_user_attributes_const(in_clock_class)); | |
112 | ||
ca9f27f3 FD |
113 | clock_class_description = bt_clock_class_get_description(in_clock_class); |
114 | ||
115 | if (clock_class_description) { | |
3b34b490 FD |
116 | enum bt_clock_class_set_description_status set_desc_status = |
117 | bt_clock_class_set_description(out_clock_class, clock_class_description); | |
118 | if (set_desc_status!= BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { | |
119 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
120 | "Error setting clock class' description: " | |
121 | "cc-addr=%p, cc-desc=%s", out_clock_class, | |
122 | clock_class_description); | |
123 | status = (int) set_desc_status; | |
124 | goto end; | |
ca9f27f3 FD |
125 | } |
126 | } | |
127 | ||
128 | in_uuid = bt_clock_class_get_uuid(in_clock_class); | |
129 | if (in_uuid) { | |
130 | bt_clock_class_set_uuid(out_clock_class, in_uuid); | |
131 | } | |
132 | ||
133 | bt_clock_class_set_frequency(out_clock_class, | |
bc463d34 | 134 | bt_clock_class_get_frequency(in_clock_class)); |
ca9f27f3 | 135 | bt_clock_class_set_precision(out_clock_class, |
bc463d34 | 136 | bt_clock_class_get_precision(in_clock_class)); |
ca9f27f3 FD |
137 | bt_clock_class_get_offset(in_clock_class, &seconds, &cycles); |
138 | bt_clock_class_set_offset(out_clock_class, seconds, cycles); | |
139 | bt_clock_class_set_origin_is_unix_epoch(out_clock_class, | |
bc463d34 | 140 | bt_clock_class_origin_is_unix_epoch(in_clock_class)); |
ca9f27f3 | 141 | |
91bc8451 | 142 | BT_COMP_LOGD("Copied content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
bc463d34 | 143 | in_clock_class, out_clock_class); |
ca9f27f3 | 144 | |
3b34b490 FD |
145 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
146 | end: | |
147 | return status; | |
ca9f27f3 FD |
148 | } |
149 | ||
150 | static | |
151 | bt_clock_class *borrow_mapped_clock_class( | |
152 | struct trace_ir_metadata_maps *md_maps, | |
153 | const bt_clock_class *in_clock_class) | |
154 | { | |
98b15851 PP |
155 | BT_ASSERT_DBG(md_maps); |
156 | BT_ASSERT_DBG(in_clock_class); | |
ca9f27f3 FD |
157 | |
158 | return g_hash_table_lookup(md_maps->clock_class_map, | |
bc463d34 | 159 | (gpointer) in_clock_class); |
ca9f27f3 FD |
160 | } |
161 | ||
162 | static | |
bc463d34 | 163 | bt_clock_class *create_new_mapped_clock_class(bt_self_component *self_comp, |
ca9f27f3 FD |
164 | struct trace_ir_metadata_maps *md_maps, |
165 | const bt_clock_class *in_clock_class) | |
166 | { | |
3b34b490 | 167 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 | 168 | bt_clock_class *out_clock_class; |
3a3d15f3 | 169 | bt_logging_level log_level = md_maps->log_level; |
ca9f27f3 | 170 | |
91bc8451 | 171 | BT_COMP_LOGD("Creating new mapped clock class: in-cc-addr=%p", |
bc463d34 | 172 | in_clock_class); |
ca9f27f3 FD |
173 | |
174 | BT_ASSERT(md_maps); | |
175 | BT_ASSERT(in_clock_class); | |
176 | ||
177 | BT_ASSERT(!borrow_mapped_clock_class(md_maps, in_clock_class)); | |
178 | ||
179 | out_clock_class = bt_clock_class_create(self_comp); | |
180 | if (!out_clock_class) { | |
3b34b490 FD |
181 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
182 | "Cannot create clock class"); | |
ca9f27f3 FD |
183 | goto end; |
184 | } | |
185 | /* If not, create a new one and add it to the mapping. */ | |
3b34b490 | 186 | status = copy_clock_class_content(in_clock_class, out_clock_class, |
91bc8451 | 187 | log_level, self_comp); |
3b34b490 FD |
188 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
189 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
190 | "Cannot copy clock class"); | |
191 | BT_CLOCK_CLASS_PUT_REF_AND_RESET(out_clock_class); | |
ca9f27f3 FD |
192 | goto end; |
193 | } | |
194 | ||
195 | g_hash_table_insert(md_maps->clock_class_map, | |
bc463d34 | 196 | (gpointer) in_clock_class, out_clock_class); |
ca9f27f3 | 197 | |
91bc8451 | 198 | BT_COMP_LOGD("Created new mapped clock class: in-cc-addr=%p, out-cc-addr=%p", |
bc463d34 | 199 | in_clock_class, out_clock_class); |
ca9f27f3 FD |
200 | end: |
201 | return out_clock_class; | |
202 | } | |
203 | ||
3b34b490 FD |
204 | enum debug_info_trace_ir_mapping_status copy_stream_class_content( |
205 | struct trace_ir_maps *ir_maps, | |
ca9f27f3 FD |
206 | const bt_stream_class *in_stream_class, |
207 | bt_stream_class *out_stream_class) | |
208 | { | |
3b34b490 | 209 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
210 | struct trace_ir_metadata_maps *md_maps; |
211 | const bt_clock_class *in_clock_class; | |
212 | bt_clock_class *out_clock_class; | |
213 | const bt_field_class *in_packet_context_fc, *in_common_context_fc; | |
214 | bt_field_class *out_packet_context_fc, *out_common_context_fc; | |
ca9f27f3 | 215 | const char *in_name; |
db5d746d | 216 | uint64_t ec_number, ec_idx; |
3a3d15f3 | 217 | bt_logging_level log_level = ir_maps->log_level; |
91bc8451 | 218 | bt_self_component *self_comp = ir_maps->self_comp; |
ca9f27f3 | 219 | |
91bc8451 | 220 | BT_COMP_LOGD("Copying content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
bc463d34 | 221 | in_stream_class, out_stream_class); |
ca9f27f3 FD |
222 | |
223 | md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class); | |
224 | in_clock_class = bt_stream_class_borrow_default_clock_class_const( | |
bc463d34 | 225 | in_stream_class); |
ca9f27f3 FD |
226 | |
227 | if (in_clock_class) { | |
3b34b490 | 228 | enum bt_stream_class_set_default_clock_class_status set_def_cc_status; |
ca9f27f3 | 229 | /* Copy the clock class. */ |
bc463d34 FD |
230 | out_clock_class = borrow_mapped_clock_class(md_maps, |
231 | in_clock_class); | |
ca9f27f3 FD |
232 | if (!out_clock_class) { |
233 | out_clock_class = create_new_mapped_clock_class( | |
bc463d34 | 234 | ir_maps->self_comp, md_maps, in_clock_class); |
3b34b490 FD |
235 | if (!out_clock_class) { |
236 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
237 | goto end; | |
238 | } | |
239 | } | |
240 | set_def_cc_status = bt_stream_class_set_default_clock_class( | |
241 | out_stream_class, out_clock_class); | |
242 | if (set_def_cc_status != BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK) { | |
243 | status = (int) set_def_cc_status; | |
244 | goto end; | |
ca9f27f3 | 245 | } |
ca9f27f3 FD |
246 | } |
247 | ||
ce45f74a PP |
248 | /* |
249 | * Safe to use the same value object because it's frozen at this | |
250 | * point. | |
251 | */ | |
252 | bt_stream_class_set_user_attributes(out_stream_class, | |
253 | bt_stream_class_borrow_user_attributes_const(in_stream_class)); | |
254 | ||
26fc5aed | 255 | bt_stream_class_set_supports_packets( |
649934d2 | 256 | out_stream_class, |
26fc5aed | 257 | bt_stream_class_supports_packets(in_stream_class), |
9b24b6aa | 258 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
26fc5aed | 259 | in_stream_class), |
9b24b6aa | 260 | bt_stream_class_packets_have_end_default_clock_snapshot( |
649934d2 | 261 | in_stream_class)); |
2e90378a PP |
262 | bt_stream_class_set_supports_discarded_events( |
263 | out_stream_class, | |
264 | bt_stream_class_supports_discarded_events(in_stream_class), | |
265 | bt_stream_class_discarded_events_have_default_clock_snapshots( | |
266 | in_stream_class)); | |
267 | bt_stream_class_set_supports_discarded_packets( | |
268 | out_stream_class, | |
269 | bt_stream_class_supports_discarded_packets(in_stream_class), | |
270 | bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
271 | in_stream_class)); | |
649934d2 | 272 | |
ca9f27f3 FD |
273 | in_name = bt_stream_class_get_name(in_stream_class); |
274 | if (in_name) { | |
3b34b490 FD |
275 | enum bt_stream_class_set_name_status set_name_status = |
276 | bt_stream_class_set_name(out_stream_class, in_name); | |
277 | if (set_name_status != BT_STREAM_CLASS_SET_NAME_STATUS_OK) { | |
278 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
279 | "Error set stream class name: " | |
280 | "out-sc-addr=%p, name=%s", out_stream_class, | |
281 | in_name); | |
282 | status = (int) set_name_status; | |
283 | goto end; | |
ca9f27f3 FD |
284 | } |
285 | } | |
286 | ||
287 | bt_stream_class_set_assigns_automatic_stream_id(out_stream_class, | |
bc463d34 | 288 | BT_FALSE); |
ca9f27f3 | 289 | bt_stream_class_set_assigns_automatic_event_class_id(out_stream_class, |
bc463d34 | 290 | BT_FALSE); |
ca9f27f3 FD |
291 | |
292 | /* | |
293 | * Add the input packet context field class to the context to | |
294 | * resolution in the further steps. | |
295 | */ | |
296 | in_packet_context_fc = | |
297 | bt_stream_class_borrow_packet_context_field_class_const( | |
bc463d34 | 298 | in_stream_class); |
ca9f27f3 FD |
299 | md_maps->fc_resolving_ctx->packet_context = |
300 | in_packet_context_fc; | |
301 | ||
302 | if (in_packet_context_fc) { | |
3b34b490 | 303 | enum bt_stream_class_set_field_class_status set_fc_status; |
ca9f27f3 | 304 | /* Copy packet context. */ |
bc463d34 FD |
305 | out_packet_context_fc = create_field_class_copy(md_maps, |
306 | in_packet_context_fc); | |
ca9f27f3 | 307 | |
3b34b490 | 308 | status = copy_field_class_content(md_maps, in_packet_context_fc, |
bc463d34 | 309 | out_packet_context_fc); |
3b34b490 FD |
310 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
311 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
312 | "Error copying stream class' packet context field class: " | |
313 | "in-packet-ctx-fc-addr=%p, out-packet-ctx-fc-addr=%p", | |
314 | in_packet_context_fc, out_packet_context_fc); | |
315 | goto end; | |
ca9f27f3 FD |
316 | } |
317 | ||
3b34b490 FD |
318 | set_fc_status = bt_stream_class_set_packet_context_field_class( |
319 | out_stream_class, out_packet_context_fc); | |
320 | if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
321 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
322 | "Error setting stream class' packet context field class: " | |
323 | "out-sc-addr=%p, out-packet-ctx-fc-addr=%p", | |
ca9f27f3 | 324 | out_stream_class, out_packet_context_fc); |
3b34b490 FD |
325 | status = (int) set_fc_status; |
326 | goto end; | |
ca9f27f3 FD |
327 | } |
328 | } | |
329 | ||
330 | /* | |
331 | * Add the input common context field class to the context to | |
332 | * resolution in the further steps. | |
333 | */ | |
334 | in_common_context_fc = | |
335 | bt_stream_class_borrow_event_common_context_field_class_const( | |
bc463d34 FD |
336 | in_stream_class); |
337 | md_maps->fc_resolving_ctx->event_common_context = in_common_context_fc; | |
ca9f27f3 FD |
338 | |
339 | if (in_common_context_fc) { | |
3b34b490 | 340 | enum bt_stream_class_set_field_class_status set_fc_status; |
ca9f27f3 FD |
341 | /* Copy common context. */ |
342 | /* TODO: I find it a bit awkward to have this special function | |
343 | * here to add the debug-info field class. I would like to | |
344 | * abstract that.*/ | |
bc463d34 FD |
345 | out_common_context_fc = create_field_class_copy(md_maps, |
346 | in_common_context_fc); | |
3b34b490 | 347 | status = copy_event_common_context_field_class_content(md_maps, |
bc463d34 FD |
348 | ir_maps->debug_info_field_class_name, |
349 | in_common_context_fc, out_common_context_fc); | |
3b34b490 FD |
350 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
351 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
352 | "Error copying stream class' common context field class: " | |
353 | "in-comm-ctx-fc-addr=%p, out-comm-ctx-fc-addr=%p", | |
354 | in_common_context_fc, out_common_context_fc); | |
355 | goto end; | |
ca9f27f3 FD |
356 | } |
357 | ||
3b34b490 FD |
358 | set_fc_status = bt_stream_class_set_event_common_context_field_class( |
359 | out_stream_class, out_common_context_fc); | |
360 | if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
361 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
362 | "Error setting stream class' common context field class: " | |
363 | "out-sc-addr=%p, out-comm-ctx-fc-addr=%p", | |
ca9f27f3 | 364 | out_stream_class, out_common_context_fc); |
3b34b490 FD |
365 | status = (int) set_fc_status; |
366 | goto end; | |
ca9f27f3 FD |
367 | } |
368 | } | |
369 | ||
db5d746d FD |
370 | /* Copy event classes contained in the stream class. */ |
371 | ec_number = bt_stream_class_get_event_class_count(in_stream_class); | |
372 | for (ec_idx = 0; ec_idx < ec_number; ec_idx++) { | |
373 | bt_event_class *out_event_class; | |
374 | const bt_event_class *in_event_class = | |
375 | bt_stream_class_borrow_event_class_by_id_const( | |
376 | in_stream_class, ec_idx); | |
377 | out_event_class = trace_ir_mapping_borrow_mapped_event_class( | |
378 | ir_maps, in_event_class); | |
379 | if (!out_event_class) { | |
380 | /* | |
381 | * We don't need the new event_class yet. We simply | |
382 | * want to create it and keep it in the map. | |
383 | */ | |
3b34b490 | 384 | out_event_class = trace_ir_mapping_create_new_mapped_event_class( |
db5d746d | 385 | ir_maps, in_event_class); |
3b34b490 FD |
386 | if (!out_event_class) { |
387 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
388 | goto end; | |
389 | } | |
db5d746d FD |
390 | } |
391 | } | |
392 | ||
91bc8451 | 393 | BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
bc463d34 | 394 | in_stream_class, out_stream_class); |
3b34b490 FD |
395 | |
396 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
397 | end: | |
398 | return status; | |
ca9f27f3 FD |
399 | } |
400 | ||
3b34b490 FD |
401 | enum debug_info_trace_ir_mapping_status copy_event_class_content( |
402 | struct trace_ir_maps *ir_maps, | |
ca9f27f3 FD |
403 | const bt_event_class *in_event_class, |
404 | bt_event_class *out_event_class) | |
405 | { | |
3b34b490 | 406 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
407 | struct trace_ir_metadata_maps *md_maps; |
408 | const char *in_event_class_name, *in_emf_uri; | |
409 | bt_property_availability prop_avail; | |
3a3d15f3 | 410 | bt_event_class_log_level ec_log_level; |
ca9f27f3 FD |
411 | bt_field_class *out_specific_context_fc, *out_payload_fc; |
412 | const bt_field_class *in_event_specific_context, *in_event_payload; | |
3a3d15f3 | 413 | bt_logging_level log_level = ir_maps->log_level; |
91bc8451 | 414 | bt_self_component *self_comp = ir_maps->self_comp; |
ca9f27f3 | 415 | |
91bc8451 | 416 | BT_COMP_LOGD("Copying content of event class: in-ec-addr=%p, out-ec-addr=%p", |
bc463d34 | 417 | in_event_class, out_event_class); |
ca9f27f3 FD |
418 | |
419 | /* Copy event class name. */ | |
420 | in_event_class_name = bt_event_class_get_name(in_event_class); | |
421 | if (in_event_class_name) { | |
3b34b490 FD |
422 | enum bt_event_class_set_name_status set_name_status = |
423 | bt_event_class_set_name(out_event_class, in_event_class_name); | |
424 | if (set_name_status != BT_EVENT_CLASS_SET_NAME_STATUS_OK) { | |
425 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' name: ec-addr=%p, " | |
ca9f27f3 | 426 | "name=%s", out_event_class, in_event_class_name); |
3b34b490 FD |
427 | status = (int) set_name_status; |
428 | goto end; | |
ca9f27f3 FD |
429 | } |
430 | } | |
431 | ||
ce45f74a PP |
432 | /* |
433 | * Safe to use the same value object because it's frozen at this | |
434 | * point. | |
435 | */ | |
436 | bt_event_class_set_user_attributes(out_event_class, | |
437 | bt_event_class_borrow_user_attributes_const(in_event_class)); | |
438 | ||
ca9f27f3 | 439 | /* Copy event class loglevel. */ |
3a3d15f3 PP |
440 | prop_avail = bt_event_class_get_log_level(in_event_class, |
441 | &ec_log_level); | |
ca9f27f3 | 442 | if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { |
bc463d34 | 443 | bt_event_class_set_log_level(out_event_class, ec_log_level); |
ca9f27f3 FD |
444 | } |
445 | ||
446 | /* Copy event class emf uri. */ | |
447 | in_emf_uri = bt_event_class_get_emf_uri(in_event_class); | |
448 | if (in_emf_uri) { | |
3b34b490 FD |
449 | enum bt_event_class_set_emf_uri_status set_emf_status = |
450 | bt_event_class_set_emf_uri(out_event_class, in_emf_uri); | |
451 | if (set_emf_status != BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { | |
452 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
453 | "Error setting event class' emf uri: " | |
454 | "out-ec-addr=%p, emf-uri=\"%s\"", | |
455 | out_event_class, in_emf_uri); | |
456 | status = (int) set_emf_status; | |
457 | goto end; | |
ca9f27f3 FD |
458 | } |
459 | } | |
460 | ||
bc463d34 FD |
461 | md_maps = borrow_metadata_maps_from_input_event_class(ir_maps, |
462 | in_event_class); | |
ca9f27f3 FD |
463 | /* |
464 | * Add the input event class' specific ctx to te | |
465 | * context. | |
466 | */ | |
467 | in_event_specific_context = | |
468 | bt_event_class_borrow_specific_context_field_class_const( | |
bc463d34 | 469 | in_event_class); |
ca9f27f3 FD |
470 | |
471 | md_maps->fc_resolving_ctx->event_specific_context = | |
472 | in_event_specific_context; | |
473 | ||
474 | if (in_event_specific_context) { | |
3b34b490 | 475 | enum bt_event_class_set_field_class_status set_fc_status; |
ca9f27f3 FD |
476 | /* Copy the specific context of this event class. */ |
477 | out_specific_context_fc = create_field_class_copy(md_maps, | |
bc463d34 | 478 | in_event_specific_context); |
ca9f27f3 | 479 | |
3b34b490 | 480 | status = copy_field_class_content(md_maps, |
bc463d34 | 481 | in_event_specific_context, out_specific_context_fc); |
3b34b490 FD |
482 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
483 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
484 | "Error copying event class' specific context field class:" | |
485 | "in-spec-ctx-fc-addr=%p, out-spec-ctx-fc-addr=%p", | |
486 | in_event_specific_context, out_specific_context_fc); | |
487 | goto end; | |
ca9f27f3 FD |
488 | } |
489 | /* | |
490 | * Add the output specific context to the output event | |
491 | * class. | |
492 | */ | |
3b34b490 | 493 | set_fc_status = bt_event_class_set_specific_context_field_class( |
ca9f27f3 | 494 | out_event_class, out_specific_context_fc); |
3b34b490 FD |
495 | if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { |
496 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
497 | "Error setting event class' specific context field class:" | |
498 | "out-ec-addr=%p, out-spec-ctx-fc-addr=%p", | |
499 | out_event_class, out_specific_context_fc); | |
500 | status = (int) set_fc_status; | |
501 | goto end; | |
ca9f27f3 FD |
502 | } |
503 | } | |
504 | ||
505 | /* | |
506 | * Add the input event class' payload field class to | |
507 | * the context. | |
508 | */ | |
509 | in_event_payload = bt_event_class_borrow_payload_field_class_const( | |
bc463d34 | 510 | in_event_class); |
ca9f27f3 FD |
511 | |
512 | md_maps->fc_resolving_ctx->event_payload = in_event_payload; | |
513 | ||
514 | if (in_event_payload) { | |
3b34b490 FD |
515 | enum bt_event_class_set_field_class_status set_fc_status; |
516 | /* Copy the payload of this event class. */ | |
ca9f27f3 | 517 | out_payload_fc = create_field_class_copy(md_maps, |
bc463d34 | 518 | in_event_payload); |
3b34b490 | 519 | status = copy_field_class_content(md_maps, in_event_payload, |
bc463d34 | 520 | out_payload_fc); |
3b34b490 FD |
521 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
522 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
523 | "Error copying event class' specific context field class:" | |
524 | "in-payload-fc-addr=%p, out-payload-fc-addr=%p", | |
525 | in_event_payload, out_payload_fc); | |
526 | goto end; | |
ca9f27f3 FD |
527 | } |
528 | ||
529 | /* Add the output payload to the output event class. */ | |
3b34b490 FD |
530 | set_fc_status = bt_event_class_set_payload_field_class( |
531 | out_event_class, out_payload_fc); | |
532 | if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
533 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' payload field class: " | |
534 | "out-ec-addr=%p, out-payload-fc-addr=%p", | |
ca9f27f3 | 535 | out_event_class, out_payload_fc); |
3b34b490 FD |
536 | status = (int) set_fc_status; |
537 | goto end; | |
ca9f27f3 FD |
538 | } |
539 | } | |
540 | ||
91bc8451 | 541 | BT_COMP_LOGD("Copied content of event class: in-ec-addr=%p, out-ec-addr=%p", |
bc463d34 | 542 | in_event_class, out_event_class); |
3b34b490 FD |
543 | |
544 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
545 | end: | |
546 | return status; | |
ca9f27f3 FD |
547 | } |
548 | ||
3b34b490 FD |
549 | enum debug_info_trace_ir_mapping_status |
550 | copy_event_common_context_field_class_content( | |
ca9f27f3 FD |
551 | struct trace_ir_metadata_maps *md_maps, |
552 | const char *debug_info_fc_name, | |
553 | const bt_field_class *in_field_class, | |
554 | bt_field_class *out_field_class) | |
555 | { | |
3b34b490 | 556 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
557 | bt_field_class *debug_field_class = NULL, *bin_field_class = NULL, |
558 | *func_field_class = NULL, *src_field_class = NULL; | |
3a3d15f3 | 559 | bt_logging_level log_level = md_maps->log_level; |
91bc8451 | 560 | bt_self_component *self_comp = md_maps->self_comp; |
ca9f27f3 | 561 | |
91bc8451 | 562 | BT_COMP_LOGD("Copying content of event common context field class: " |
ca9f27f3 FD |
563 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
564 | ||
565 | /* Copy the content of the input common context. */ | |
3b34b490 FD |
566 | status = copy_field_class_content(md_maps, in_field_class, out_field_class); |
567 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { | |
568 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
569 | "Error copying content of event common context field class: " | |
570 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, | |
571 | out_field_class); | |
ca9f27f3 FD |
572 | goto error; |
573 | } | |
574 | ||
575 | /* | |
576 | * If this event common context has the necessary fields to compute the | |
577 | * debug information append the debug-info field class to the event | |
578 | * common context. | |
579 | */ | |
580 | if (is_event_common_ctx_dbg_info_compatible(in_field_class, debug_info_fc_name)) { | |
3b34b490 | 581 | enum bt_field_class_structure_append_member_status append_member_status; |
ca9f27f3 FD |
582 | /* |
583 | * The struct field and 3 sub-fields are not stored in the | |
584 | * field class map because they don't have input equivalent. | |
585 | * We need to put our reference each of these field classes | |
586 | * once they are added to their respective containing field | |
587 | * classes. | |
588 | */ | |
589 | debug_field_class = bt_field_class_structure_create( | |
bc463d34 | 590 | md_maps->output_trace_class); |
ca9f27f3 | 591 | if (!debug_field_class) { |
3b34b490 FD |
592 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
593 | "Failed to create debug_info structure."); | |
594 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
ca9f27f3 FD |
595 | goto error; |
596 | } | |
597 | ||
598 | bin_field_class = bt_field_class_string_create( | |
bc463d34 | 599 | md_maps->output_trace_class); |
ca9f27f3 | 600 | if (!bin_field_class) { |
3b34b490 FD |
601 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
602 | "Failed to create string for field=\"bin\"."); | |
603 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
ca9f27f3 FD |
604 | goto error; |
605 | } | |
606 | ||
607 | func_field_class = bt_field_class_string_create( | |
bc463d34 | 608 | md_maps->output_trace_class); |
ca9f27f3 | 609 | if (!func_field_class) { |
3b34b490 FD |
610 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
611 | "Failed to create string for field=\"func\"."); | |
612 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
ca9f27f3 FD |
613 | goto error; |
614 | } | |
615 | ||
616 | src_field_class = bt_field_class_string_create( | |
bc463d34 | 617 | md_maps->output_trace_class); |
ca9f27f3 | 618 | if (!src_field_class) { |
3b34b490 FD |
619 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
620 | "Failed to create string for field=\"src\"."); | |
621 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; | |
ca9f27f3 FD |
622 | goto error; |
623 | } | |
624 | ||
3b34b490 FD |
625 | append_member_status = bt_field_class_structure_append_member( |
626 | debug_field_class, "bin", bin_field_class); | |
627 | if (append_member_status != | |
d24d5663 | 628 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
3b34b490 FD |
629 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
630 | "Failed to add a field to debug_info struct: " | |
631 | "field=\"bin\"."); | |
632 | status = (int) append_member_status; | |
ca9f27f3 FD |
633 | goto error; |
634 | } | |
635 | BT_FIELD_CLASS_PUT_REF_AND_RESET(bin_field_class); | |
636 | ||
3b34b490 FD |
637 | append_member_status = bt_field_class_structure_append_member( |
638 | debug_field_class, "func", func_field_class); | |
639 | if (append_member_status != | |
d24d5663 | 640 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
3b34b490 FD |
641 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
642 | "Failed to add a field to debug_info struct: " | |
643 | "field=\"func\"."); | |
644 | status = (int) append_member_status; | |
ca9f27f3 FD |
645 | goto error; |
646 | } | |
647 | BT_FIELD_CLASS_PUT_REF_AND_RESET(func_field_class); | |
648 | ||
3b34b490 FD |
649 | append_member_status = bt_field_class_structure_append_member( |
650 | debug_field_class, "src", src_field_class); | |
651 | if (append_member_status != | |
d24d5663 | 652 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
3b34b490 FD |
653 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
654 | "Failed to add a field to debug_info struct: " | |
655 | "field=\"src\"."); | |
656 | status = (int) append_member_status; | |
ca9f27f3 FD |
657 | goto error; |
658 | } | |
659 | BT_FIELD_CLASS_PUT_REF_AND_RESET(src_field_class); | |
660 | ||
661 | /*Add the filled debug-info field class to the common context. */ | |
3b34b490 FD |
662 | append_member_status = bt_field_class_structure_append_member( |
663 | out_field_class, debug_info_fc_name, debug_field_class); | |
664 | if (append_member_status != | |
d24d5663 | 665 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
3b34b490 FD |
666 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
667 | "Failed to add debug_info field to event common context."); | |
668 | status = (int) append_member_status; | |
ca9f27f3 FD |
669 | goto error; |
670 | } | |
671 | BT_FIELD_CLASS_PUT_REF_AND_RESET(debug_field_class); | |
672 | } | |
91bc8451 | 673 | BT_COMP_LOGD("Copied content of event common context field class: " |
ca9f27f3 | 674 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
3b34b490 FD |
675 | |
676 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
ca9f27f3 FD |
677 | goto end; |
678 | ||
679 | error: | |
680 | if (debug_field_class) { | |
681 | bt_field_class_put_ref(debug_field_class); | |
682 | } | |
683 | if (bin_field_class) { | |
684 | bt_field_class_put_ref(bin_field_class); | |
685 | } | |
686 | if (func_field_class) { | |
687 | bt_field_class_put_ref(func_field_class); | |
688 | } | |
689 | if (src_field_class) { | |
690 | bt_field_class_put_ref(src_field_class); | |
691 | } | |
692 | end: | |
3b34b490 | 693 | return status; |
ca9f27f3 FD |
694 | } |
695 | ||
ca9f27f3 FD |
696 | bt_field_class *create_field_class_copy(struct trace_ir_metadata_maps *md_maps, |
697 | const bt_field_class *in_field_class) | |
698 | { | |
699 | return create_field_class_copy_internal(md_maps, in_field_class); | |
700 | } | |
701 | ||
3b34b490 FD |
702 | enum debug_info_trace_ir_mapping_status copy_field_class_content( |
703 | struct trace_ir_metadata_maps *md_maps, | |
ca9f27f3 FD |
704 | const bt_field_class *in_field_class, |
705 | bt_field_class *out_field_class) | |
706 | { | |
707 | return copy_field_class_content_internal(md_maps, in_field_class, | |
708 | out_field_class); | |
709 | } |