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