src.ctf.fs: use DataLen in ctf_fs_ds_index_entry
[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
f340a3e8
SM
61struct ctf_fs_component_deleter
62{
63 void operator()(struct ctf_fs_component *);
64};
65
4164020e
SM
66struct ctf_fs_component
67{
f340a3e8
SM
68 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
69
0f5c5d5c
SM
70 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
71 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
72 {
73 }
74
75 bt2c::Logger logger;
98903a3e 76
4164020e 77 /* Array of struct ctf_fs_port_data *, owned by this */
afb0f12b 78 GPtrArray *port_data = nullptr;
1a9f7075 79
4164020e 80 /* Owned by this */
afb0f12b 81 struct ctf_fs_trace *trace = nullptr;
1a9f7075 82
c942e7a2 83 ctf::src::ClkClsCfg clkClsCfg;
1a9f7075
PP
84};
85
4164020e
SM
86struct ctf_fs_trace
87{
0f5c5d5c
SM
88 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
89 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
90 {
91 }
98903a3e 92
0f5c5d5c 93 bt2c::Logger logger;
4c65a157 94
4164020e 95 /* Owned by this */
afb0f12b 96 struct ctf_fs_metadata *metadata = nullptr;
1a9f7075 97
4164020e 98 /* Owned by this */
afb0f12b 99 bt_trace *trace = nullptr;
862ca4ed 100
4164020e 101 /* Array of struct ctf_fs_ds_file_group *, owned by this */
afb0f12b 102 GPtrArray *ds_file_groups = nullptr;
94cf822e 103
4164020e 104 /* Owned by this */
afb0f12b 105 GString *path = nullptr;
1a9f7075 106
4164020e 107 /* Next automatic stream ID when not provided by packet header */
afb0f12b 108 uint64_t next_stream_id = 0;
1a9f7075
PP
109};
110
4164020e
SM
111struct ctf_fs_ds_index_entry
112{
ef7d7ac2
SM
113 explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
114 const bt2c::DataLen packetSizeParam) noexcept :
115 offset(offsetParam),
116 packetSize(packetSizeParam)
117 {
118 }
119
4164020e 120 /* Weak, belongs to ctf_fs_ds_file_info. */
afb0f12b 121 const char *path = nullptr;
4164020e 122
ef7d7ac2
SM
123 /* Position of the packet from the beginning of the file. */
124 bt2c::DataLen offset;
4164020e 125
ef7d7ac2
SM
126 /* Size of the packet. */
127 bt2c::DataLen packetSize;
4164020e
SM
128
129 /*
130 * Extracted from the packet context, relative to the respective fields'
131 * mapped clock classes (in cycles).
132 */
afb0f12b 133 uint64_t timestamp_begin = 0, timestamp_end = 0;
4164020e
SM
134
135 /*
136 * Converted from the packet context, relative to the trace's EPOCH
137 * (in ns since EPOCH).
138 */
afb0f12b 139 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
4164020e
SM
140
141 /*
142 * Packet sequence number, or UINT64_MAX if not present in the index.
143 */
afb0f12b 144 uint64_t packet_seq_num = 0;
7ed5243a
FD
145};
146
4164020e
SM
147struct ctf_fs_ds_index
148{
149 /* Array of pointer to struct ctf_fs_ds_index_entry. */
afb0f12b 150 GPtrArray *entries = nullptr;
7ed5243a
FD
151};
152
4164020e
SM
153struct ctf_fs_ds_file_group
154{
155 /*
156 * Array of struct ctf_fs_ds_file_info, owned by this.
157 *
158 * This is an _ordered_ array of data stream file infos which
159 * belong to this group (a single stream instance).
160 *
161 * You can call ctf_fs_ds_file_create() with one of those paths
162 * and the trace IR stream below.
163 */
afb0f12b 164 GPtrArray *ds_file_infos = nullptr;
4164020e
SM
165
166 /* Owned by this */
afb0f12b 167 struct ctf_stream_class *sc = nullptr;
4164020e
SM
168
169 /* Owned by this */
afb0f12b 170 bt_stream *stream = nullptr;
4164020e
SM
171
172 /* Stream (instance) ID; -1ULL means none */
afb0f12b 173 uint64_t stream_id = 0;
4164020e
SM
174
175 /* Weak, belongs to component */
afb0f12b 176 struct ctf_fs_trace *ctf_fs_trace = nullptr;
4164020e
SM
177
178 /*
179 * Owned by this.
180 */
afb0f12b 181 struct ctf_fs_ds_index *index = nullptr;
ea0b4b9e
JG
182};
183
4164020e
SM
184struct ctf_fs_port_data
185{
186 /* Weak, belongs to ctf_fs_trace */
afb0f12b 187 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
5c563278 188
4164020e 189 /* Weak */
afb0f12b 190 struct ctf_fs_component *ctf_fs = nullptr;
94cf822e
PP
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.116219 seconds and 4 git commands to generate.