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/logging.hpp"
19 #include "metadata.hpp"
21 extern bool ctf_fs_debug;
25 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
26 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
33 GString *path = nullptr;
41 struct ctf_fs_metadata
44 struct ctf_metadata_decoder *decoder = nullptr;
47 bt_trace_class *trace_class = nullptr;
49 /* Weak (owned by `decoder` above) */
50 struct ctf_trace_class *tc = nullptr;
58 struct ctf_fs_component
60 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
61 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
67 /* Array of struct ctf_fs_port_data *, owned by this */
68 GPtrArray *port_data = nullptr;
71 struct ctf_fs_trace *trace = nullptr;
73 struct ctf_fs_metadata_config metadata_config;
78 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
79 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
86 struct ctf_fs_metadata *metadata = nullptr;
89 bt_trace *trace = nullptr;
91 /* Array of struct ctf_fs_ds_file_group *, owned by this */
92 GPtrArray *ds_file_groups = nullptr;
95 GString *path = nullptr;
97 /* Next automatic stream ID when not provided by packet header */
98 uint64_t next_stream_id = 0;
101 struct ctf_fs_ds_index_entry
103 /* Weak, belongs to ctf_fs_ds_file_info. */
104 const char *path = nullptr;
106 /* Position, in bytes, of the packet from the beginning of the file. */
109 /* Size of the packet, in bytes. */
110 uint64_t packet_size = 0;
113 * Extracted from the packet context, relative to the respective fields'
114 * mapped clock classes (in cycles).
116 uint64_t timestamp_begin = 0, timestamp_end = 0;
119 * Converted from the packet context, relative to the trace's EPOCH
120 * (in ns since EPOCH).
122 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
125 * Packet sequence number, or UINT64_MAX if not present in the index.
127 uint64_t packet_seq_num = 0;
130 struct ctf_fs_ds_index
132 /* Array of pointer to struct ctf_fs_ds_index_entry. */
133 GPtrArray *entries = nullptr;
136 struct ctf_fs_ds_file_group
139 * Array of struct ctf_fs_ds_file_info, owned by this.
141 * This is an _ordered_ array of data stream file infos which
142 * belong to this group (a single stream instance).
144 * You can call ctf_fs_ds_file_create() with one of those paths
145 * and the trace IR stream below.
147 GPtrArray *ds_file_infos = nullptr;
150 struct ctf_stream_class *sc = nullptr;
153 bt_stream *stream = nullptr;
155 /* Stream (instance) ID; -1ULL means none */
156 uint64_t stream_id = 0;
158 /* Weak, belongs to component */
159 struct ctf_fs_trace *ctf_fs_trace = nullptr;
164 struct ctf_fs_ds_index *index = nullptr;
167 struct ctf_fs_port_data
169 /* Weak, belongs to ctf_fs_trace */
170 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
173 struct ctf_fs_component *ctf_fs = nullptr;
176 struct ctf_fs_msg_iter_data
178 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
179 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
180 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
185 bt_self_message_iterator *self_msg_iter = nullptr;
189 /* Weak, belongs to ctf_fs_trace */
190 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
193 struct ctf_msg_iter *msg_iter = nullptr;
196 * Saved error. If we hit an error in the _next method, but have some
197 * messages ready to return, we save the error here and return it on
198 * the next _next call.
200 bt_message_iterator_class_next_method_status next_saved_status =
201 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
202 const struct bt_error *next_saved_error = nullptr;
204 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
207 bt_component_class_initialize_method_status
208 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
209 const bt_value *params, void *init_method_data);
211 void ctf_fs_finalize(bt_self_component_source *component);
213 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
214 bt_private_query_executor *priv_query_exec,
215 const char *object, const bt_value *params,
216 void *method_data, const bt_value **result);
218 bt_message_iterator_class_initialize_method_status
219 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
220 bt_self_message_iterator_configuration *config,
221 bt_self_component_port_output *self_port);
223 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
225 bt_message_iterator_class_next_method_status
226 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
227 uint64_t capacity, uint64_t *count);
229 bt_message_iterator_class_seek_beginning_method_status
230 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
232 /* Create and initialize a new, empty ctf_fs_component. */
234 ctf_fs_component *ctf_fs_component_create(const bt2c::Logger& parentLogger);
237 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
240 * `paths_value` must be an array of strings,
242 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
244 * `self_comp` and `self_comp_class` are used for logging, only one of them
248 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
249 const bt_value *paths_value,
250 const bt_value *trace_name_value,
251 bt_self_component *selfComp);
253 /* Free `ctf_fs` and everything it owns. */
255 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
258 * Read and validate parameters taken by the src.ctf.fs plugin.
260 * - The mandatory `paths` parameter is returned in `*paths`.
261 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
262 * present, are recorded in the `ctf_fs` structure.
263 * - The optional `trace-name` parameter is returned in `*trace_name` if
264 * present, else `*trace_name` is set to NULL.
266 * `self_comp` and `self_comp_class` are used for logging, only one of them
269 * Return true on success, false if any parameter didn't pass validation.
272 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
273 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
276 * Generate the port name to be used for a given data stream file group.
278 * The result must be freed using g_free by the caller.
281 gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
283 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */