Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / ctf / fs-src / fs.h
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>
94cf822e 16#include "data-stream-file.h"
97ade20b 17#include "metadata.h"
44c440bc 18#include "../common/metadata/decoder.h"
490db841 19
78bb6992
MD
20BT_HIDDEN
21extern bool ctf_fs_debug;
56a1cced
JG
22
23struct ctf_fs_file {
98903a3e
PP
24 bt_logging_level log_level;
25
4c65a157
PP
26 /* Weak */
27 bt_self_component *self_comp;
28
1a9f7075 29 /* Owned by this */
56a1cced 30 GString *path;
1a9f7075
PP
31
32 /* Owned by this */
56a1cced 33 FILE *fp;
1a9f7075 34
56a1cced
JG
35 off_t size;
36};
37
38struct ctf_fs_metadata {
44c440bc
PP
39 /* Owned by this */
40 struct ctf_metadata_decoder *decoder;
41
1a9f7075 42 /* Owned by this */
b19ff26f 43 bt_trace_class *trace_class;
1a9f7075 44
44c440bc
PP
45 /* Weak (owned by `decoder` above) */
46 struct ctf_trace_class *tc;
47
1a9f7075
PP
48 /* Owned by this */
49 char *text;
50
56a1cced 51 int bo;
56a1cced
JG
52};
53
ea0b4b9e 54struct ctf_fs_component {
98903a3e
PP
55 bt_logging_level log_level;
56
1a9f7075
PP
57 /* Array of struct ctf_fs_port_data *, owned by this */
58 GPtrArray *port_data;
59
a0cd55ad
SM
60 /* Owned by this */
61 struct ctf_fs_trace *trace;
1a9f7075 62
a2a54545 63 struct ctf_fs_metadata_config metadata_config;
1a9f7075
PP
64};
65
66struct ctf_fs_trace {
98903a3e
PP
67 bt_logging_level log_level;
68
b7d2695a
SM
69 /*
70 * Weak. These are mostly used to generate log messages or to append
aad00638 71 * error causes. They are mutually exclusive, only one of them must be
b7d2695a
SM
72 * set.
73 */
4c65a157 74 bt_self_component *self_comp;
b7d2695a 75 bt_self_component_class *self_comp_class;
4c65a157 76
1a9f7075 77 /* Owned by this */
5b29e799 78 struct ctf_fs_metadata *metadata;
1a9f7075 79
862ca4ed 80 /* Owned by this */
b19ff26f 81 bt_trace *trace;
862ca4ed 82
94cf822e
PP
83 /* Array of struct ctf_fs_ds_file_group *, owned by this */
84 GPtrArray *ds_file_groups;
85
1a9f7075
PP
86 /* Owned by this */
87 GString *path;
88
3dca2276
PP
89 /* Next automatic stream ID when not provided by packet header */
90 uint64_t next_stream_id;
1a9f7075
PP
91};
92
7ed5243a 93struct ctf_fs_ds_index_entry {
bf012bde
FD
94 /* Weak, belongs to ctf_fs_ds_file_info. */
95 const char *path;
96
7ed5243a
FD
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;
6834784d
SM
114
115 /*
116 * Packet sequence number, or UINT64_MAX if not present in the index.
117 */
118 uint64_t packet_seq_num;
7ed5243a
FD
119};
120
121struct ctf_fs_ds_index {
ce75de14 122 /* Array of pointer to struct ctf_fs_ds_index_entry. */
7ed5243a
FD
123 GPtrArray *entries;
124};
125
94cf822e
PP
126struct 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
56e18c4c 134 * and the trace IR stream below.
94cf822e
PP
135 */
136 GPtrArray *ds_file_infos;
137
547eacf1 138 /* Owned by this */
60363f2f 139 struct ctf_stream_class *sc;
547eacf1 140
1a9f7075 141 /* Owned by this */
b19ff26f 142 bt_stream *stream;
1a9f7075 143
547eacf1
PP
144 /* Stream (instance) ID; -1ULL means none */
145 uint64_t stream_id;
146
94cf822e 147 /* Weak, belongs to component */
1a9f7075 148 struct ctf_fs_trace *ctf_fs_trace;
7ed5243a
FD
149
150 /*
29a8227a 151 * Owned by this.
7ed5243a
FD
152 */
153 struct ctf_fs_ds_index *index;
ea0b4b9e
JG
154};
155
94cf822e
PP
156struct ctf_fs_port_data {
157 /* Weak, belongs to ctf_fs_trace */
158 struct ctf_fs_ds_file_group *ds_file_group;
5c563278
PP
159
160 /* Weak */
161 struct ctf_fs_component *ctf_fs;
94cf822e
PP
162};
163
d6e69534 164struct ctf_fs_msg_iter_data {
98903a3e
PP
165 bt_logging_level log_level;
166
4c65a157
PP
167 /* Weak */
168 bt_self_component *self_comp;
169
5c563278 170 /* Weak */
f30762e5 171 bt_self_message_iterator *self_msg_iter;
5c563278 172
94cf822e
PP
173 /* Weak, belongs to ctf_fs_trace */
174 struct ctf_fs_ds_file_group *ds_file_group;
175
6de92955 176 /* Owned by this */
18a1979b 177 struct ctf_msg_iter *msg_iter;
cbca1c06
SM
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 */
a3f0c7db 184 bt_message_iterator_class_next_method_status next_saved_status;
cbca1c06 185 const struct bt_error *next_saved_error;
f6e68e70
SM
186
187 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data;
94cf822e
PP
188};
189
f3bc2010 190BT_HIDDEN
21a9f056 191bt_component_class_initialize_method_status ctf_fs_init(
b19ff26f 192 bt_self_component_source *source,
59225a3e 193 bt_self_component_source_configuration *config,
b19ff26f 194 const bt_value *params, void *init_method_data);
490db841 195
d3e4dcd8 196BT_HIDDEN
b19ff26f 197void ctf_fs_finalize(bt_self_component_source *component);
d3e4dcd8 198
55314f2a 199BT_HIDDEN
d24d5663 200bt_component_class_query_method_status ctf_fs_query(
b19ff26f 201 bt_self_component_class_source *comp_class,
3c729b9a 202 bt_private_query_executor *priv_query_exec,
b19ff26f 203 const char *object, const bt_value *params,
7c14d641 204 void *method_data, const bt_value **result);
55314f2a 205
97ade20b 206BT_HIDDEN
a3f0c7db 207bt_message_iterator_class_initialize_method_status ctf_fs_iterator_init(
d6e69534 208 bt_self_message_iterator *self_msg_iter,
8d8b141d 209 bt_self_message_iterator_configuration *config,
b19ff26f 210 bt_self_component_port_output *self_port);
d94d92ac 211
97ade20b 212BT_HIDDEN
d6e69534 213void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
d3eb6e8f 214
97ade20b 215BT_HIDDEN
a3f0c7db 216bt_message_iterator_class_next_method_status ctf_fs_iterator_next(
d6e69534
PP
217 bt_self_message_iterator *iterator,
218 bt_message_array_const msgs, uint64_t capacity,
d4393e08 219 uint64_t *count);
d3eb6e8f 220
6a9bb5e9 221BT_HIDDEN
a3f0c7db 222bt_message_iterator_class_seek_beginning_method_status ctf_fs_iterator_seek_beginning(
6a9bb5e9
PP
223 bt_self_message_iterator *message_iterator);
224
f280892e
SM
225/* Create and initialize a new, empty ctf_fs_component. */
226
227BT_HIDDEN
4c65a157
PP
228struct ctf_fs_component *ctf_fs_component_create(bt_logging_level log_level,
229 bt_self_component *self_comp);
f280892e
SM
230
231/*
a0cd55ad
SM
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`.
d23b766e
SM
238 *
239 * `self_comp` and `self_comp_class` are used for logging, only one of them
240 * should be set.
f280892e
SM
241 */
242
243BT_HIDDEN
a0cd55ad 244int ctf_fs_component_create_ctf_fs_trace(
f280892e 245 struct ctf_fs_component *ctf_fs,
d23b766e 246 const bt_value *paths_value,
005d49d6 247 const bt_value *trace_name_value,
d23b766e
SM
248 bt_self_component *self_comp,
249 bt_self_component_class *self_comp_class);
f280892e
SM
250
251/* Free `ctf_fs` and everything it owns. */
252
253BT_HIDDEN
254void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
255
d907165c
SM
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.
005d49d6
SM
262 * - The optional `trace-name` parameter is returned in `*trace_name` if
263 * present, else `*trace_name` is set to NULL.
d907165c 264 *
d23b766e
SM
265 * `self_comp` and `self_comp_class` are used for logging, only one of them
266 * should be set.
267 *
d907165c
SM
268 * Return true on success, false if any parameter didn't pass validation.
269 */
f280892e
SM
270
271BT_HIDDEN
d907165c 272bool read_src_fs_parameters(const bt_value *params,
005d49d6
SM
273 const bt_value **paths,
274 const bt_value **trace_name,
275 struct ctf_fs_component *ctf_fs,
d23b766e
SM
276 bt_self_component *self_comp,
277 bt_self_component_class *self_comp_class);
f280892e 278
a38d7650
SM
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
285BT_HIDDEN
286gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
287
541b0a11 288#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.084031 seconds and 4 git commands to generate.