Commit | Line | Data |
---|---|---|
58f6d595 FD |
1 | #ifndef BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H |
2 | #define BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H | |
3 | /* | |
4 | * Copyright 2019 Francis Deslauriers francis.deslauriers@efficios.com> | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
22 | * SOFTWARE. | |
23 | */ | |
24 | ||
25 | #include <glib.h> | |
26 | ||
57952005 | 27 | #include "common/assert.h" |
85e7137b | 28 | #include "common/macros.h" |
71c5da58 | 29 | #include <babeltrace2/babeltrace.h> |
58f6d595 FD |
30 | |
31 | #include "debug-info.h" | |
32 | ||
bc79143c FD |
33 | enum debug_info_trace_ir_mapping_status { |
34 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK = 0, | |
35 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR = -12, | |
36 | }; | |
37 | ||
58f6d595 FD |
38 | /* Used to resolve field paths for dynamic arrays and variant field classes. */ |
39 | struct field_class_resolving_context { | |
40 | /* Weak reference. Owned by input stream class. */ | |
41 | const bt_field_class *packet_context; | |
42 | /* Weak reference. Owned by input stream class. */ | |
43 | const bt_field_class *event_common_context; | |
44 | /* Weak reference. Owned by input event class. */ | |
45 | const bt_field_class *event_specific_context; | |
46 | /* Weak reference. Owned by input event class. */ | |
47 | const bt_field_class *event_payload; | |
48 | }; | |
49 | ||
50 | struct trace_ir_metadata_maps { | |
a07aba4f | 51 | bt_logging_level log_level; |
475e740e | 52 | bt_self_component *self_comp; |
58f6d595 FD |
53 | const bt_trace_class *input_trace_class; |
54 | bt_trace_class *output_trace_class; | |
55 | ||
56 | /* | |
57 | * Map between input stream class and its corresponding output stream | |
58 | * class. | |
59 | * input stream class: weak reference. Owned by an upstream | |
60 | * component. | |
61 | * output stream class: owned by this structure. | |
62 | */ | |
63 | GHashTable *stream_class_map; | |
64 | ||
65 | /* | |
66 | * Map between input event class and its corresponding output event | |
67 | * class. | |
68 | * input event class: weak reference. Owned by an upstream component. | |
69 | * output event class: owned by this structure. | |
70 | */ | |
71 | GHashTable *event_class_map; | |
72 | ||
73 | /* | |
74 | * Map between input field class and its corresponding output field | |
75 | * class. | |
76 | * input field class: weak reference. Owned by an upstream component. | |
77 | * output field class: owned by this structure. | |
78 | */ | |
79 | GHashTable *field_class_map; | |
80 | ||
81 | /* | |
82 | * Map between input clock class and its corresponding output clock | |
83 | * class. | |
84 | * input clock class: weak reference. Owned by an upstream component. | |
85 | * output clock class: owned by this structure. | |
86 | */ | |
87 | GHashTable *clock_class_map; | |
88 | ||
89 | struct field_class_resolving_context *fc_resolving_ctx; | |
90 | ||
eba7ea21 | 91 | bt_listener_id destruction_listener_id; |
58f6d595 FD |
92 | }; |
93 | ||
94 | struct trace_ir_data_maps { | |
a07aba4f | 95 | bt_logging_level log_level; |
475e740e | 96 | bt_self_component *self_comp; |
58f6d595 FD |
97 | const bt_trace *input_trace; |
98 | bt_trace *output_trace; | |
99 | ||
100 | /* | |
101 | * Map between input stream its corresponding output stream. | |
102 | * input stream: weak reference. Owned by an upstream component. | |
103 | * output stream: owned by this structure. | |
104 | */ | |
105 | GHashTable *stream_map; | |
106 | ||
107 | /* | |
108 | * Map between input packet its corresponding output packet. | |
109 | * input packet: weak reference. Owned by an upstream packet component. | |
110 | * output packet: owned by this structure. | |
111 | */ | |
112 | GHashTable *packet_map; | |
113 | ||
eba7ea21 | 114 | bt_listener_id destruction_listener_id; |
58f6d595 FD |
115 | }; |
116 | ||
117 | struct trace_ir_maps { | |
a07aba4f PP |
118 | bt_logging_level log_level; |
119 | ||
58f6d595 FD |
120 | /* |
121 | * input trace -> trace_ir_data_maps. | |
122 | * input trace: weak reference. Owned by an upstream component. | |
123 | * trace_ir_data_maps: Owned by this structure. | |
124 | */ | |
125 | GHashTable *data_maps; | |
126 | ||
127 | /* | |
128 | * input trace class -> trace_ir_metadata_maps. | |
129 | * input trace class: weak reference. Owned by an upstream component. | |
130 | * trace_ir_metadata_maps: Owned by this structure. | |
131 | */ | |
132 | GHashTable *metadata_maps; | |
133 | ||
134 | char *debug_info_field_class_name; | |
135 | ||
136 | bt_self_component *self_comp; | |
137 | }; | |
138 | ||
139 | BT_HIDDEN | |
140 | struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp, | |
a07aba4f | 141 | const char *debug_info_field_name, bt_logging_level log_level); |
58f6d595 FD |
142 | |
143 | BT_HIDDEN | |
144 | void trace_ir_maps_clear(struct trace_ir_maps *maps); | |
145 | ||
146 | BT_HIDDEN | |
147 | void trace_ir_maps_destroy(struct trace_ir_maps *maps); | |
148 | ||
149 | BT_HIDDEN | |
150 | struct trace_ir_data_maps *trace_ir_data_maps_create( | |
151 | struct trace_ir_maps *ir_maps, | |
152 | const bt_trace *in_trace); | |
153 | ||
154 | BT_HIDDEN | |
155 | void trace_ir_data_maps_destroy(struct trace_ir_data_maps *d_maps); | |
156 | ||
157 | BT_HIDDEN | |
158 | struct trace_ir_metadata_maps *trace_ir_metadata_maps_create( | |
159 | struct trace_ir_maps *ir_maps, | |
160 | const bt_trace_class *in_trace_class); | |
161 | ||
162 | BT_HIDDEN | |
163 | void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps *md_maps); | |
164 | ||
38559056 FD |
165 | BT_HIDDEN |
166 | bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class( | |
167 | struct trace_ir_maps *ir_maps, | |
168 | const bt_stream_class *in_stream_class); | |
169 | ||
170 | BT_HIDDEN | |
171 | bt_stream_class *trace_ir_mapping_borrow_mapped_stream_class( | |
172 | struct trace_ir_maps *ir_maps, | |
173 | const bt_stream_class *in_stream_class); | |
174 | ||
58f6d595 FD |
175 | BT_HIDDEN |
176 | bt_stream *trace_ir_mapping_create_new_mapped_stream( | |
177 | struct trace_ir_maps *ir_maps, | |
178 | const bt_stream *in_stream); | |
179 | ||
180 | BT_HIDDEN | |
181 | bt_stream *trace_ir_mapping_borrow_mapped_stream( | |
182 | struct trace_ir_maps *ir_maps, | |
183 | const bt_stream *in_stream); | |
184 | ||
185 | BT_HIDDEN | |
186 | void trace_ir_mapping_remove_mapped_stream( | |
187 | struct trace_ir_maps *ir_maps, | |
188 | const bt_stream *in_stream); | |
189 | ||
190 | BT_HIDDEN | |
191 | bt_event_class *trace_ir_mapping_create_new_mapped_event_class( | |
192 | struct trace_ir_maps *ir_maps, | |
193 | const bt_event_class *in_event_class); | |
194 | ||
195 | BT_HIDDEN | |
196 | bt_event_class *trace_ir_mapping_borrow_mapped_event_class( | |
197 | struct trace_ir_maps *ir_maps, | |
198 | const bt_event_class *in_event_class); | |
199 | ||
200 | BT_HIDDEN | |
201 | bt_packet *trace_ir_mapping_create_new_mapped_packet( | |
202 | struct trace_ir_maps *ir_maps, | |
203 | const bt_packet *in_packet); | |
204 | ||
205 | BT_HIDDEN | |
206 | bt_packet *trace_ir_mapping_borrow_mapped_packet( | |
207 | struct trace_ir_maps *ir_maps, | |
208 | const bt_packet *in_packet); | |
209 | ||
210 | BT_HIDDEN | |
211 | void trace_ir_mapping_remove_mapped_packet( | |
212 | struct trace_ir_maps *ir_maps, | |
213 | const bt_packet *in_packet); | |
214 | ||
215 | static inline | |
216 | struct trace_ir_data_maps *borrow_data_maps_from_input_trace( | |
217 | struct trace_ir_maps *ir_maps, const bt_trace *in_trace) | |
218 | { | |
219 | BT_ASSERT(ir_maps); | |
220 | BT_ASSERT(in_trace); | |
221 | ||
222 | struct trace_ir_data_maps *d_maps = | |
223 | g_hash_table_lookup(ir_maps->data_maps, (gpointer) in_trace); | |
224 | if (!d_maps) { | |
225 | d_maps = trace_ir_data_maps_create(ir_maps, in_trace); | |
226 | g_hash_table_insert(ir_maps->data_maps, (gpointer) in_trace, d_maps); | |
227 | } | |
228 | ||
229 | return d_maps; | |
230 | } | |
231 | ||
232 | static inline | |
233 | struct trace_ir_data_maps *borrow_data_maps_from_input_stream( | |
234 | struct trace_ir_maps *ir_maps, const bt_stream *in_stream) | |
235 | { | |
236 | BT_ASSERT(ir_maps); | |
237 | BT_ASSERT(in_stream); | |
238 | ||
239 | return borrow_data_maps_from_input_trace(ir_maps, | |
240 | bt_stream_borrow_trace_const(in_stream)); | |
241 | } | |
242 | ||
243 | static inline | |
244 | struct trace_ir_data_maps *borrow_data_maps_from_input_packet( | |
245 | struct trace_ir_maps *ir_maps, const bt_packet *in_packet) | |
246 | { | |
247 | BT_ASSERT(ir_maps); | |
248 | BT_ASSERT(in_packet); | |
249 | ||
250 | return borrow_data_maps_from_input_stream(ir_maps, | |
251 | bt_packet_borrow_stream_const(in_packet)); | |
252 | } | |
253 | ||
254 | static inline | |
255 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_trace_class( | |
256 | struct trace_ir_maps *ir_maps, | |
257 | const bt_trace_class *in_trace_class) | |
258 | { | |
259 | BT_ASSERT(ir_maps); | |
260 | BT_ASSERT(in_trace_class); | |
261 | ||
262 | struct trace_ir_metadata_maps *md_maps = | |
263 | g_hash_table_lookup(ir_maps->metadata_maps, | |
264 | (gpointer) in_trace_class); | |
265 | if (!md_maps) { | |
266 | md_maps = trace_ir_metadata_maps_create(ir_maps, in_trace_class); | |
267 | g_hash_table_insert(ir_maps->metadata_maps, | |
268 | (gpointer) in_trace_class, md_maps); | |
269 | } | |
270 | ||
271 | return md_maps; | |
272 | } | |
273 | ||
274 | static inline | |
275 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_stream_class( | |
276 | struct trace_ir_maps *ir_maps, | |
277 | const bt_stream_class *in_stream_class) { | |
278 | ||
279 | BT_ASSERT(in_stream_class); | |
280 | ||
281 | return borrow_metadata_maps_from_input_trace_class(ir_maps, | |
282 | bt_stream_class_borrow_trace_class_const(in_stream_class)); | |
283 | } | |
284 | ||
285 | static inline | |
286 | struct trace_ir_metadata_maps *borrow_metadata_maps_from_input_event_class( | |
287 | struct trace_ir_maps *ir_maps, | |
288 | const bt_event_class *in_event_class) { | |
289 | ||
290 | BT_ASSERT(in_event_class); | |
291 | ||
292 | return borrow_metadata_maps_from_input_stream_class(ir_maps, | |
293 | bt_event_class_borrow_stream_class_const(in_event_class)); | |
294 | } | |
295 | ||
296 | #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H */ |