src.ctf.fs: make ctf_fs_component::trace a unique_ptr
[babeltrace.git] / src / plugins / ctf / fs-src / fs.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
6 *
7 * BabelTrace - CTF on File System Component
8 */
9
10 #ifndef BABELTRACE_PLUGIN_CTF_FS_H
11 #define BABELTRACE_PLUGIN_CTF_FS_H
12
13 #include <glib.h>
14
15 #include <babeltrace2/babeltrace.h>
16
17 #include "cpp-common/bt2c/data-len.hpp"
18 #include "cpp-common/bt2c/glib-up.hpp"
19 #include "cpp-common/bt2c/logging.hpp"
20
21 #include "metadata.hpp"
22 #include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
23
24 extern bool ctf_fs_debug;
25
26 struct ctf_fs_file
27 {
28 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
29 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
30 {
31 }
32
33 bt2c::Logger logger;
34
35 /* Owned by this */
36 GString *path = nullptr;
37
38 /* Owned by this */
39 FILE *fp = nullptr;
40
41 off_t size = 0;
42 };
43
44 struct ctf_fs_metadata
45 {
46 /* Owned by this */
47 ctf_metadata_decoder_up decoder;
48
49 /* Owned by this */
50 bt_trace_class *trace_class = nullptr;
51
52 /* Weak (owned by `decoder` above) */
53 struct ctf_trace_class *tc = nullptr;
54
55 /* Owned by this */
56 char *text = nullptr;
57
58 int bo = 0;
59 };
60
61 struct ctf_fs_trace_deleter
62 {
63 void operator()(ctf_fs_trace *) noexcept;
64 };
65
66 struct ctf_fs_trace
67 {
68 using UP = std::unique_ptr<ctf_fs_trace, ctf_fs_trace_deleter>;
69
70 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
71 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
72 {
73 }
74
75 bt2c::Logger logger;
76
77 /* Owned by this */
78 struct ctf_fs_metadata *metadata = nullptr;
79
80 /* Owned by this */
81 bt_trace *trace = nullptr;
82
83 /* Array of struct ctf_fs_ds_file_group *, owned by this */
84 GPtrArray *ds_file_groups = nullptr;
85
86 /* Owned by this */
87 GString *path = nullptr;
88
89 /* Next automatic stream ID when not provided by packet header */
90 uint64_t next_stream_id = 0;
91 };
92
93 struct ctf_fs_port_data
94 {
95 /* Weak, belongs to ctf_fs_trace */
96 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
97
98 /* Weak */
99 struct ctf_fs_component *ctf_fs = nullptr;
100 };
101
102 struct ctf_fs_component_deleter
103 {
104 void operator()(ctf_fs_component *);
105 };
106
107 struct ctf_fs_component
108 {
109 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
110
111 explicit ctf_fs_component(const bt2c::Logger& parentLogger) noexcept :
112 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
113 {
114 }
115
116 bt2c::Logger logger;
117
118 /* Array of struct ctf_fs_port_data *, owned by this */
119 GPtrArray *port_data = nullptr;
120
121 ctf_fs_trace::UP trace;
122
123 ctf::src::ClkClsCfg clkClsCfg;
124 };
125
126 struct ctf_fs_ds_index_entry
127 {
128 explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
129 const bt2c::DataLen packetSizeParam) noexcept :
130 offset(offsetParam),
131 packetSize(packetSizeParam)
132 {
133 }
134
135 /* Weak, belongs to ctf_fs_ds_file_info. */
136 const char *path = nullptr;
137
138 /* Position of the packet from the beginning of the file. */
139 bt2c::DataLen offset;
140
141 /* Size of the packet. */
142 bt2c::DataLen packetSize;
143
144 /*
145 * Extracted from the packet context, relative to the respective fields'
146 * mapped clock classes (in cycles).
147 */
148 uint64_t timestamp_begin = 0, timestamp_end = 0;
149
150 /*
151 * Converted from the packet context, relative to the trace's EPOCH
152 * (in ns since EPOCH).
153 */
154 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
155
156 /*
157 * Packet sequence number, or UINT64_MAX if not present in the index.
158 */
159 uint64_t packet_seq_num = 0;
160 };
161
162 struct ctf_fs_ds_index
163 {
164 /* Array of pointer to struct ctf_fs_ds_index_entry. */
165 GPtrArray *entries = nullptr;
166 };
167
168 struct ctf_fs_ds_file_group
169 {
170 /*
171 * Array of struct ctf_fs_ds_file_info, owned by this.
172 *
173 * This is an _ordered_ array of data stream file infos which
174 * belong to this group (a single stream instance).
175 *
176 * You can call ctf_fs_ds_file_create() with one of those paths
177 * and the trace IR stream below.
178 */
179 GPtrArray *ds_file_infos = nullptr;
180
181 /* Owned by this */
182 struct ctf_stream_class *sc = nullptr;
183
184 /* Owned by this */
185 bt_stream *stream = nullptr;
186
187 /* Stream (instance) ID; -1ULL means none */
188 uint64_t stream_id = 0;
189
190 /* Weak, belongs to component */
191 struct ctf_fs_trace *ctf_fs_trace = nullptr;
192
193 /*
194 * Owned by this.
195 */
196 struct ctf_fs_ds_index *index = nullptr;
197 };
198
199 struct ctf_fs_msg_iter_data
200 {
201 explicit ctf_fs_msg_iter_data(bt_self_message_iterator *selfMsgIter) :
202 self_msg_iter {selfMsgIter}, logger {bt2::SelfMessageIterator {self_msg_iter},
203 "PLUGIN/SRC.CTF.FS/MSG-ITER"}
204 {
205 }
206
207 /* Weak */
208 bt_self_message_iterator *self_msg_iter = nullptr;
209
210 bt2c::Logger logger;
211
212 /* Weak, belongs to ctf_fs_trace */
213 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
214
215 /* Owned by this */
216 struct ctf_msg_iter *msg_iter = nullptr;
217
218 /*
219 * Saved error. If we hit an error in the _next method, but have some
220 * messages ready to return, we save the error here and return it on
221 * the next _next call.
222 */
223 bt_message_iterator_class_next_method_status next_saved_status =
224 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
225 const struct bt_error *next_saved_error = nullptr;
226
227 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
228 };
229
230 bt_component_class_initialize_method_status
231 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
232 const bt_value *params, void *init_method_data);
233
234 void ctf_fs_finalize(bt_self_component_source *component);
235
236 bt_component_class_query_method_status ctf_fs_query(bt_self_component_class_source *comp_class,
237 bt_private_query_executor *priv_query_exec,
238 const char *object, const bt_value *params,
239 void *method_data, const bt_value **result);
240
241 bt_message_iterator_class_initialize_method_status
242 ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
243 bt_self_message_iterator_configuration *config,
244 bt_self_component_port_output *self_port);
245
246 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
247
248 bt_message_iterator_class_next_method_status
249 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
250 uint64_t capacity, uint64_t *count);
251
252 bt_message_iterator_class_seek_beginning_method_status
253 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
254
255 /* Create and initialize a new, empty ctf_fs_component. */
256
257 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
258
259 /*
260 * Create one `struct ctf_fs_trace` from one trace, or multiple traces sharing
261 * the same UUID.
262 *
263 * `paths_value` must be an array of strings,
264 *
265 * The created `struct ctf_fs_trace` is assigned to `ctf_fs->trace`.
266 *
267 * `self_comp` and `self_comp_class` are used for logging, only one of them
268 * should be set.
269 */
270
271 int ctf_fs_component_create_ctf_fs_trace(struct ctf_fs_component *ctf_fs,
272 const bt_value *paths_value,
273 const bt_value *trace_name_value,
274 bt_self_component *selfComp);
275
276 /* Free `ctf_fs` and everything it owns. */
277
278 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
279
280 /*
281 * Read and validate parameters taken by the src.ctf.fs plugin.
282 *
283 * - The mandatory `paths` parameter is returned in `*paths`.
284 * - The optional `clock-class-offset-s` and `clock-class-offset-ns`, if
285 * present, are recorded in the `ctf_fs` structure.
286 * - The optional `trace-name` parameter is returned in `*trace_name` if
287 * present, else `*trace_name` is set to NULL.
288 *
289 * `self_comp` and `self_comp_class` are used for logging, only one of them
290 * should be set.
291 *
292 * Return true on success, false if any parameter didn't pass validation.
293 */
294
295 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
296 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
297
298 /*
299 * Generate the port name to be used for a given data stream file group.
300 */
301
302 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
303
304 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.036506 seconds and 5 git commands to generate.