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