| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2019 Francis Deslauriers francis.deslauriers@efficios.com> |
| 5 | */ |
| 6 | |
| 7 | #ifndef BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H |
| 8 | #define BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H |
| 9 | |
| 10 | #include <glib.h> |
| 11 | |
| 12 | #include "common/assert.h" |
| 13 | #include "common/macros.h" |
| 14 | #include <babeltrace2/babeltrace.h> |
| 15 | |
| 16 | #include "debug-info.h" |
| 17 | |
| 18 | enum debug_info_trace_ir_mapping_status { |
| 19 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK = 0, |
| 20 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR = -12, |
| 21 | }; |
| 22 | |
| 23 | /* Used to resolve field paths for dynamic arrays and variant field classes. */ |
| 24 | struct field_class_resolving_context { |
| 25 | /* Weak reference. Owned by input stream class. */ |
| 26 | const bt_field_class *packet_context; |
| 27 | /* Weak reference. Owned by input stream class. */ |
| 28 | const bt_field_class *event_common_context; |
| 29 | /* Weak reference. Owned by input event class. */ |
| 30 | const bt_field_class *event_specific_context; |
| 31 | /* Weak reference. Owned by input event class. */ |
| 32 | const bt_field_class *event_payload; |
| 33 | }; |
| 34 | |
| 35 | struct trace_ir_metadata_maps { |
| 36 | bt_logging_level log_level; |
| 37 | bt_self_component *self_comp; |
| 38 | const bt_trace_class *input_trace_class; |
| 39 | bt_trace_class *output_trace_class; |
| 40 | |
| 41 | /* |
| 42 | * Map between input stream class and its corresponding output stream |
| 43 | * class. |
| 44 | * input stream class: weak reference. Owned by an upstream |
| 45 | * component. |
| 46 | * output stream class: owned by this structure. |
| 47 | */ |
| 48 | GHashTable *stream_class_map; |
| 49 | |
| 50 | /* |
| 51 | * Map between input event class and its corresponding output event |
| 52 | * class. |
| 53 | * input event class: weak reference. Owned by an upstream component. |
| 54 | * output event class: owned by this structure. |
| 55 | */ |
| 56 | GHashTable *event_class_map; |
| 57 | |
| 58 | /* |
| 59 | * Map between input field class and its corresponding output field |
| 60 | * class. |
| 61 | * input field class: weak reference. Owned by an upstream component. |
| 62 | * output field class: owned by this structure. |
| 63 | */ |
| 64 | GHashTable *field_class_map; |
| 65 | |
| 66 | /* |
| 67 | * Map between input clock class and its corresponding output clock |
| 68 | * class. |
| 69 | * input clock class: weak reference. Owned by an upstream component. |
| 70 | * output clock class: owned by this structure. |
| 71 | */ |
| 72 | GHashTable *clock_class_map; |
| 73 | |
| 74 | struct field_class_resolving_context *fc_resolving_ctx; |
| 75 | |
| 76 | bt_listener_id destruction_listener_id; |
| 77 | }; |
| 78 | |
| 79 | struct trace_ir_data_maps { |
| 80 | bt_logging_level log_level; |
| 81 | bt_self_component *self_comp; |
| 82 | const bt_trace *input_trace; |
| 83 | bt_trace *output_trace; |
| 84 | |
| 85 | /* |
| 86 | * Map between input stream its corresponding output stream. |
| 87 | * input stream: weak reference. Owned by an upstream component. |
| 88 | * output stream: owned by this structure. |
| 89 | */ |
| 90 | GHashTable *stream_map; |
| 91 | |
| 92 | /* |
| 93 | * Map between input packet its corresponding output packet. |
| 94 | * input packet: weak reference. Owned by an upstream packet component. |
| 95 | * output packet: owned by this structure. |
| 96 | */ |
| 97 | GHashTable *packet_map; |
| 98 | |
| 99 | bt_listener_id destruction_listener_id; |
| 100 | }; |
| 101 | |
| 102 | struct trace_ir_maps { |
| 103 | bt_logging_level log_level; |
| 104 | |
| 105 | /* |
| 106 | * input trace -> trace_ir_data_maps. |
| 107 | * input trace: weak reference. Owned by an upstream component. |
| 108 | * trace_ir_data_maps: Owned by this structure. |
| 109 | */ |
| 110 | GHashTable *data_maps; |
| 111 | |
| 112 | /* |
| 113 | * input trace class -> trace_ir_metadata_maps. |
| 114 | * input trace class: weak reference. Owned by an upstream component. |
| 115 | * trace_ir_metadata_maps: Owned by this structure. |
| 116 | */ |
| 117 | GHashTable *metadata_maps; |
| 118 | |
| 119 | char *debug_info_field_class_name; |
| 120 | |
| 121 | bt_self_component *self_comp; |
| 122 | }; |
| 123 | |
| 124 | BT_HIDDEN |
| 125 | struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp, |
| 126 | const char *debug_info_field_name, bt_logging_level log_level); |
| 127 | |
| 128 | BT_HIDDEN |
| 129 | void trace_ir_maps_clear(struct trace_ir_maps *maps); |
| 130 | |
| 131 | BT_HIDDEN |
| 132 | void trace_ir_maps_destroy(struct trace_ir_maps *maps); |
| 133 | |
| 134 | BT_HIDDEN |
| 135 | struct trace_ir_data_maps *trace_ir_data_maps_create( |
| 136 | struct trace_ir_maps *ir_maps, |
| 137 | const bt_trace *in_trace); |
| 138 | |
| 139 | BT_HIDDEN |
| 140 | void trace_ir_data_maps_destroy(struct trace_ir_data_maps *d_maps); |
| 141 | |
| 142 | BT_HIDDEN |
| 143 | struct trace_ir_metadata_maps *trace_ir_metadata_maps_create( |
| 144 | struct trace_ir_maps *ir_maps, |
| 145 | const bt_trace_class *in_trace_class); |
| 146 | |
| 147 | BT_HIDDEN |
| 148 | void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *md_maps); |
| 149 | |
| 150 | BT_HIDDEN |
| 151 | bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class( |
| 152 | struct trace_ir_maps *ir_maps, |
| 153 | const bt_stream_class *in_stream_class); |
| 154 | |
| 155 | BT_HIDDEN |
| 156 | bt_stream_class *trace_ir_mapping_borrow_mapped_stream_class( |
| 157 | struct trace_ir_maps *ir_maps, |
| 158 | const bt_stream_class *in_stream_class); |
| 159 | |
| 160 | BT_HIDDEN |
| 161 | bt_stream *trace_ir_mapping_create_new_mapped_stream( |
| 162 | struct trace_ir_maps *ir_maps, |
| 163 | const bt_stream *in_stream); |
| 164 | |
| 165 | BT_HIDDEN |
| 166 | bt_stream *trace_ir_mapping_borrow_mapped_stream( |
| 167 | struct trace_ir_maps *ir_maps, |
| 168 | const bt_stream *in_stream); |
| 169 | |
| 170 | BT_HIDDEN |
| 171 | void trace_ir_mapping_remove_mapped_stream( |
| 172 | struct trace_ir_maps *ir_maps, |
| 173 | const bt_stream *in_stream); |
| 174 | |
| 175 | BT_HIDDEN |
| 176 | bt_event_class *trace_ir_mapping_create_new_mapped_event_class( |
| 177 | struct trace_ir_maps *ir_maps, |
| 178 | const bt_event_class *in_event_class); |
| 179 | |
| 180 | BT_HIDDEN |
| 181 | bt_event_class *trace_ir_mapping_borrow_mapped_event_class( |
| 182 | struct trace_ir_maps *ir_maps, |
| 183 | const bt_event_class *in_event_class); |
| 184 | |
| 185 | BT_HIDDEN |
| 186 | bt_packet *trace_ir_mapping_create_new_mapped_packet( |
| 187 | struct trace_ir_maps *ir_maps, |
| 188 | const bt_packet *in_packet); |
| 189 | |
| 190 | BT_HIDDEN |
| 191 | bt_packet *trace_ir_mapping_borrow_mapped_packet( |
| 192 | struct trace_ir_maps *ir_maps, |
| 193 | const bt_packet *in_packet); |
| 194 | |
| 195 | BT_HIDDEN |
| 196 | void trace_ir_mapping_remove_mapped_packet( |
| 197 | struct trace_ir_maps *ir_maps, |
| 198 | const bt_packet *in_packet); |
| 199 | |
| 200 | static inline |
| 201 | struct trace_ir_data_maps *borrow_data_maps_from_input_trace( |
| 202 | struct trace_ir_maps *ir_maps, const bt_trace *in_trace) |
| 203 | { |
| 204 | BT_ASSERT(ir_maps); |
| 205 | BT_ASSERT(in_trace); |
| 206 | |
| 207 | struct trace_ir_data_maps *d_maps = |
| 208 | g_hash_table_lookup(ir_maps->data_maps, (gpointer) in_trace); |
| 209 | if (!d_maps) { |
| 210 | d_maps = trace_ir_data_maps_create(ir_maps, in_trace); |
| 211 | g_hash_table_insert(ir_maps->data_maps, (gpointer) in_trace, d_maps); |
| 212 | } |
| 213 | |
| 214 | return d_maps; |
| 215 | } |
| 216 | |
| 217 | static inline |
| 218 | struct trace_ir_data_maps *borrow_data_maps_from_input_stream( |
| 219 | struct trace_ir_maps *ir_maps, const bt_stream *in_stream) |
| 220 | { |
| 221 | BT_ASSERT(ir_maps); |
| 222 | BT_ASSERT(in_stream); |
| 223 | |
| 224 | return borrow_data_maps_from_input_trace(ir_maps, |
| 225 | bt_stream_borrow_trace_const(in_stream)); |
| 226 | } |
| 227 | |
| 228 | static inline |
| 229 | struct trace_ir_data_maps *borrow_data_maps_from_input_packet( |
| 230 | struct trace_ir_maps *ir_maps, const bt_packet *in_packet) |
| 231 | { |
| 232 | BT_ASSERT(ir_maps); |
| 233 | BT_ASSERT(in_packet); |
| 234 | |
| 235 | return borrow_data_maps_from_input_stream(ir_maps, |
| 236 | bt_packet_borrow_stream_const(in_packet)); |
| 237 | } |
| 238 | |
| 239 | static inline |
| 240 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_trace_class( |
| 241 | struct trace_ir_maps *ir_maps, |
| 242 | const bt_trace_class *in_trace_class) |
| 243 | { |
| 244 | BT_ASSERT(ir_maps); |
| 245 | BT_ASSERT(in_trace_class); |
| 246 | |
| 247 | struct trace_ir_metadata_maps *md_maps = |
| 248 | g_hash_table_lookup(ir_maps->metadata_maps, |
| 249 | (gpointer) in_trace_class); |
| 250 | if (!md_maps) { |
| 251 | md_maps = trace_ir_metadata_maps_create(ir_maps, in_trace_class); |
| 252 | g_hash_table_insert(ir_maps->metadata_maps, |
| 253 | (gpointer) in_trace_class, md_maps); |
| 254 | } |
| 255 | |
| 256 | return md_maps; |
| 257 | } |
| 258 | |
| 259 | static inline |
| 260 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_stream_class( |
| 261 | struct trace_ir_maps *ir_maps, |
| 262 | const bt_stream_class *in_stream_class) { |
| 263 | |
| 264 | BT_ASSERT(in_stream_class); |
| 265 | |
| 266 | return borrow_metadata_maps_from_input_trace_class(ir_maps, |
| 267 | bt_stream_class_borrow_trace_class_const(in_stream_class)); |
| 268 | } |
| 269 | |
| 270 | static inline |
| 271 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_event_class( |
| 272 | struct trace_ir_maps *ir_maps, |
| 273 | const bt_event_class *in_event_class) { |
| 274 | |
| 275 | BT_ASSERT(in_event_class); |
| 276 | |
| 277 | return borrow_metadata_maps_from_input_stream_class(ir_maps, |
| 278 | bt_event_class_borrow_stream_class_const(in_event_class)); |
| 279 | } |
| 280 | |
| 281 | #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H */ |