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