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