src.ctf.fs: use DataLen in ctf_fs_ds_index_entry
[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_component_deleter
62 {
63 void operator()(struct ctf_fs_component *);
64 };
65
66 struct ctf_fs_component
67 {
68 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
69
70 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
71 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
72 {
73 }
74
75 bt2c::Logger logger;
76
77 /* Array of struct ctf_fs_port_data *, owned by this */
78 GPtrArray *port_data = nullptr;
79
80 /* Owned by this */
81 struct ctf_fs_trace *trace = nullptr;
82
83 ctf::src::ClkClsCfg clkClsCfg;
84 };
85
86 struct ctf_fs_trace
87 {
88 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
89 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
90 {
91 }
92
93 bt2c::Logger logger;
94
95 /* Owned by this */
96 struct ctf_fs_metadata *metadata = nullptr;
97
98 /* Owned by this */
99 bt_trace *trace = nullptr;
100
101 /* Array of struct ctf_fs_ds_file_group *, owned by this */
102 GPtrArray *ds_file_groups = nullptr;
103
104 /* Owned by this */
105 GString *path = nullptr;
106
107 /* Next automatic stream ID when not provided by packet header */
108 uint64_t next_stream_id = 0;
109 };
110
111 struct ctf_fs_ds_index_entry
112 {
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
120 /* Weak, belongs to ctf_fs_ds_file_info. */
121 const char *path = nullptr;
122
123 /* Position of the packet from the beginning of the file. */
124 bt2c::DataLen offset;
125
126 /* Size of the packet. */
127 bt2c::DataLen packetSize;
128
129 /*
130 * Extracted from the packet context, relative to the respective fields'
131 * mapped clock classes (in cycles).
132 */
133 uint64_t timestamp_begin = 0, timestamp_end = 0;
134
135 /*
136 * Converted from the packet context, relative to the trace's EPOCH
137 * (in ns since EPOCH).
138 */
139 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
140
141 /*
142 * Packet sequence number, or UINT64_MAX if not present in the index.
143 */
144 uint64_t packet_seq_num = 0;
145 };
146
147 struct ctf_fs_ds_index
148 {
149 /* Array of pointer to struct ctf_fs_ds_index_entry. */
150 GPtrArray *entries = nullptr;
151 };
152
153 struct 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 */
164 GPtrArray *ds_file_infos = nullptr;
165
166 /* Owned by this */
167 struct ctf_stream_class *sc = nullptr;
168
169 /* Owned by this */
170 bt_stream *stream = nullptr;
171
172 /* Stream (instance) ID; -1ULL means none */
173 uint64_t stream_id = 0;
174
175 /* Weak, belongs to component */
176 struct ctf_fs_trace *ctf_fs_trace = nullptr;
177
178 /*
179 * Owned by this.
180 */
181 struct ctf_fs_ds_index *index = nullptr;
182 };
183
184 struct ctf_fs_port_data
185 {
186 /* Weak, belongs to ctf_fs_trace */
187 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
188
189 /* Weak */
190 struct ctf_fs_component *ctf_fs = nullptr;
191 };
192
193 struct ctf_fs_msg_iter_data
194 {
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 }
200
201 /* Weak */
202 bt_self_message_iterator *self_msg_iter = nullptr;
203
204 bt2c::Logger logger;
205
206 /* Weak, belongs to ctf_fs_trace */
207 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
208
209 /* Owned by this */
210 struct ctf_msg_iter *msg_iter = nullptr;
211
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 */
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;
220
221 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
222 };
223
224 bt_component_class_initialize_method_status
225 ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
226 const bt_value *params, void *init_method_data);
227
228 void ctf_fs_finalize(bt_self_component_source *component);
229
230 bt_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);
234
235 bt_message_iterator_class_initialize_method_status
236 ctf_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);
239
240 void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
241
242 bt_message_iterator_class_next_method_status
243 ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
244 uint64_t capacity, uint64_t *count);
245
246 bt_message_iterator_class_seek_beginning_method_status
247 ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
248
249 /* Create and initialize a new, empty ctf_fs_component. */
250
251 ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
252
253 /*
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`.
260 *
261 * `self_comp` and `self_comp_class` are used for logging, only one of them
262 * should be set.
263 */
264
265 int 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,
268 bt_self_component *selfComp);
269
270 /* Free `ctf_fs` and everything it owns. */
271
272 void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
273
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.
280 * - The optional `trace-name` parameter is returned in `*trace_name` if
281 * present, else `*trace_name` is set to NULL.
282 *
283 * `self_comp` and `self_comp_class` are used for logging, only one of them
284 * should be set.
285 *
286 * Return true on success, false if any parameter didn't pass validation.
287 */
288
289 bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
290 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
291
292 /*
293 * Generate the port name to be used for a given data stream file group.
294 */
295
296 bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
297
298 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.041082 seconds and 4 git commands to generate.