ctf: add ClkClsConfig and use it
[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
c7e1be4b 13#include <glib.h>
c802cacb 14
c7e1be4b 15#include <babeltrace2/babeltrace.h>
c802cacb 16
49b956cc 17#include "cpp-common/bt2c/glib-up.hpp"
0f5c5d5c
SM
18#include "cpp-common/bt2c/logging.hpp"
19
087cd0f5 20#include "metadata.hpp"
1fa280c9 21#include "plugins/ctf/common/src/metadata/tsdl/decoder.hpp"
490db841 22
78bb6992 23extern bool ctf_fs_debug;
56a1cced 24
4164020e
SM
25struct ctf_fs_file
26{
0f5c5d5c
SM
27 explicit ctf_fs_file(const bt2c::Logger& parentLogger) :
28 logger {parentLogger, "PLUGIN/SRC.CTF.FS/FILE"}
29 {
30 }
98903a3e 31
0f5c5d5c 32 bt2c::Logger logger;
4c65a157 33
4164020e 34 /* Owned by this */
afb0f12b 35 GString *path = nullptr;
1a9f7075 36
4164020e 37 /* Owned by this */
afb0f12b 38 FILE *fp = nullptr;
1a9f7075 39
afb0f12b 40 off_t size = 0;
56a1cced
JG
41};
42
4164020e
SM
43struct ctf_fs_metadata
44{
45 /* Owned by this */
1fa280c9 46 ctf_metadata_decoder_up decoder;
44c440bc 47
4164020e 48 /* Owned by this */
afb0f12b 49 bt_trace_class *trace_class = nullptr;
1a9f7075 50
4164020e 51 /* Weak (owned by `decoder` above) */
afb0f12b 52 struct ctf_trace_class *tc = nullptr;
44c440bc 53
4164020e 54 /* Owned by this */
afb0f12b 55 char *text = nullptr;
1a9f7075 56
afb0f12b 57 int bo = 0;
56a1cced
JG
58};
59
f340a3e8
SM
60struct ctf_fs_component_deleter
61{
62 void operator()(struct ctf_fs_component *);
63};
64
4164020e
SM
65struct ctf_fs_component
66{
f340a3e8
SM
67 using UP = std::unique_ptr<ctf_fs_component, ctf_fs_component_deleter>;
68
0f5c5d5c
SM
69 explicit ctf_fs_component(const bt2c::Logger& parentLogger) :
70 logger {parentLogger, "PLUGIN/SRC.CTF.FS/COMP"}
71 {
72 }
73
74 bt2c::Logger logger;
98903a3e 75
4164020e 76 /* Array of struct ctf_fs_port_data *, owned by this */
afb0f12b 77 GPtrArray *port_data = nullptr;
1a9f7075 78
4164020e 79 /* Owned by this */
afb0f12b 80 struct ctf_fs_trace *trace = nullptr;
1a9f7075 81
c942e7a2 82 ctf::src::ClkClsCfg clkClsCfg;
1a9f7075
PP
83};
84
4164020e
SM
85struct ctf_fs_trace
86{
0f5c5d5c
SM
87 explicit ctf_fs_trace(const bt2c::Logger& parentLogger) :
88 logger {parentLogger, "PLUGIN/SRC.CTF.FS/TRACE"}
89 {
90 }
98903a3e 91
0f5c5d5c 92 bt2c::Logger logger;
4c65a157 93
4164020e 94 /* Owned by this */
afb0f12b 95 struct ctf_fs_metadata *metadata = nullptr;
1a9f7075 96
4164020e 97 /* Owned by this */
afb0f12b 98 bt_trace *trace = nullptr;
862ca4ed 99
4164020e 100 /* Array of struct ctf_fs_ds_file_group *, owned by this */
afb0f12b 101 GPtrArray *ds_file_groups = nullptr;
94cf822e 102
4164020e 103 /* Owned by this */
afb0f12b 104 GString *path = nullptr;
1a9f7075 105
4164020e 106 /* Next automatic stream ID when not provided by packet header */
afb0f12b 107 uint64_t next_stream_id = 0;
1a9f7075
PP
108};
109
4164020e
SM
110struct ctf_fs_ds_index_entry
111{
112 /* Weak, belongs to ctf_fs_ds_file_info. */
afb0f12b 113 const char *path = nullptr;
4164020e
SM
114
115 /* Position, in bytes, of the packet from the beginning of the file. */
afb0f12b 116 uint64_t offset = 0;
4164020e
SM
117
118 /* Size of the packet, in bytes. */
afb0f12b 119 uint64_t packet_size = 0;
4164020e
SM
120
121 /*
122 * Extracted from the packet context, relative to the respective fields'
123 * mapped clock classes (in cycles).
124 */
afb0f12b 125 uint64_t timestamp_begin = 0, timestamp_end = 0;
4164020e
SM
126
127 /*
128 * Converted from the packet context, relative to the trace's EPOCH
129 * (in ns since EPOCH).
130 */
afb0f12b 131 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
4164020e
SM
132
133 /*
134 * Packet sequence number, or UINT64_MAX if not present in the index.
135 */
afb0f12b 136 uint64_t packet_seq_num = 0;
7ed5243a
FD
137};
138
4164020e
SM
139struct ctf_fs_ds_index
140{
141 /* Array of pointer to struct ctf_fs_ds_index_entry. */
afb0f12b 142 GPtrArray *entries = nullptr;
7ed5243a
FD
143};
144
4164020e
SM
145struct 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 */
afb0f12b 156 GPtrArray *ds_file_infos = nullptr;
4164020e
SM
157
158 /* Owned by this */
afb0f12b 159 struct ctf_stream_class *sc = nullptr;
4164020e
SM
160
161 /* Owned by this */
afb0f12b 162 bt_stream *stream = nullptr;
4164020e
SM
163
164 /* Stream (instance) ID; -1ULL means none */
afb0f12b 165 uint64_t stream_id = 0;
4164020e
SM
166
167 /* Weak, belongs to component */
afb0f12b 168 struct ctf_fs_trace *ctf_fs_trace = nullptr;
4164020e
SM
169
170 /*
171 * Owned by this.
172 */
afb0f12b 173 struct ctf_fs_ds_index *index = nullptr;
ea0b4b9e
JG
174};
175
4164020e
SM
176struct ctf_fs_port_data
177{
178 /* Weak, belongs to ctf_fs_trace */
afb0f12b 179 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
5c563278 180
4164020e 181 /* Weak */
afb0f12b 182 struct ctf_fs_component *ctf_fs = nullptr;
94cf822e
PP
183};
184
4164020e
SM
185struct ctf_fs_msg_iter_data
186{
0f5c5d5c
SM
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 }
4c65a157 192
4164020e 193 /* Weak */
afb0f12b 194 bt_self_message_iterator *self_msg_iter = nullptr;
5c563278 195
0f5c5d5c
SM
196 bt2c::Logger logger;
197
4164020e 198 /* Weak, belongs to ctf_fs_trace */
afb0f12b 199 struct ctf_fs_ds_file_group *ds_file_group = nullptr;
94cf822e 200
4164020e 201 /* Owned by this */
afb0f12b 202 struct ctf_msg_iter *msg_iter = nullptr;
cbca1c06 203
4164020e
SM
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 */
afb0f12b
SM
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;
f6e68e70 212
afb0f12b 213 struct ctf_fs_ds_group_medops_data *msg_iter_medops_data = nullptr;
94cf822e
PP
214};
215
4164020e
SM
216bt_component_class_initialize_method_status
217ctf_fs_init(bt_self_component_source *source, bt_self_component_source_configuration *config,
218 const bt_value *params, void *init_method_data);
490db841 219
b19ff26f 220void ctf_fs_finalize(bt_self_component_source *component);
d3e4dcd8 221
4164020e
SM
222bt_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);
55314f2a 226
4164020e
SM
227bt_message_iterator_class_initialize_method_status
228ctf_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);
d94d92ac 231
d6e69534 232void ctf_fs_iterator_finalize(bt_self_message_iterator *it);
d3eb6e8f 233
4164020e
SM
234bt_message_iterator_class_next_method_status
235ctf_fs_iterator_next(bt_self_message_iterator *iterator, bt_message_array_const msgs,
236 uint64_t capacity, uint64_t *count);
d3eb6e8f 237
4164020e
SM
238bt_message_iterator_class_seek_beginning_method_status
239ctf_fs_iterator_seek_beginning(bt_self_message_iterator *message_iterator);
6a9bb5e9 240
f280892e
SM
241/* Create and initialize a new, empty ctf_fs_component. */
242
f340a3e8 243ctf_fs_component::UP ctf_fs_component_create(const bt2c::Logger& parentLogger);
f280892e
SM
244
245/*
a0cd55ad
SM
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`.
d23b766e
SM
252 *
253 * `self_comp` and `self_comp_class` are used for logging, only one of them
254 * should be set.
f280892e
SM
255 */
256
4164020e
SM
257int 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,
0f5c5d5c 260 bt_self_component *selfComp);
f280892e
SM
261
262/* Free `ctf_fs` and everything it owns. */
263
f280892e
SM
264void ctf_fs_destroy(struct ctf_fs_component *ctf_fs);
265
d907165c
SM
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.
005d49d6
SM
272 * - The optional `trace-name` parameter is returned in `*trace_name` if
273 * present, else `*trace_name` is set to NULL.
d907165c 274 *
d23b766e
SM
275 * `self_comp` and `self_comp_class` are used for logging, only one of them
276 * should be set.
277 *
d907165c
SM
278 * Return true on success, false if any parameter didn't pass validation.
279 */
f280892e 280
4164020e 281bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
0f5c5d5c 282 const bt_value **trace_name, struct ctf_fs_component *ctf_fs);
f280892e 283
a38d7650
SM
284/*
285 * Generate the port name to be used for a given data stream file group.
a38d7650
SM
286 */
287
49b956cc 288bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
a38d7650 289
541b0a11 290#endif /* BABELTRACE_PLUGIN_CTF_FS_H */
This page took 0.110006 seconds and 4 git commands to generate.