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