1 #ifndef BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
2 #define BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
4 * Copyright 2019 Francis Deslauriers francis.deslauriers@efficios.com>
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
27 #include "common/assert.h"
28 #include "common/macros.h"
29 #include <babeltrace2/babeltrace.h>
31 #include "debug-info.h"
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
;
45 struct trace_ir_metadata_maps
{
46 bt_logging_level log_level
;
47 const bt_trace_class
*input_trace_class
;
48 bt_trace_class
*output_trace_class
;
51 * Map between input stream class and its corresponding output stream
53 * input stream class: weak reference. Owned by an upstream
55 * output stream class: owned by this structure.
57 GHashTable
*stream_class_map
;
60 * Map between input event class and its corresponding output event
62 * input event class: weak reference. Owned by an upstream component.
63 * output event class: owned by this structure.
65 GHashTable
*event_class_map
;
68 * Map between input field class and its corresponding output field
70 * input field class: weak reference. Owned by an upstream component.
71 * output field class: owned by this structure.
73 GHashTable
*field_class_map
;
76 * Map between input clock class and its corresponding output clock
78 * input clock class: weak reference. Owned by an upstream component.
79 * output clock class: owned by this structure.
81 GHashTable
*clock_class_map
;
83 struct field_class_resolving_context
*fc_resolving_ctx
;
85 uint64_t destruction_listener_id
;
88 struct trace_ir_data_maps
{
89 bt_logging_level log_level
;
90 const bt_trace
*input_trace
;
91 bt_trace
*output_trace
;
94 * Map between input stream its corresponding output stream.
95 * input stream: weak reference. Owned by an upstream component.
96 * output stream: owned by this structure.
98 GHashTable
*stream_map
;
101 * Map between input packet its corresponding output packet.
102 * input packet: weak reference. Owned by an upstream packet component.
103 * output packet: owned by this structure.
105 GHashTable
*packet_map
;
107 uint64_t destruction_listener_id
;
110 struct trace_ir_maps
{
111 bt_logging_level log_level
;
114 * input trace -> trace_ir_data_maps.
115 * input trace: weak reference. Owned by an upstream component.
116 * trace_ir_data_maps: Owned by this structure.
118 GHashTable
*data_maps
;
121 * input trace class -> trace_ir_metadata_maps.
122 * input trace class: weak reference. Owned by an upstream component.
123 * trace_ir_metadata_maps: Owned by this structure.
125 GHashTable
*metadata_maps
;
127 char *debug_info_field_class_name
;
129 bt_self_component
*self_comp
;
133 struct trace_ir_maps
*trace_ir_maps_create(bt_self_component
*self_comp
,
134 const char *debug_info_field_name
, bt_logging_level log_level
);
137 void trace_ir_maps_clear(struct trace_ir_maps
*maps
);
140 void trace_ir_maps_destroy(struct trace_ir_maps
*maps
);
143 struct trace_ir_data_maps
*trace_ir_data_maps_create(
144 struct trace_ir_maps
*ir_maps
,
145 const bt_trace
*in_trace
);
148 void trace_ir_data_maps_destroy(struct trace_ir_data_maps
*d_maps
);
151 struct trace_ir_metadata_maps
*trace_ir_metadata_maps_create(
152 struct trace_ir_maps
*ir_maps
,
153 const bt_trace_class
*in_trace_class
);
156 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps
*md_maps
);
159 bt_stream
*trace_ir_mapping_create_new_mapped_stream(
160 struct trace_ir_maps
*ir_maps
,
161 const bt_stream
*in_stream
);
164 bt_stream
*trace_ir_mapping_borrow_mapped_stream(
165 struct trace_ir_maps
*ir_maps
,
166 const bt_stream
*in_stream
);
169 void trace_ir_mapping_remove_mapped_stream(
170 struct trace_ir_maps
*ir_maps
,
171 const bt_stream
*in_stream
);
174 bt_event_class
*trace_ir_mapping_create_new_mapped_event_class(
175 struct trace_ir_maps
*ir_maps
,
176 const bt_event_class
*in_event_class
);
179 bt_event_class
*trace_ir_mapping_borrow_mapped_event_class(
180 struct trace_ir_maps
*ir_maps
,
181 const bt_event_class
*in_event_class
);
184 bt_packet
*trace_ir_mapping_create_new_mapped_packet(
185 struct trace_ir_maps
*ir_maps
,
186 const bt_packet
*in_packet
);
189 bt_packet
*trace_ir_mapping_borrow_mapped_packet(
190 struct trace_ir_maps
*ir_maps
,
191 const bt_packet
*in_packet
);
194 void trace_ir_mapping_remove_mapped_packet(
195 struct trace_ir_maps
*ir_maps
,
196 const bt_packet
*in_packet
);
199 struct trace_ir_data_maps
*borrow_data_maps_from_input_trace(
200 struct trace_ir_maps
*ir_maps
, const bt_trace
*in_trace
)
205 struct trace_ir_data_maps
*d_maps
=
206 g_hash_table_lookup(ir_maps
->data_maps
, (gpointer
) in_trace
);
208 d_maps
= trace_ir_data_maps_create(ir_maps
, in_trace
);
209 g_hash_table_insert(ir_maps
->data_maps
, (gpointer
) in_trace
, d_maps
);
216 struct trace_ir_data_maps
*borrow_data_maps_from_input_stream(
217 struct trace_ir_maps
*ir_maps
, const bt_stream
*in_stream
)
220 BT_ASSERT(in_stream
);
222 return borrow_data_maps_from_input_trace(ir_maps
,
223 bt_stream_borrow_trace_const(in_stream
));
227 struct trace_ir_data_maps
*borrow_data_maps_from_input_packet(
228 struct trace_ir_maps
*ir_maps
, const bt_packet
*in_packet
)
231 BT_ASSERT(in_packet
);
233 return borrow_data_maps_from_input_stream(ir_maps
,
234 bt_packet_borrow_stream_const(in_packet
));
238 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_trace_class(
239 struct trace_ir_maps
*ir_maps
,
240 const bt_trace_class
*in_trace_class
)
243 BT_ASSERT(in_trace_class
);
245 struct trace_ir_metadata_maps
*md_maps
=
246 g_hash_table_lookup(ir_maps
->metadata_maps
,
247 (gpointer
) in_trace_class
);
249 md_maps
= trace_ir_metadata_maps_create(ir_maps
, in_trace_class
);
250 g_hash_table_insert(ir_maps
->metadata_maps
,
251 (gpointer
) in_trace_class
, md_maps
);
258 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_stream_class(
259 struct trace_ir_maps
*ir_maps
,
260 const bt_stream_class
*in_stream_class
) {
262 BT_ASSERT(in_stream_class
);
264 return borrow_metadata_maps_from_input_trace_class(ir_maps
,
265 bt_stream_class_borrow_trace_class_const(in_stream_class
));
269 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_event_class(
270 struct trace_ir_maps
*ir_maps
,
271 const bt_event_class
*in_event_class
) {
273 BT_ASSERT(in_event_class
);
275 return borrow_metadata_maps_from_input_stream_class(ir_maps
,
276 bt_event_class_borrow_stream_class_const(in_event_class
));
279 #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H */