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