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