Commit | Line | Data |
---|---|---|
490db841 | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
490db841 | 3 | * |
f3bc2010 | 4 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
56a1cced | 5 | * Copyright 2016 Philippe Proulx <pproulx@efficios.com> |
490db841 | 6 | * |
0235b0db | 7 | * BabelTrace - CTF on File System Component |
490db841 JG |
8 | */ |
9 | ||
0235b0db MJ |
10 | #ifndef BABELTRACE_PLUGIN_CTF_FS_H |
11 | #define BABELTRACE_PLUGIN_CTF_FS_H | |
12 | ||
c7e1be4b | 13 | #include <glib.h> |
c802cacb | 14 | |
c7e1be4b | 15 | #include <babeltrace2/babeltrace.h> |
c802cacb | 16 | |
087cd0f5 | 17 | #include "metadata.hpp" |
490db841 | 18 | |
78bb6992 | 19 | extern bool ctf_fs_debug; |
56a1cced | 20 | |
4164020e SM |
21 | struct ctf_fs_file |
22 | { | |
afb0f12b | 23 | bt_logging_level log_level = (bt_logging_level) 0; |
98903a3e | 24 | |
4164020e | 25 | /* Weak */ |
afb0f12b | 26 | bt_self_component *self_comp = nullptr; |
4c65a157 | 27 | |
4164020e | 28 | /* Owned by this */ |
afb0f12b | 29 | GString *path = nullptr; |
1a9f7075 | 30 | |
4164020e | 31 | /* Owned by this */ |
afb0f12b | 32 | FILE *fp = nullptr; |
1a9f7075 | 33 | |
afb0f12b | 34 | off_t size = 0; |
56a1cced JG |
35 | }; |
36 | ||
4164020e SM |
37 | struct ctf_fs_metadata |
38 | { | |
39 | /* Owned by this */ | |
afb0f12b | 40 | struct ctf_metadata_decoder *decoder = nullptr; |
44c440bc | 41 | |
4164020e | 42 | /* Owned by this */ |
afb0f12b | 43 | bt_trace_class *trace_class = nullptr; |
1a9f7075 | 44 | |
4164020e | 45 | /* Weak (owned by `decoder` above) */ |
afb0f12b | 46 | struct ctf_trace_class *tc = nullptr; |
44c440bc | 47 | |
4164020e | 48 | /* Owned by this */ |
afb0f12b | 49 | char *text = nullptr; |
1a9f7075 | 50 | |
afb0f12b | 51 | int bo = 0; |
56a1cced JG |
52 | }; |
53 | ||
4164020e SM |
54 | struct ctf_fs_component |
55 | { | |
afb0f12b | 56 | bt_logging_level log_level = (bt_logging_level) 0; |
98903a3e | 57 | |
4164020e | 58 | /* Array of struct ctf_fs_port_data *, owned by this */ |
afb0f12b | 59 | GPtrArray *port_data = nullptr; |
1a9f7075 | 60 | |
4164020e | 61 | /* Owned by this */ |
afb0f12b | 62 | struct ctf_fs_trace *trace = nullptr; |
1a9f7075 | 63 | |
4164020e | 64 | struct ctf_fs_metadata_config metadata_config; |
1a9f7075 PP |
65 | }; |
66 | ||
4164020e SM |
67 | struct ctf_fs_trace |
68 | { | |
afb0f12b | 69 | bt_logging_level log_level = (bt_logging_level) 0; |
98903a3e | 70 | |
4164020e SM |
71 | /* |
72 | * Weak. These are mostly used to generate log messages or to append | |
73 | * error causes. They are mutually exclusive, only one of them must be | |
74 | * set. | |
75 | */ | |
afb0f12b SM |
76 | bt_self_component *self_comp = nullptr; |
77 | bt_self_component_class *self_comp_class = nullptr; | |
4c65a157 | 78 | |
4164020e | 79 | /* Owned by this */ |
afb0f12b | 80 | struct ctf_fs_metadata *metadata = nullptr; |
1a9f7075 | 81 | |
4164020e | 82 | /* Owned by this */ |
afb0f12b | 83 | bt_trace *trace = nullptr; |
862ca4ed | 84 | |
4164020e | 85 | /* Array of struct ctf_fs_ds_file_group *, owned by this */ |
afb0f12b | 86 | GPtrArray *ds_file_groups = nullptr; |
94cf822e | 87 | |
4164020e | 88 | /* Owned by this */ |
afb0f12b | 89 | GString *path = nullptr; |
1a9f7075 | 90 | |
4164020e | 91 | /* Next automatic stream ID when not provided by packet header */ |
afb0f12b | 92 | uint64_t next_stream_id = 0; |
1a9f7075 PP |
93 | }; |
94 | ||
4164020e SM |
95 | struct ctf_fs_ds_index_entry |
96 | { | |
97 | /* Weak, belongs to ctf_fs_ds_file_info. */ | |
afb0f12b | 98 | const char *path = nullptr; |
4164020e SM |
99 | |
100 | /* Position, in bytes, of the packet from the beginning of the file. */ | |
afb0f12b | 101 | uint64_t offset = 0; |
4164020e SM |
102 | |
103 | /* Size of the packet, in bytes. */ | |
afb0f12b | 104 | uint64_t packet_size = 0; |
4164020e SM |
105 | |
106 | /* | |
107 | * Extracted from the packet context, relative to the respective fields' | |
108 | * mapped clock classes (in cycles). | |
109 | */ | |
afb0f12b | 110 | uint64_t timestamp_begin = 0, timestamp_end = 0; |
4164020e SM |
111 | |
112 | /* | |
113 | * Converted from the packet context, relative to the trace's EPOCH | |
114 | * (in ns since EPOCH). | |
115 | */ | |
afb0f12b | 116 | int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0; |
4164020e SM |
117 | |
118 | /* | |
119 | * Packet sequence number, or UINT64_MAX if not present in the index. | |
120 | */ | |
afb0f12b | 121 | uint64_t packet_seq_num = 0; |
7ed5243a FD |
122 | }; |
123 | ||
4164020e SM |
124 | struct ctf_fs_ds_index |
125 | { | |
126 | /* Array of pointer to struct ctf_fs_ds_index_entry. */ | |
afb0f12b | 127 | GPtrArray *entries = nullptr; |
7ed5243a FD |
128 | }; |
129 | ||
4164020e SM |
130 | struct ctf_fs_ds_file_group |
131 | { | |
132 | /* | |
133 | * Array of struct ctf_fs_ds_file_info, owned by this. | |
134 | * | |
135 | * This is an _ordered_ array of data stream file infos which | |
136 | * belong to this group (a single stream instance). | |
137 | * | |
138 | * You can call ctf_fs_ds_file_create() with one of those paths | |
139 | * and the trace IR stream below. | |
140 | */ | |
afb0f12b | 141 | GPtrArray *ds_file_infos = nullptr; |
4164020e SM |
142 | |
143 | /* Owned by this */ | |
afb0f12b | 144 | struct ctf_stream_class *sc = nullptr; |
4164020e SM |
145 | |
146 | /* Owned by this */ | |
afb0f12b | 147 | bt_stream *stream = nullptr; |
4164020e SM |
148 | |
149 | /* Stream (instance) ID; -1ULL means none */ | |
afb0f12b | 150 | uint64_t stream_id = 0; |
4164020e SM |
151 | |
152 | /* Weak, belongs to component */ | |
afb0f12b | 153 | struct ctf_fs_trace *ctf_fs_trace = nullptr; |
4164020e SM |
154 | |
155 | /* | |
156 | * Owned by this. | |
157 | */ | |
afb0f12b | 158 | struct ctf_fs_ds_index *index = nullptr; |
ea0b4b9e JG |
159 | }; |
160 | ||
4164020e SM |
161 | struct ctf_fs_port_data |
162 | { | |
163 | /* Weak, belongs to ctf_fs_trace */ | |
afb0f12b | 164 | struct ctf_fs_ds_file_group *ds_file_group = nullptr; |
5c563278 | 165 | |
4164020e | 166 | /* Weak */ |
afb0f12b | 167 | struct ctf_fs_component *ctf_fs = nullptr; |
94cf822e PP |
168 | }; |
169 | ||
4164020e SM |
170 | struct ctf_fs_msg_iter_data |
171 | { | |
afb0f12b | 172 | bt_logging_level log_level = (bt_logging_level) 0; |
98903a3e | 173 | |
4164020e | 174 | /* Weak */ |
afb0f12b | 175 | bt_self_component *self_comp = nullptr; |
4c65a157 | 176 | |
4164020e | 177 | /* Weak */ |
afb0f12b | 178 | bt_self_message_iterator *self_msg_iter = nullptr; |
5c563278 | 179 | |
4164020e | 180 | /* Weak, belongs to ctf_fs_trace */ |
afb0f12b | 181 | struct ctf_fs_ds_file_group *ds_file_group = nullptr; |
94cf822e | 182 | |
4164020e | 183 | /* Owned by this */ |
afb0f12b | 184 | struct ctf_msg_iter *msg_iter = nullptr; |
cbca1c06 | 185 | |
4164020e SM |
186 | /* |
187 | * Saved error. If we hit an error in the _next method, but have some | |
188 | * messages ready to return, we save the error here and return it on | |
189 | * the next _next call. | |
190 | */ | |
afb0f12b SM |
191 | bt_message_iterator_class_next_method_status next_saved_status = |
192 | BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK; | |
193 | const struct bt_error *next_saved_error = nullptr; | |
f6e68e70 | 194 | |
afb0f12b | 195 | struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr; |
94cf822e PP |
196 | }; |
197 | ||
4164020e SM |
198 | bt_component_class_initialize_method_status |
199 | ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config, | |
200 | const bt_value *params, void *init_method_data); | |
490db841 | 201 | |
b19ff26f | 202 | void ctf_fs_finalize(bt_self_component_source *component); |
d3e4dcd8 | 203 | |
4164020e SM |
204 | bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class, |
205 | bt_private_query_executor *priv_query_exec, | |
206 | const char *object, const bt_value *params, | |
207 | void *method_data, const bt_value **result); | |
55314f2a | 208 | |
4164020e SM |
209 | bt_message_iterator_class_initialize_method_status |
210 | ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter, | |
211 | bt_self_message_iterator_configuration *config, | |
212 | bt_self_component_port_output *self_port); | |
d94d92ac | 213 | |
d6e69534 | 214 | void ctf_fs_iterator_finalize(bt_self_message_iterator *it); |
d3eb6e8f | 215 | |
4164020e SM |
216 | bt_message_iterator_class_next_method_status |
217 | ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs, | |
218 | uint64_t capacity, uint64_t *count); | |
d3eb6e8f | 219 | |
4164020e SM |
220 | bt_message_iterator_class_seek_beginning_method_status |
221 | ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator); | |
6a9bb5e9 | 222 | |
f280892e SM |
223 | /* Create and initialize a new, empty ctf_fs_component. */ |
224 | ||
50b9f4b5 | 225 | struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level); |
f280892e SM |
226 | |
227 | /* | |
a0cd55ad SM |
228 | * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing |
229 | * the same UUID. | |
230 | * | |
231 | * `paths_value` must be an array of strings, | |
232 | * | |
233 | * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`. | |
d23b766e SM |
234 | * |
235 | * `self_comp` and `self_comp_class` are used for logging, only one of them | |
236 | * should be set. | |
f280892e SM |
237 | */ |
238 | ||
4164020e SM |
239 | int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs, |
240 | const bt_value *paths_value, | |
241 | const bt_value *trace_name_value, | |
242 | bt_self_component *self_comp, | |
243 | bt_self_component_class *self_comp_class); | |
f280892e SM |
244 | |
245 | /* Free `ctf_fs` and everything it owns. */ | |
246 | ||
f280892e SM |
247 | void ctf_fs_destroy(struct ctf_fs_component *ctf_fs); |
248 | ||
d907165c SM |
249 | /* |
250 | * Read and validate parameters taken by the src.ctf.fs plugin. | |
251 | * | |
252 | * - The mandatory `paths` parameter is returned in `*paths`. | |
253 | * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if | |
254 | * present, are recorded in the `ctf_fs` structure. | |
005d49d6 SM |
255 | * - The optional `trace-name` parameter is returned in `*trace_name` if |
256 | * present, else `*trace_name` is set to NULL. | |
d907165c | 257 | * |
d23b766e SM |
258 | * `self_comp` and `self_comp_class` are used for logging, only one of them |
259 | * should be set. | |
260 | * | |
d907165c SM |
261 | * Return true on success, false if any parameter didn't pass validation. |
262 | */ | |
f280892e | 263 | |
4164020e SM |
264 | bool read_src_fs_parameters(const bt_value *params, const bt_value **paths, |
265 | const bt_value **trace_name, struct ctf_fs_component *ctf_fs, | |
266 | bt_self_component *self_comp, bt_self_component_class *self_comp_class); | |
f280892e | 267 | |
a38d7650 SM |
268 | /* |
269 | * Generate the port name to be used for a given data stream file group. | |
270 | * | |
271 | * The result must be freed using g_free by the caller. | |
272 | */ | |
273 | ||
a38d7650 SM |
274 | gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group); |
275 | ||
541b0a11 | 276 | #endif /* BABELTRACE_PLUGIN_CTF_FS_H */ |