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