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"
22 extern bool ctf_fs_debug;
26 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
27 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
34 GString *path = nullptr;
42 struct ctf_fs_metadata
45 struct ctf_metadata_decoder *decoder = nullptr;
48 bt_trace_class *trace_class = nullptr;
50 /* Weak (owned by `decoder` above) */
51 struct ctf_trace_class *tc = nullptr;
59 struct ctf_fs_component_deleter
61 void operator()(struct ctf_fs_component *);
64 struct ctf_fs_component
66 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
68 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
69 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
75 /* Array of struct ctf_fs_port_data *, owned by this */
76 GPtrArray *port_data = nullptr;
79 struct ctf_fs_trace *trace = nullptr;
81 struct ctf_fs_metadata_config metadata_config;
86 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
87 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
94 struct ctf_fs_metadata *metadata = nullptr;
97 bt_trace *trace = nullptr;
99 /* Array of struct ctf_fs_ds_file_group *, owned by this */
100 GPtrArray *ds_file_groups = nullptr;
103 GString *path = nullptr;
105 /* Next automatic stream ID when not provided by packet header */
106 uint64_t next_stream_id = 0;
109 struct ctf_fs_ds_index_entry
111 /* Weak, belongs to ctf_fs_ds_file_info. */
112 const char *path = nullptr;
114 /* Position, in bytes, of the packet from the beginning of the file. */
117 /* Size of the packet, in bytes. */
118 uint64_t packet_size = 0;
121 * Extracted from the packet context, relative to the respective fields'
122 * mapped clock classes (in cycles).
124 uint64_t timestamp_begin = 0, timestamp_end = 0;
127 * Converted from the packet context, relative to the trace's EPOCH
128 * (in ns since EPOCH).
130 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
133 * Packet sequence number, or UINT64_MAX if not present in the index.
135 uint64_t packet_seq_num = 0;
138 struct ctf_fs_ds_index
140 /* Array of pointer to struct ctf_fs_ds_index_entry. */
141 GPtrArray *entries = nullptr;
144 struct ctf_fs_ds_file_group
147 * Array of struct ctf_fs_ds_file_info, owned by this.
149 * This is an _ordered_ array of data stream file infos which
150 * belong to this group (a single stream instance).
152 * You can call ctf_fs_ds_file_create() with one of those paths
153 * and the trace IR stream below.
155 GPtrArray *ds_file_infos = nullptr;
158 struct ctf_stream_class *sc = nullptr;
161 bt_stream *stream = nullptr;
163 /* Stream (instance) ID; -1ULL means none */
164 uint64_t stream_id = 0;
166 /* Weak, belongs to component */
167 struct ctf_fs_trace *ctf_fs_trace = nullptr;
172 struct ctf_fs_ds_index *index = nullptr;
175 struct ctf_fs_port_data
177 /* Weak, belongs to ctf_fs_trace */
178 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
181 struct ctf_fs_component *ctf_fs = nullptr;
184 struct ctf_fs_msg_iter_data
186 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
187 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
188 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
193 bt_self_message_iterator *self_msg_iter = nullptr;
197 /* Weak, belongs to ctf_fs_trace */
198 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
201 struct ctf_msg_iter *msg_iter = nullptr;
204 * Saved error. If we hit an error in the _next method, but have some
205 * messages ready to return, we save the error here and return it on
206 * the next _next call.
208 bt_message_iterator_class_next_method_status next_saved_status =
209 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
210 const struct bt_error *next_saved_error = nullptr;
212 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
215 bt_component_class_initialize_method_status
216 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
217 const bt_value *params, void *init_method_data);
219 void ctf_fs_finalize(bt_self_component_source *component);
221 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
222 bt_private_query_executor *priv_query_exec,
223 const char *object, const bt_value *params,
224 void *method_data, const bt_value **result);
226 bt_message_iterator_class_initialize_method_status
227 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
228 bt_self_message_iterator_configuration *config,
229 bt_self_component_port_output *self_port);
231 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
233 bt_message_iterator_class_next_method_status
234 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
235 uint64_t capacity, uint64_t *count);
237 bt_message_iterator_class_seek_beginning_method_status
238 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
240 /* Create and initialize a new, empty ctf_fs_component. */
242 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
245 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
248 * `paths_value` must be an array of strings,
250 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
252 * `self_comp` and `self_comp_class` are used for logging, only one of them
256 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
257 const bt_value *paths_value,
258 const bt_value *trace_name_value,
259 bt_self_component *selfComp);
261 /* Free `ctf_fs` and everything it owns. */
263 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
266 * Read and validate parameters taken by the src.ctf.fs plugin.
268 * - The mandatory `paths` parameter is returned in `*paths`.
269 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
270 * present, are recorded in the `ctf_fs` structure.
271 * - The optional `trace-name` parameter is returned in `*trace_name` if
272 * present, else `*trace_name` is set to NULL.
274 * `self_comp` and `self_comp_class` are used for logging, only one of them
277 * Return true on success, false if any parameter didn't pass validation.
280 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
281 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
284 * Generate the port name to be used for a given data stream file group.
287 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
289 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */