2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 Francis Deslauriers francis.deslauriers@efficios.com>
7 #ifndef BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
8 #define BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H
12 #include "common/assert.h"
13 #include "common/macros.h"
14 #include <babeltrace2/babeltrace.h>
16 #include "debug-info.h"
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,
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
;
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
;
42 * Map between input stream class and its corresponding output stream
44 * input stream class: weak reference. Owned by an upstream
46 * output stream class: owned by this structure.
48 GHashTable
*stream_class_map
;
51 * Map between input event class and its corresponding output event
53 * input event class: weak reference. Owned by an upstream component.
54 * output event class: owned by this structure.
56 GHashTable
*event_class_map
;
59 * Map between input field class and its corresponding output field
61 * input field class: weak reference. Owned by an upstream component.
62 * output field class: owned by this structure.
64 GHashTable
*field_class_map
;
67 * Map between input clock class and its corresponding output clock
69 * input clock class: weak reference. Owned by an upstream component.
70 * output clock class: owned by this structure.
72 GHashTable
*clock_class_map
;
74 struct field_class_resolving_context
*fc_resolving_ctx
;
76 bt_listener_id destruction_listener_id
;
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
;
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.
90 GHashTable
*stream_map
;
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.
97 GHashTable
*packet_map
;
99 bt_listener_id destruction_listener_id
;
102 struct trace_ir_maps
{
103 bt_logging_level log_level
;
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.
110 GHashTable
*data_maps
;
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.
117 GHashTable
*metadata_maps
;
119 char *debug_info_field_class_name
;
121 bt_self_component
*self_comp
;
124 struct trace_ir_maps
*trace_ir_maps_create(bt_self_component
*self_comp
,
125 const char *debug_info_field_name
, bt_logging_level log_level
);
127 void trace_ir_maps_clear(struct trace_ir_maps
*maps
);
129 void trace_ir_maps_destroy(struct trace_ir_maps
*maps
);
131 struct trace_ir_data_maps
*trace_ir_data_maps_create(
132 struct trace_ir_maps
*ir_maps
,
133 const bt_trace
*in_trace
);
135 void trace_ir_data_maps_destroy(struct trace_ir_data_maps
*d_maps
);
137 struct trace_ir_metadata_maps
*trace_ir_metadata_maps_create(
138 struct trace_ir_maps
*ir_maps
,
139 const bt_trace_class
*in_trace_class
);
141 void trace_ir_metadata_maps_destroy(struct trace_ir_metadata_maps
*md_maps
);
143 bt_stream_class
*trace_ir_mapping_create_new_mapped_stream_class(
144 struct trace_ir_maps
*ir_maps
,
145 const bt_stream_class
*in_stream_class
);
147 bt_stream_class
*trace_ir_mapping_borrow_mapped_stream_class(
148 struct trace_ir_maps
*ir_maps
,
149 const bt_stream_class
*in_stream_class
);
151 bt_stream
*trace_ir_mapping_create_new_mapped_stream(
152 struct trace_ir_maps
*ir_maps
,
153 const bt_stream
*in_stream
);
155 bt_stream
*trace_ir_mapping_borrow_mapped_stream(
156 struct trace_ir_maps
*ir_maps
,
157 const bt_stream
*in_stream
);
159 void trace_ir_mapping_remove_mapped_stream(
160 struct trace_ir_maps
*ir_maps
,
161 const bt_stream
*in_stream
);
163 bt_event_class
*trace_ir_mapping_create_new_mapped_event_class(
164 struct trace_ir_maps
*ir_maps
,
165 const bt_event_class
*in_event_class
);
167 bt_event_class
*trace_ir_mapping_borrow_mapped_event_class(
168 struct trace_ir_maps
*ir_maps
,
169 const bt_event_class
*in_event_class
);
171 bt_packet
*trace_ir_mapping_create_new_mapped_packet(
172 struct trace_ir_maps
*ir_maps
,
173 const bt_packet
*in_packet
);
175 bt_packet
*trace_ir_mapping_borrow_mapped_packet(
176 struct trace_ir_maps
*ir_maps
,
177 const bt_packet
*in_packet
);
179 void trace_ir_mapping_remove_mapped_packet(
180 struct trace_ir_maps
*ir_maps
,
181 const bt_packet
*in_packet
);
184 struct trace_ir_data_maps
*borrow_data_maps_from_input_trace(
185 struct trace_ir_maps
*ir_maps
, const bt_trace
*in_trace
)
190 struct trace_ir_data_maps
*d_maps
=
191 g_hash_table_lookup(ir_maps
->data_maps
, (gpointer
) in_trace
);
193 d_maps
= trace_ir_data_maps_create(ir_maps
, in_trace
);
194 g_hash_table_insert(ir_maps
->data_maps
, (gpointer
) in_trace
, d_maps
);
201 struct trace_ir_data_maps
*borrow_data_maps_from_input_stream(
202 struct trace_ir_maps
*ir_maps
, const bt_stream
*in_stream
)
205 BT_ASSERT(in_stream
);
207 return borrow_data_maps_from_input_trace(ir_maps
,
208 bt_stream_borrow_trace_const(in_stream
));
212 struct trace_ir_data_maps
*borrow_data_maps_from_input_packet(
213 struct trace_ir_maps
*ir_maps
, const bt_packet
*in_packet
)
216 BT_ASSERT(in_packet
);
218 return borrow_data_maps_from_input_stream(ir_maps
,
219 bt_packet_borrow_stream_const(in_packet
));
223 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_trace_class(
224 struct trace_ir_maps
*ir_maps
,
225 const bt_trace_class
*in_trace_class
)
228 BT_ASSERT(in_trace_class
);
230 struct trace_ir_metadata_maps
*md_maps
=
231 g_hash_table_lookup(ir_maps
->metadata_maps
,
232 (gpointer
) in_trace_class
);
234 md_maps
= trace_ir_metadata_maps_create(ir_maps
, in_trace_class
);
235 g_hash_table_insert(ir_maps
->metadata_maps
,
236 (gpointer
) in_trace_class
, md_maps
);
243 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_stream_class(
244 struct trace_ir_maps
*ir_maps
,
245 const bt_stream_class
*in_stream_class
) {
247 BT_ASSERT(in_stream_class
);
249 return borrow_metadata_maps_from_input_trace_class(ir_maps
,
250 bt_stream_class_borrow_trace_class_const(in_stream_class
));
254 struct trace_ir_metadata_maps
*borrow_metadata_maps_from_input_event_class(
255 struct trace_ir_maps
*ir_maps
,
256 const bt_event_class
*in_event_class
) {
258 BT_ASSERT(in_event_class
);
260 return borrow_metadata_maps_from_input_stream_class(ir_maps
,
261 bt_event_class_borrow_stream_class_const(in_event_class
));
264 #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_IR_MAPPING_H */