2 * SPDX-License-Identifier: MIT
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
7 * BabelTrace - CTF on File System Component
10 #ifndef BABELTRACE_PLUGIN_CTF_FS_H
11 #define BABELTRACE_PLUGIN_CTF_FS_H
15 #include <babeltrace2/babeltrace.h>
17 #include "cpp-common/bt2c/glib-up.hpp"
18 #include "cpp-common/bt2c/logging.hpp"
20 #include "metadata.hpp"
21 #include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
23 extern bool ctf_fs_debug;
27 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
28 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
35 GString *path = nullptr;
43 struct ctf_fs_metadata
46 ctf_metadata_decoder_up decoder;
49 bt_trace_class *trace_class = nullptr;
51 /* Weak (owned by `decoder` above) */
52 struct ctf_trace_class *tc = nullptr;
60 struct ctf_fs_component_deleter
62 void operator()(struct ctf_fs_component *);
65 struct ctf_fs_component
67 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
69 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
70 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
76 /* Array of struct ctf_fs_port_data *, owned by this */
77 GPtrArray *port_data = nullptr;
80 struct ctf_fs_trace *trace = nullptr;
82 struct ctf_fs_metadata_config metadata_config;
87 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
88 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
95 struct ctf_fs_metadata *metadata = nullptr;
98 bt_trace *trace = nullptr;
100 /* Array of struct ctf_fs_ds_file_group *, owned by this */
101 GPtrArray *ds_file_groups = nullptr;
104 GString *path = nullptr;
106 /* Next automatic stream ID when not provided by packet header */
107 uint64_t next_stream_id = 0;
110 struct ctf_fs_ds_index_entry
112 /* Weak, belongs to ctf_fs_ds_file_info. */
113 const char *path = nullptr;
115 /* Position, in bytes, of the packet from the beginning of the file. */
118 /* Size of the packet, in bytes. */
119 uint64_t packet_size = 0;
122 * Extracted from the packet context, relative to the respective fields'
123 * mapped clock classes (in cycles).
125 uint64_t timestamp_begin = 0, timestamp_end = 0;
128 * Converted from the packet context, relative to the trace's EPOCH
129 * (in ns since EPOCH).
131 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
134 * Packet sequence number, or UINT64_MAX if not present in the index.
136 uint64_t packet_seq_num = 0;
139 struct ctf_fs_ds_index
141 /* Array of pointer to struct ctf_fs_ds_index_entry. */
142 GPtrArray *entries = nullptr;
145 struct ctf_fs_ds_file_group
148 * Array of struct ctf_fs_ds_file_info, owned by this.
150 * This is an _ordered_ array of data stream file infos which
151 * belong to this group (a single stream instance).
153 * You can call ctf_fs_ds_file_create() with one of those paths
154 * and the trace IR stream below.
156 GPtrArray *ds_file_infos = nullptr;
159 struct ctf_stream_class *sc = nullptr;
162 bt_stream *stream = nullptr;
164 /* Stream (instance) ID; -1ULL means none */
165 uint64_t stream_id = 0;
167 /* Weak, belongs to component */
168 struct ctf_fs_trace *ctf_fs_trace = nullptr;
173 struct ctf_fs_ds_index *index = nullptr;
176 struct ctf_fs_port_data
178 /* Weak, belongs to ctf_fs_trace */
179 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
182 struct ctf_fs_component *ctf_fs = nullptr;
185 struct ctf_fs_msg_iter_data
187 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
188 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
189 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
194 bt_self_message_iterator *self_msg_iter = nullptr;
198 /* Weak, belongs to ctf_fs_trace */
199 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
202 struct ctf_msg_iter *msg_iter = nullptr;
205 * Saved error. If we hit an error in the _next method, but have some
206 * messages ready to return, we save the error here and return it on
207 * the next _next call.
209 bt_message_iterator_class_next_method_status next_saved_status =
210 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
211 const struct bt_error *next_saved_error = nullptr;
213 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
216 bt_component_class_initialize_method_status
217 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
218 const bt_value *params, void *init_method_data);
220 void ctf_fs_finalize(bt_self_component_source *component);
222 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
223 bt_private_query_executor *priv_query_exec,
224 const char *object, const bt_value *params,
225 void *method_data, const bt_value **result);
227 bt_message_iterator_class_initialize_method_status
228 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
229 bt_self_message_iterator_configuration *config,
230 bt_self_component_port_output *self_port);
232 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
234 bt_message_iterator_class_next_method_status
235 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
236 uint64_t capacity, uint64_t *count);
238 bt_message_iterator_class_seek_beginning_method_status
239 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
241 /* Create and initialize a new, empty ctf_fs_component. */
243 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
246 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
249 * `paths_value` must be an array of strings,
251 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
253 * `self_comp` and `self_comp_class` are used for logging, only one of them
257 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
258 const bt_value *paths_value,
259 const bt_value *trace_name_value,
260 bt_self_component *selfComp);
262 /* Free `ctf_fs` and everything it owns. */
264 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
267 * Read and validate parameters taken by the src.ctf.fs plugin.
269 * - The mandatory `paths` parameter is returned in `*paths`.
270 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
271 * present, are recorded in the `ctf_fs` structure.
272 * - The optional `trace-name` parameter is returned in `*trace_name` if
273 * present, else `*trace_name` is set to NULL.
275 * `self_comp` and `self_comp_class` are used for logging, only one of them
278 * Return true on success, false if any parameter didn't pass validation.
281 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
282 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
285 * Generate the port name to be used for a given data stream file group.
288 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
290 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */