a0153a9b99509f4637b3b3ebce53dd1fab0ad3de
[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
62 {
63 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
64 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
65 {
66 }
67
68 bt2c::Logger logger;
69
70 /* Owned by this */
71 struct ctf_fs_metadata *metadata = nullptr;
72
73 /* Owned by this */
74 bt_trace *trace = nullptr;
75
76 /* Array of struct ctf_fs_ds_file_group *, owned by this */
77 GPtrArray *ds_file_groups = nullptr;
78
79 /* Owned by this */
80 GString *path = nullptr;
81
82 /* Next automatic stream ID when not provided by packet header */
83 uint64_t next_stream_id = 0;
84 };
85
86 struct 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
95 struct ctf_fs_component_deleter
96 {
97 void operator()(ctf_fs_component *);
98 };
99
100 struct 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
120 struct ctf_fs_ds_index_entry
121 {
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
129 /* Weak, belongs to ctf_fs_ds_file_info. */
130 const char *path = nullptr;
131
132 /* Position of the packet from the beginning of the file. */
133 bt2c::DataLen offset;
134
135 /* Size of the packet. */
136 bt2c::DataLen packetSize;
137
138 /*
139 * Extracted from the packet context, relative to the respective fields'
140 * mapped clock classes (in cycles).
141 */
142 uint64_t timestamp_begin = 0, timestamp_end = 0;
143
144 /*
145 * Converted from the packet context, relative to the trace's EPOCH
146 * (in ns since EPOCH).
147 */
148 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
149
150 /*
151 * Packet sequence number, or UINT64_MAX if not present in the index.
152 */
153 uint64_t packet_seq_num = 0;
154 };
155
156 struct ctf_fs_ds_index
157 {
158 /* Array of pointer to struct ctf_fs_ds_index_entry. */
159 GPtrArray *entries = nullptr;
160 };
161
162 struct 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 */
173 GPtrArray *ds_file_infos = nullptr;
174
175 /* Owned by this */
176 struct ctf_stream_class *sc = nullptr;
177
178 /* Owned by this */
179 bt_stream *stream = nullptr;
180
181 /* Stream (instance) ID; -1ULL means none */
182 uint64_t stream_id = 0;
183
184 /* Weak, belongs to component */
185 struct ctf_fs_trace *ctf_fs_trace = nullptr;
186
187 /*
188 * Owned by this.
189 */
190 struct ctf_fs_ds_index *index = 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.035348 seconds and 3 git commands to generate.