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" |
91bc8451 | 30 | #include "plugins/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 | |
42 | int copy_trace_class_content(const bt_trace_class *in_trace_class, | |
91bc8451 PP |
43 | bt_trace_class *out_trace_class, bt_logging_level log_level, |
44 | bt_self_component *self_comp) | |
ca9f27f3 FD |
45 | { |
46 | int ret = 0; | |
47 | uint64_t i, env_field_count; | |
48 | const char *in_trace_class_name; | |
ca9f27f3 | 49 | |
91bc8451 | 50 | BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
ca9f27f3 FD |
51 | in_trace_class, out_trace_class); |
52 | ||
53 | /* Use the same stream class ids as in the origin trace class. */ | |
54 | bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class, | |
55 | BT_FALSE); | |
56 | ||
57 | in_trace_class_name = bt_trace_class_get_name(in_trace_class); | |
58 | if (in_trace_class_name) { | |
b80991f6 PP |
59 | bt_trace_class_set_name_status status; |
60 | ||
61 | status = bt_trace_class_set_name(out_trace_class, | |
62 | in_trace_class_name); | |
63 | if (status != BT_TRACE_CLASS_SET_NAME_STATUS_OK) { | |
64 | bt_current_thread_clear_error(); | |
65 | } | |
ca9f27f3 FD |
66 | } |
67 | ||
2d836ebb FD |
68 | /* |
69 | * Do not copy the trace class UUID as it may be modified and should no | |
70 | * longer have the same UUID. | |
71 | */ | |
ca9f27f3 FD |
72 | |
73 | /* | |
74 | * Go over all the entries in the environment section of the trace class | |
75 | * and copy the content to the new trace class. | |
76 | */ | |
77 | env_field_count = bt_trace_class_get_environment_entry_count(in_trace_class); | |
78 | for (i = 0; i < env_field_count; i++) { | |
79 | const char *value_name; | |
80 | const bt_value *value = NULL; | |
d24d5663 | 81 | bt_trace_class_set_environment_entry_status set_env_status; |
ca9f27f3 FD |
82 | |
83 | bt_trace_class_borrow_environment_entry_by_index_const( | |
84 | in_trace_class, i, &value_name, &value); | |
85 | ||
91bc8451 | 86 | BT_COMP_LOGD("Copying trace class environnement entry: " |
ca9f27f3 FD |
87 | "index=%" PRId64 ", value-addr=%p, value-name=%s", |
88 | i, value, value_name); | |
89 | ||
90 | BT_ASSERT(value_name); | |
91 | BT_ASSERT(value); | |
92 | ||
fdd3a2da | 93 | if (bt_value_is_signed_integer(value)) { |
d24d5663 | 94 | set_env_status = |
ca9f27f3 FD |
95 | bt_trace_class_set_environment_entry_integer( |
96 | out_trace_class, value_name, | |
fdd3a2da PP |
97 | bt_value_signed_integer_get( |
98 | value)); | |
ca9f27f3 | 99 | } else if (bt_value_is_string(value)) { |
d24d5663 | 100 | set_env_status = |
ca9f27f3 FD |
101 | bt_trace_class_set_environment_entry_string( |
102 | out_trace_class, value_name, | |
103 | bt_value_string_get(value)); | |
104 | } else { | |
105 | abort(); | |
106 | } | |
107 | ||
d24d5663 PP |
108 | if (set_env_status != |
109 | BT_TRACE_CLASS_SET_ENVIRONMENT_ENTRY_STATUS_OK) { | |
ca9f27f3 FD |
110 | ret = -1; |
111 | goto error; | |
112 | } | |
113 | } | |
114 | ||
91bc8451 | 115 | BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
ca9f27f3 FD |
116 | in_trace_class, out_trace_class); |
117 | error: | |
118 | return ret; | |
119 | } | |
120 | ||
121 | static | |
122 | int copy_clock_class_content(const bt_clock_class *in_clock_class, | |
91bc8451 PP |
123 | bt_clock_class *out_clock_class, bt_logging_level log_level, |
124 | bt_self_component *self_comp) | |
ca9f27f3 | 125 | { |
ca9f27f3 FD |
126 | const char *clock_class_name, *clock_class_description; |
127 | int64_t seconds; | |
128 | uint64_t cycles; | |
129 | bt_uuid in_uuid; | |
130 | int ret = 0; | |
131 | ||
91bc8451 | 132 | BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
ca9f27f3 FD |
133 | in_clock_class, out_clock_class); |
134 | ||
135 | clock_class_name = bt_clock_class_get_name(in_clock_class); | |
136 | ||
137 | if (clock_class_name) { | |
d24d5663 PP |
138 | if (bt_clock_class_set_name(out_clock_class, clock_class_name) |
139 | != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { | |
91bc8451 | 140 | BT_COMP_LOGE("Error setting clock class' name cc-addr=%p, name=%p", |
ca9f27f3 FD |
141 | out_clock_class, clock_class_name); |
142 | out_clock_class = NULL; | |
143 | ret = -1; | |
144 | goto error; | |
145 | } | |
146 | } | |
147 | ||
148 | clock_class_description = bt_clock_class_get_description(in_clock_class); | |
149 | ||
150 | if (clock_class_description) { | |
d24d5663 PP |
151 | if (bt_clock_class_set_description(out_clock_class, |
152 | clock_class_description) != | |
153 | BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { | |
91bc8451 | 154 | BT_COMP_LOGE("Error setting clock class' description cc-addr=%p, " |
ca9f27f3 FD |
155 | "name=%p", out_clock_class, clock_class_description); |
156 | out_clock_class = NULL; | |
157 | ret = -1; | |
158 | goto error; | |
159 | } | |
160 | } | |
161 | ||
162 | in_uuid = bt_clock_class_get_uuid(in_clock_class); | |
163 | if (in_uuid) { | |
164 | bt_clock_class_set_uuid(out_clock_class, in_uuid); | |
165 | } | |
166 | ||
167 | bt_clock_class_set_frequency(out_clock_class, | |
168 | bt_clock_class_get_frequency(in_clock_class)); | |
169 | bt_clock_class_set_precision(out_clock_class, | |
170 | bt_clock_class_get_precision(in_clock_class)); | |
171 | bt_clock_class_get_offset(in_clock_class, &seconds, &cycles); | |
172 | bt_clock_class_set_offset(out_clock_class, seconds, cycles); | |
173 | bt_clock_class_set_origin_is_unix_epoch(out_clock_class, | |
174 | bt_clock_class_origin_is_unix_epoch(in_clock_class)); | |
175 | ||
91bc8451 | 176 | BT_COMP_LOGD("Copied content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
ca9f27f3 FD |
177 | in_clock_class, out_clock_class); |
178 | ||
179 | error: | |
180 | return ret; | |
181 | } | |
182 | ||
183 | static | |
184 | bt_clock_class *borrow_mapped_clock_class( | |
185 | struct trace_ir_metadata_maps *md_maps, | |
186 | const bt_clock_class *in_clock_class) | |
187 | { | |
188 | BT_ASSERT(md_maps); | |
189 | BT_ASSERT(in_clock_class); | |
190 | ||
191 | return g_hash_table_lookup(md_maps->clock_class_map, | |
192 | (gpointer) in_clock_class); | |
193 | } | |
194 | ||
195 | static | |
196 | bt_clock_class *create_new_mapped_clock_class( | |
197 | bt_self_component *self_comp, | |
198 | struct trace_ir_metadata_maps *md_maps, | |
199 | const bt_clock_class *in_clock_class) | |
200 | { | |
201 | bt_clock_class *out_clock_class; | |
202 | int ret; | |
3a3d15f3 | 203 | bt_logging_level log_level = md_maps->log_level; |
ca9f27f3 | 204 | |
91bc8451 | 205 | BT_COMP_LOGD("Creating new mapped clock class: in-cc-addr=%p", |
ca9f27f3 FD |
206 | in_clock_class); |
207 | ||
208 | BT_ASSERT(md_maps); | |
209 | BT_ASSERT(in_clock_class); | |
210 | ||
211 | BT_ASSERT(!borrow_mapped_clock_class(md_maps, in_clock_class)); | |
212 | ||
213 | out_clock_class = bt_clock_class_create(self_comp); | |
214 | if (!out_clock_class) { | |
91bc8451 | 215 | BT_COMP_LOGE_STR("Cannot create clock class"); |
ca9f27f3 FD |
216 | goto end; |
217 | } | |
218 | /* If not, create a new one and add it to the mapping. */ | |
3a3d15f3 | 219 | ret = copy_clock_class_content(in_clock_class, out_clock_class, |
91bc8451 | 220 | log_level, self_comp); |
ca9f27f3 | 221 | if (ret) { |
91bc8451 | 222 | BT_COMP_LOGE_STR("Cannot copy clock class"); |
ca9f27f3 FD |
223 | goto end; |
224 | } | |
225 | ||
226 | g_hash_table_insert(md_maps->clock_class_map, | |
227 | (gpointer) in_clock_class, out_clock_class); | |
228 | ||
91bc8451 | 229 | BT_COMP_LOGD("Created new mapped clock class: in-cc-addr=%p, out-cc-addr=%p", |
ca9f27f3 FD |
230 | in_clock_class, out_clock_class); |
231 | end: | |
232 | return out_clock_class; | |
233 | } | |
234 | ||
235 | BT_HIDDEN | |
236 | int copy_stream_class_content(struct trace_ir_maps *ir_maps, | |
237 | const bt_stream_class *in_stream_class, | |
238 | bt_stream_class *out_stream_class) | |
239 | { | |
240 | struct trace_ir_metadata_maps *md_maps; | |
241 | const bt_clock_class *in_clock_class; | |
242 | bt_clock_class *out_clock_class; | |
243 | const bt_field_class *in_packet_context_fc, *in_common_context_fc; | |
244 | bt_field_class *out_packet_context_fc, *out_common_context_fc; | |
ca9f27f3 FD |
245 | const char *in_name; |
246 | int ret = 0; | |
3a3d15f3 | 247 | bt_logging_level log_level = ir_maps->log_level; |
91bc8451 | 248 | bt_self_component *self_comp = ir_maps->self_comp; |
ca9f27f3 | 249 | |
91bc8451 | 250 | BT_COMP_LOGD("Copying content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
ca9f27f3 FD |
251 | in_stream_class, out_stream_class); |
252 | ||
253 | md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class); | |
254 | in_clock_class = bt_stream_class_borrow_default_clock_class_const( | |
255 | in_stream_class); | |
256 | ||
257 | if (in_clock_class) { | |
258 | /* Copy the clock class. */ | |
259 | out_clock_class = | |
260 | borrow_mapped_clock_class(md_maps, in_clock_class); | |
261 | if (!out_clock_class) { | |
262 | out_clock_class = create_new_mapped_clock_class( | |
263 | ir_maps->self_comp, md_maps, | |
264 | in_clock_class); | |
265 | } | |
266 | bt_stream_class_set_default_clock_class(out_stream_class, | |
267 | out_clock_class); | |
268 | ||
269 | } | |
270 | ||
9b24b6aa | 271 | bt_stream_class_set_packets_have_beginning_default_clock_snapshot( |
649934d2 | 272 | out_stream_class, |
9b24b6aa | 273 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
649934d2 | 274 | in_stream_class)); |
9b24b6aa | 275 | bt_stream_class_set_packets_have_end_default_clock_snapshot( |
649934d2 | 276 | out_stream_class, |
9b24b6aa | 277 | bt_stream_class_packets_have_end_default_clock_snapshot( |
649934d2 | 278 | in_stream_class)); |
2e90378a PP |
279 | bt_stream_class_set_supports_discarded_events( |
280 | out_stream_class, | |
281 | bt_stream_class_supports_discarded_events(in_stream_class), | |
282 | bt_stream_class_discarded_events_have_default_clock_snapshots( | |
283 | in_stream_class)); | |
284 | bt_stream_class_set_supports_discarded_packets( | |
285 | out_stream_class, | |
286 | bt_stream_class_supports_discarded_packets(in_stream_class), | |
287 | bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
288 | in_stream_class)); | |
649934d2 | 289 | |
ca9f27f3 FD |
290 | in_name = bt_stream_class_get_name(in_stream_class); |
291 | if (in_name) { | |
d24d5663 PP |
292 | if (bt_stream_class_set_name(out_stream_class, in_name) != |
293 | BT_STREAM_CLASS_SET_NAME_STATUS_OK) { | |
91bc8451 | 294 | BT_COMP_LOGE("Error set stream class name: out-sc-addr=%p, " |
ca9f27f3 FD |
295 | "name=%s", out_stream_class, in_name); |
296 | ret = -1; | |
297 | goto error; | |
298 | } | |
299 | } | |
300 | ||
301 | bt_stream_class_set_assigns_automatic_stream_id(out_stream_class, | |
302 | BT_FALSE); | |
303 | bt_stream_class_set_assigns_automatic_event_class_id(out_stream_class, | |
304 | BT_FALSE); | |
305 | ||
306 | /* | |
307 | * Add the input packet context field class to the context to | |
308 | * resolution in the further steps. | |
309 | */ | |
310 | in_packet_context_fc = | |
311 | bt_stream_class_borrow_packet_context_field_class_const( | |
312 | in_stream_class); | |
313 | md_maps->fc_resolving_ctx->packet_context = | |
314 | in_packet_context_fc; | |
315 | ||
316 | if (in_packet_context_fc) { | |
317 | /* Copy packet context. */ | |
318 | out_packet_context_fc = create_field_class_copy( | |
319 | md_maps, in_packet_context_fc); | |
320 | ||
321 | ret = copy_field_class_content(md_maps, | |
322 | in_packet_context_fc, out_packet_context_fc); | |
323 | if (ret) { | |
324 | ret = -1; | |
325 | goto error; | |
326 | } | |
327 | ||
d24d5663 PP |
328 | if (bt_stream_class_set_packet_context_field_class( |
329 | out_stream_class, out_packet_context_fc) != | |
330 | BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
91bc8451 | 331 | BT_COMP_LOGE("Error setting stream class' packet context " |
ca9f27f3 FD |
332 | "field class: sc-addr=%p, packet-fc-addr=%p", |
333 | out_stream_class, out_packet_context_fc); | |
334 | ret = -1; | |
335 | goto error; | |
336 | } | |
337 | } | |
338 | ||
339 | /* | |
340 | * Add the input common context field class to the context to | |
341 | * resolution in the further steps. | |
342 | */ | |
343 | in_common_context_fc = | |
344 | bt_stream_class_borrow_event_common_context_field_class_const( | |
345 | in_stream_class); | |
346 | md_maps->fc_resolving_ctx->event_common_context = | |
347 | in_common_context_fc; | |
348 | ||
349 | if (in_common_context_fc) { | |
350 | /* Copy common context. */ | |
351 | /* TODO: I find it a bit awkward to have this special function | |
352 | * here to add the debug-info field class. I would like to | |
353 | * abstract that.*/ | |
354 | out_common_context_fc = create_field_class_copy( | |
355 | md_maps, in_common_context_fc); | |
356 | ||
357 | ret = copy_event_common_context_field_class_content( | |
358 | md_maps, ir_maps->debug_info_field_class_name, | |
359 | in_common_context_fc, out_common_context_fc); | |
360 | if (ret) { | |
361 | goto error; | |
362 | } | |
363 | ||
d24d5663 PP |
364 | if (bt_stream_class_set_event_common_context_field_class( |
365 | out_stream_class, out_common_context_fc) != | |
366 | BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
91bc8451 | 367 | BT_COMP_LOGE("Error setting stream class' packet context " |
ca9f27f3 FD |
368 | "field class: sc-addr=%p, packet-fc-addr=%p", |
369 | out_stream_class, out_common_context_fc); | |
370 | ret = -1; | |
371 | goto error; | |
372 | } | |
373 | } | |
374 | ||
375 | /* Set packet snapshot boolean fields. */ | |
91bc8451 | 376 | BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
ca9f27f3 FD |
377 | in_stream_class, out_stream_class); |
378 | error: | |
379 | return ret; | |
380 | } | |
381 | ||
382 | BT_HIDDEN | |
383 | int copy_event_class_content(struct trace_ir_maps *ir_maps, | |
384 | const bt_event_class *in_event_class, | |
385 | bt_event_class *out_event_class) | |
386 | { | |
387 | struct trace_ir_metadata_maps *md_maps; | |
388 | const char *in_event_class_name, *in_emf_uri; | |
389 | bt_property_availability prop_avail; | |
3a3d15f3 | 390 | bt_event_class_log_level ec_log_level; |
ca9f27f3 FD |
391 | bt_field_class *out_specific_context_fc, *out_payload_fc; |
392 | const bt_field_class *in_event_specific_context, *in_event_payload; | |
393 | int ret = 0; | |
3a3d15f3 | 394 | bt_logging_level log_level = ir_maps->log_level; |
91bc8451 | 395 | bt_self_component *self_comp = ir_maps->self_comp; |
ca9f27f3 | 396 | |
91bc8451 | 397 | BT_COMP_LOGD("Copying content of event class: in-ec-addr=%p, out-ec-addr=%p", |
ca9f27f3 FD |
398 | in_event_class, out_event_class); |
399 | ||
400 | /* Copy event class name. */ | |
401 | in_event_class_name = bt_event_class_get_name(in_event_class); | |
402 | if (in_event_class_name) { | |
d24d5663 PP |
403 | if (bt_event_class_set_name(out_event_class, |
404 | in_event_class_name) != | |
405 | BT_EVENT_CLASS_SET_NAME_STATUS_OK) { | |
91bc8451 | 406 | BT_COMP_LOGE("Error setting event class' name: ec-addr=%p, " |
ca9f27f3 FD |
407 | "name=%s", out_event_class, in_event_class_name); |
408 | ret = -1; | |
409 | goto error; | |
410 | } | |
411 | } | |
412 | ||
413 | /* Copy event class loglevel. */ | |
3a3d15f3 PP |
414 | prop_avail = bt_event_class_get_log_level(in_event_class, |
415 | &ec_log_level); | |
ca9f27f3 FD |
416 | if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { |
417 | bt_event_class_set_log_level(out_event_class, | |
3a3d15f3 | 418 | ec_log_level); |
ca9f27f3 FD |
419 | } |
420 | ||
421 | /* Copy event class emf uri. */ | |
422 | in_emf_uri = bt_event_class_get_emf_uri(in_event_class); | |
423 | if (in_emf_uri) { | |
d24d5663 PP |
424 | if (bt_event_class_set_emf_uri(out_event_class, in_emf_uri) != |
425 | BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { | |
91bc8451 | 426 | BT_COMP_LOGE("Error setting event class' emf uri: ec-addr=%p, " |
ca9f27f3 FD |
427 | "emf uri=%s", out_event_class, in_emf_uri); |
428 | ret = -1; | |
429 | goto error; | |
430 | } | |
431 | } | |
432 | ||
433 | md_maps = borrow_metadata_maps_from_input_event_class(ir_maps, in_event_class); | |
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( | |
440 | in_event_class); | |
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, | |
448 | in_event_specific_context); | |
449 | ||
5e1abef6 | 450 | ret = copy_field_class_content(md_maps, |
ca9f27f3 FD |
451 | in_event_specific_context, out_specific_context_fc); |
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( | |
475 | in_event_class); | |
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, | |
482 | in_event_payload); | |
5e1abef6 | 483 | ret = copy_field_class_content(md_maps, |
ca9f27f3 FD |
484 | in_event_payload, out_payload_fc); |
485 | if (ret) { | |
486 | goto error; | |
487 | } | |
488 | ||
489 | /* Add the output payload to the output event class. */ | |
d24d5663 PP |
490 | if (bt_event_class_set_payload_field_class( |
491 | out_event_class, out_payload_fc) != | |
492 | BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
91bc8451 | 493 | BT_COMP_LOGE("Error setting event class' payload " |
ca9f27f3 FD |
494 | "field class: ec-addr=%p, payload-fc-addr=%p", |
495 | out_event_class, out_payload_fc); | |
496 | ret = -1; | |
497 | goto error; | |
498 | } | |
499 | } | |
500 | ||
91bc8451 | 501 | BT_COMP_LOGD("Copied content of event class: in-ec-addr=%p, out-ec-addr=%p", |
ca9f27f3 FD |
502 | in_event_class, out_event_class); |
503 | error: | |
504 | return ret; | |
505 | } | |
506 | ||
507 | BT_HIDDEN | |
508 | int copy_event_common_context_field_class_content( | |
509 | struct trace_ir_metadata_maps *md_maps, | |
510 | const char *debug_info_fc_name, | |
511 | const bt_field_class *in_field_class, | |
512 | bt_field_class *out_field_class) | |
513 | { | |
ca9f27f3 FD |
514 | bt_field_class *debug_field_class = NULL, *bin_field_class = NULL, |
515 | *func_field_class = NULL, *src_field_class = NULL; | |
516 | int ret = 0; | |
3a3d15f3 | 517 | bt_logging_level log_level = md_maps->log_level; |
91bc8451 | 518 | bt_self_component *self_comp = md_maps->self_comp; |
ca9f27f3 | 519 | |
91bc8451 | 520 | BT_COMP_LOGD("Copying content of event common context field class: " |
ca9f27f3 FD |
521 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
522 | ||
523 | /* Copy the content of the input common context. */ | |
524 | ret = copy_field_class_content(md_maps, in_field_class, out_field_class); | |
525 | if (ret) { | |
526 | goto error; | |
527 | } | |
528 | ||
529 | /* | |
530 | * If this event common context has the necessary fields to compute the | |
531 | * debug information append the debug-info field class to the event | |
532 | * common context. | |
533 | */ | |
534 | if (is_event_common_ctx_dbg_info_compatible(in_field_class, debug_info_fc_name)) { | |
535 | /* | |
536 | * The struct field and 3 sub-fields are not stored in the | |
537 | * field class map because they don't have input equivalent. | |
538 | * We need to put our reference each of these field classes | |
539 | * once they are added to their respective containing field | |
540 | * classes. | |
541 | */ | |
542 | debug_field_class = bt_field_class_structure_create( | |
543 | md_maps->output_trace_class); | |
544 | if (!debug_field_class) { | |
91bc8451 | 545 | BT_COMP_LOGE_STR("Failed to create debug_info structure."); |
ca9f27f3 FD |
546 | ret = -1; |
547 | goto error; | |
548 | } | |
549 | ||
550 | bin_field_class = bt_field_class_string_create( | |
551 | md_maps->output_trace_class); | |
552 | if (!bin_field_class) { | |
91bc8451 | 553 | BT_COMP_LOGE_STR("Failed to create string for field=bin."); |
ca9f27f3 FD |
554 | ret = -1; |
555 | goto error; | |
556 | } | |
557 | ||
558 | func_field_class = bt_field_class_string_create( | |
559 | md_maps->output_trace_class); | |
560 | if (!func_field_class) { | |
91bc8451 | 561 | BT_COMP_LOGE_STR("Failed to create string for field=func."); |
ca9f27f3 FD |
562 | ret = -1; |
563 | goto error; | |
564 | } | |
565 | ||
566 | src_field_class = bt_field_class_string_create( | |
567 | md_maps->output_trace_class); | |
568 | if (!src_field_class) { | |
91bc8451 | 569 | BT_COMP_LOGE_STR("Failed to create string for field=src."); |
ca9f27f3 FD |
570 | ret = -1; |
571 | goto error; | |
572 | } | |
573 | ||
d24d5663 PP |
574 | if (bt_field_class_structure_append_member( |
575 | debug_field_class, "bin", bin_field_class) != | |
576 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 577 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
ca9f27f3 FD |
578 | "struct: field=bin."); |
579 | ret = -1; | |
580 | goto error; | |
581 | } | |
582 | BT_FIELD_CLASS_PUT_REF_AND_RESET(bin_field_class); | |
583 | ||
d24d5663 PP |
584 | if (bt_field_class_structure_append_member( |
585 | debug_field_class, "func", func_field_class) != | |
586 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 587 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
ca9f27f3 FD |
588 | "struct: field=func."); |
589 | ret = -1; | |
590 | goto error; | |
591 | } | |
592 | BT_FIELD_CLASS_PUT_REF_AND_RESET(func_field_class); | |
593 | ||
d24d5663 PP |
594 | if (bt_field_class_structure_append_member( |
595 | debug_field_class, "src", src_field_class) != | |
596 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 597 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
ca9f27f3 FD |
598 | "struct: field=src."); |
599 | ret = -1; | |
600 | goto error; | |
601 | } | |
602 | BT_FIELD_CLASS_PUT_REF_AND_RESET(src_field_class); | |
603 | ||
604 | /*Add the filled debug-info field class to the common context. */ | |
d24d5663 PP |
605 | if (bt_field_class_structure_append_member(out_field_class, |
606 | debug_info_fc_name, debug_field_class) != | |
607 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 608 | BT_COMP_LOGE_STR("Failed to add debug_info field to " |
ca9f27f3 FD |
609 | "event common context."); |
610 | ret = -1; | |
611 | goto error; | |
612 | } | |
613 | BT_FIELD_CLASS_PUT_REF_AND_RESET(debug_field_class); | |
614 | } | |
91bc8451 | 615 | BT_COMP_LOGD("Copied content of event common context field class: " |
ca9f27f3 FD |
616 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
617 | goto end; | |
618 | ||
619 | error: | |
620 | if (debug_field_class) { | |
621 | bt_field_class_put_ref(debug_field_class); | |
622 | } | |
623 | if (bin_field_class) { | |
624 | bt_field_class_put_ref(bin_field_class); | |
625 | } | |
626 | if (func_field_class) { | |
627 | bt_field_class_put_ref(func_field_class); | |
628 | } | |
629 | if (src_field_class) { | |
630 | bt_field_class_put_ref(src_field_class); | |
631 | } | |
632 | end: | |
633 | return ret; | |
634 | } | |
635 | ||
636 | BT_HIDDEN | |
637 | bt_field_class *create_field_class_copy(struct trace_ir_metadata_maps *md_maps, | |
638 | const bt_field_class *in_field_class) | |
639 | { | |
640 | return create_field_class_copy_internal(md_maps, in_field_class); | |
641 | } | |
642 | ||
643 | BT_HIDDEN | |
644 | int copy_field_class_content(struct trace_ir_metadata_maps *md_maps, | |
645 | const bt_field_class *in_field_class, | |
646 | bt_field_class *out_field_class) | |
647 | { | |
648 | return copy_field_class_content_internal(md_maps, in_field_class, | |
649 | out_field_class); | |
650 | } |