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 "data-stream-file.hpp"
21 #include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
23 extern bool ctf_fs_debug;
25 struct ctf_fs_metadata
28 ctf_metadata_decoder_up decoder;
31 bt_trace_class *trace_class = nullptr;
33 /* Weak (owned by `decoder` above) */
34 struct ctf_trace_class *tc = nullptr;
42 struct ctf_fs_trace_deleter
44 void operator()(ctf_fs_trace *) noexcept;
49 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
51 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
52 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
59 struct ctf_fs_metadata *metadata = nullptr;
61 bt2::Trace::Shared trace;
63 std::vector<ctf_fs_ds_file_group::UP> ds_file_groups;
66 GString *path = nullptr;
68 /* Next automatic stream ID when not provided by packet header */
69 uint64_t next_stream_id = 0;
72 struct ctf_fs_port_data
74 using UP = std::unique_ptr<ctf_fs_port_data>;
76 /* Weak, belongs to ctf_fs_trace */
77 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
80 struct ctf_fs_component *ctf_fs = nullptr;
83 struct ctf_fs_component
85 using UP = std::unique_ptr<ctf_fs_component>;
87 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
88 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
94 std::vector<ctf_fs_port_data::UP> port_data;
96 ctf_fs_trace::UP trace;
98 ctf::src::ClkClsCfg clkClsCfg;
101 struct ctf_fs_msg_iter_data
103 using UP = std::unique_ptr<ctf_fs_msg_iter_data>;
105 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
106 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
107 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
112 bt_self_message_iterator *self_msg_iter = nullptr;
116 /* Weak, belongs to ctf_fs_trace */
117 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
119 ctf_msg_iter_up msg_iter;
122 * Saved error. If we hit an error in the _next method, but have some
123 * messages ready to return, we save the error here and return it on
124 * the next _next call.
126 bt_message_iterator_class_next_method_status next_saved_status =
127 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
128 const struct bt_error *next_saved_error = nullptr;
130 ctf_fs_ds_group_medops_data_up msg_iter_medops_data;
133 bt_component_class_initialize_method_status
134 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
135 const bt_value *params, void *init_method_data);
137 void ctf_fs_finalize(bt_self_component_source *component);
139 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
140 bt_private_query_executor *priv_query_exec,
141 const char *object, const bt_value *params,
142 void *method_data, const bt_value **result);
144 bt_message_iterator_class_initialize_method_status
145 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
146 bt_self_message_iterator_configuration *config,
147 bt_self_component_port_output *self_port);
149 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
151 bt_message_iterator_class_next_method_status
152 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
153 uint64_t capacity, uint64_t *count);
155 bt_message_iterator_class_seek_beginning_method_status
156 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
158 /* Create and initialize a new, empty ctf_fs_component. */
160 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
163 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
166 * `paths_value` must be an array of strings,
168 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
170 * `self_comp` and `self_comp_class` are used for logging, only one of them
174 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
175 const bt_value *paths_value,
176 const bt_value *trace_name_value,
177 bt_self_component *selfComp);
180 * Read and validate parameters taken by the src.ctf.fs plugin.
182 * - The mandatory `paths` parameter is returned in `*paths`.
183 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
184 * present, are recorded in the `ctf_fs` structure.
185 * - The optional `trace-name` parameter is returned in `*trace_name` if
186 * present, else `*trace_name` is set to NULL.
188 * `self_comp` and `self_comp_class` are used for logging, only one of them
191 * Return true on success, false if any parameter didn't pass validation.
194 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
195 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
198 * Generate the port name to be used for a given data stream file group.
201 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
203 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */