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
13 #include <babeltrace2/babeltrace.h>
15 #include "common/macros.h"
17 #include "../common/metadata/decoder.hpp"
18 #include "data-stream-file.hpp"
19 #include "metadata.hpp"
21 extern bool ctf_fs_debug;
25 bt_logging_level log_level;
28 bt_self_component *self_comp;
39 struct ctf_fs_metadata
42 struct ctf_metadata_decoder *decoder;
45 bt_trace_class *trace_class;
47 /* Weak (owned by `decoder` above) */
48 struct ctf_trace_class *tc;
56 struct ctf_fs_component
58 bt_logging_level log_level;
60 /* Array of struct ctf_fs_port_data *, owned by this */
64 struct ctf_fs_trace *trace;
66 struct ctf_fs_metadata_config metadata_config;
71 bt_logging_level log_level;
74 * Weak. These are mostly used to generate log messages or to append
75 * error causes. They are mutually exclusive, only one of them must be
78 bt_self_component *self_comp;
79 bt_self_component_class *self_comp_class;
82 struct ctf_fs_metadata *metadata;
87 /* Array of struct ctf_fs_ds_file_group *, owned by this */
88 GPtrArray *ds_file_groups;
93 /* Next automatic stream ID when not provided by packet header */
94 uint64_t next_stream_id;
97 struct ctf_fs_ds_index_entry
99 /* Weak, belongs to ctf_fs_ds_file_info. */
102 /* Position, in bytes, of the packet from the beginning of the file. */
105 /* Size of the packet, in bytes. */
106 uint64_t packet_size;
109 * Extracted from the packet context, relative to the respective fields'
110 * mapped clock classes (in cycles).
112 uint64_t timestamp_begin, timestamp_end;
115 * Converted from the packet context, relative to the trace's EPOCH
116 * (in ns since EPOCH).
118 int64_t timestamp_begin_ns, timestamp_end_ns;
121 * Packet sequence number, or UINT64_MAX if not present in the index.
123 uint64_t packet_seq_num;
126 struct ctf_fs_ds_index
128 /* Array of pointer to struct ctf_fs_ds_index_entry. */
132 struct ctf_fs_ds_file_group
135 * Array of struct ctf_fs_ds_file_info, owned by this.
137 * This is an _ordered_ array of data stream file infos which
138 * belong to this group (a single stream instance).
140 * You can call ctf_fs_ds_file_create() with one of those paths
141 * and the trace IR stream below.
143 GPtrArray *ds_file_infos;
146 struct ctf_stream_class *sc;
151 /* Stream (instance) ID; -1ULL means none */
154 /* Weak, belongs to component */
155 struct ctf_fs_trace *ctf_fs_trace;
160 struct ctf_fs_ds_index *index;
163 struct ctf_fs_port_data
165 /* Weak, belongs to ctf_fs_trace */
166 struct ctf_fs_ds_file_group *ds_file_group;
169 struct ctf_fs_component *ctf_fs;
172 struct ctf_fs_msg_iter_data
174 bt_logging_level log_level;
177 bt_self_component *self_comp;
180 bt_self_message_iterator *self_msg_iter;
182 /* Weak, belongs to ctf_fs_trace */
183 struct ctf_fs_ds_file_group *ds_file_group;
186 struct ctf_msg_iter *msg_iter;
189 * Saved error. If we hit an error in the _next method, but have some
190 * messages ready to return, we save the error here and return it on
191 * the next _next call.
193 bt_message_iterator_class_next_method_status next_saved_status;
194 const struct bt_error *next_saved_error;
196 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data;
199 bt_component_class_initialize_method_status
200 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
201 const bt_value *params, void *init_method_data);
203 void ctf_fs_finalize(bt_self_component_source *component);
205 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
206 bt_private_query_executor *priv_query_exec,
207 const char *object, const bt_value *params,
208 void *method_data, const bt_value **result);
210 bt_message_iterator_class_initialize_method_status
211 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
212 bt_self_message_iterator_configuration *config,
213 bt_self_component_port_output *self_port);
215 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
217 bt_message_iterator_class_next_method_status
218 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
219 uint64_t capacity, uint64_t *count);
221 bt_message_iterator_class_seek_beginning_method_status
222 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
224 /* Create and initialize a new, empty ctf_fs_component. */
226 struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level);
229 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
232 * `paths_value` must be an array of strings,
234 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
236 * `self_comp` and `self_comp_class` are used for logging, only one of them
240 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
241 const bt_value *paths_value,
242 const bt_value *trace_name_value,
243 bt_self_component *self_comp,
244 bt_self_component_class *self_comp_class);
246 /* Free `ctf_fs` and everything it owns. */
248 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
251 * Read and validate parameters taken by the src.ctf.fs plugin.
253 * - The mandatory `paths` parameter is returned in `*paths`.
254 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
255 * present, are recorded in the `ctf_fs` structure.
256 * - The optional `trace-name` parameter is returned in `*trace_name` if
257 * present, else `*trace_name` is set to NULL.
259 * `self_comp` and `self_comp_class` are used for logging, only one of them
262 * Return true on success, false if any parameter didn't pass validation.
265 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
266 const bt_value **trace_name, struct ctf_fs_component *ctf_fs,
267 bt_self_component *self_comp, bt_self_component_class *self_comp_class);
270 * Generate the port name to be used for a given data stream file group.
272 * The result must be freed using g_free by the caller.
275 gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
277 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */