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