2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com>
7 #ifndef CTF_FS_DS_FILE_H
8 #define CTF_FS_DS_FILE_H
17 #include <babeltrace2/babeltrace.h>
19 #include "cpp-common/bt2/trace-ir.hpp"
20 #include "cpp-common/bt2c/data-len.hpp"
21 #include "cpp-common/bt2c/logging.hpp"
23 #include "../common/src/msg-iter/msg-iter.hpp"
25 struct ctf_fs_ds_file_info
27 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
31 /* Guaranteed to be set, as opposed to the index. */
37 explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) :
38 logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"}
45 struct ctf_fs_metadata *metadata = nullptr;
48 struct ctf_fs_file *file = nullptr;
50 bt2::Stream::Shared stream;
52 void *mmap_addr = nullptr;
55 * Max length of chunk to mmap() when updating the current mapping.
56 * This value must be page-aligned.
58 size_t mmap_max_len = 0;
60 /* Length of the current mapping. Never exceeds the file's length. */
63 /* Offset in the file where the current mapping starts. */
64 off_t mmap_offset_in_file = 0;
67 * Offset, in the current mapping, of the address to return on the next
70 off_t request_offset_in_mapping = 0;
73 struct ctf_fs_ds_index_entry
75 using UP = std::unique_ptr<ctf_fs_ds_index_entry>;
77 explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam,
78 const bt2c::DataLen packetSizeParam) noexcept :
80 packetSize(packetSizeParam)
84 /* Weak, belongs to ctf_fs_ds_file_info. */
85 const char *path = nullptr;
87 /* Position of the packet from the beginning of the file. */
90 /* Size of the packet. */
91 bt2c::DataLen packetSize;
94 * Extracted from the packet context, relative to the respective fields'
95 * mapped clock classes (in cycles).
97 uint64_t timestamp_begin = 0, timestamp_end = 0;
100 * Converted from the packet context, relative to the trace's EPOCH
101 * (in ns since EPOCH).
103 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
106 * Packet sequence number, or UINT64_MAX if not present in the index.
108 uint64_t packet_seq_num = 0;
111 struct ctf_fs_ds_index
113 using UP = std::unique_ptr<ctf_fs_ds_index>;
115 std::vector<ctf_fs_ds_index_entry::UP> entries;
118 struct ctf_fs_ds_file_group
120 using UP = std::unique_ptr<ctf_fs_ds_file_group>;
123 * This is an _ordered_ array of data stream file infos which
124 * belong to this group (a single stream instance).
126 * You can call ctf_fs_ds_file_create() with one of those paths
127 * and the trace IR stream below.
129 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
132 struct ctf_stream_class *sc = nullptr;
134 bt2::Stream::Shared stream;
136 /* Stream (instance) ID; -1ULL means none */
137 uint64_t stream_id = 0;
139 /* Weak, belongs to component */
140 struct ctf_fs_trace *ctf_fs_trace = nullptr;
142 ctf_fs_ds_index::UP index;
145 struct ctf_fs_ds_file *ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream,
146 const char *path, const bt2c::Logger& logger);
148 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream);
150 ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
151 struct ctf_fs_ds_file_info *ds_file_info,
152 struct ctf_msg_iter *msg_iter);
154 ctf_fs_ds_index::UP ctf_fs_ds_index_create();
156 ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
158 ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
159 struct ctf_stream_class *sc,
160 uint64_t stream_instance_id,
161 ctf_fs_ds_index::UP index);
164 * Medium operations to iterate on a single ctf_fs_ds_file.
166 * The data pointer when using this must be a pointer to the ctf_fs_ds_file.
168 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
171 * Medium operations to iterate on the packet of a ctf_fs_ds_group.
173 * The iteration is done based on the index of the group.
175 * The data pointer when using these medops must be a pointer to a ctf_fs_ds
176 * group_medops_data structure.
178 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops;
180 enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
181 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
182 const bt2c::Logger& logger, struct ctf_fs_ds_group_medops_data **out);
184 void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
186 void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data);
188 #endif /* CTF_FS_DS_FILE_H */