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