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