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
15 #include "common/macros.h"
16 #include <babeltrace2/babeltrace.h>
19 #include "../common/src/msg-iter/msg-iter.hpp"
20 #include "cpp-common/data-len.hpp"
21 #include "lttng-index.hpp"
22 #include "cpp-common/log-cfg.hpp"
24 struct ctf_fs_component;
27 struct ctf_fs_ds_group_medops_data;
29 struct ctf_fs_ds_file_info
31 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
35 /* Guaranteed to be set, as opposed to the index. */
39 struct ctf_fs_metadata;
43 explicit ctf_fs_ds_file(const bt2_common::LogCfg& logCfgParam) noexcept : logCfg {logCfgParam}
47 const bt2_common::LogCfg logCfg;
50 struct ctf_fs_metadata *metadata = nullptr;
53 struct ctf_fs_file *file = nullptr;
56 bt_stream *stream = nullptr;
58 void *mmap_addr = nullptr;
61 * Max length of chunk to mmap() when updating the current mapping.
62 * This value must be page-aligned.
64 size_t mmap_max_len = 0;
66 /* Length of the current mapping. Never exceeds the file's length. */
69 /* Offset in the file where the current mapping starts. */
70 off_t mmap_offset_in_file = 0;
73 * Offset, in the current mapping, of the address to return on the next
76 off_t request_offset_in_mapping = 0;
79 struct ctf_fs_ds_index_entry
81 ctf_fs_ds_index_entry(bt2_common::DataLen offsetParam, bt2_common::DataLen packetSizeParam) :
82 offset(offsetParam), packetSize(packetSizeParam)
86 /* Weak, belongs to ctf_fs_ds_file_info. */
87 const char *path = nullptr;
89 /* Position of the packet from the beginning of the file. */
90 const bt2_common::DataLen offset;
92 /* Size of the packet. */
93 const bt2_common::DataLen packetSize;
96 * Extracted from the packet context, relative to the respective fields'
97 * mapped clock classes (in cycles).
99 uint64_t timestamp_begin = 0, timestamp_end = 0;
102 * Converted from the packet context, relative to the trace's EPOCH
103 * (in ns since EPOCH).
105 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
108 * Packet sequence number, or UINT64_MAX if not present in the index.
110 uint64_t packet_seq_num = 0;
113 struct ctf_fs_ds_index_deleter
115 void operator()(struct ctf_fs_ds_index *index);
118 struct ctf_fs_ds_index
120 using UP = std::unique_ptr<ctf_fs_ds_index, ctf_fs_ds_index_deleter>;
122 /* Array of pointer to struct ctf_fs_ds_index_entry. */
123 GPtrArray *entries = nullptr;
126 struct ctf_fs_ds_file_group_deleter
128 void operator()(struct ctf_fs_ds_file_group *group);
131 struct ctf_fs_ds_file_group
133 using UP = std::unique_ptr<ctf_fs_ds_file_group, ctf_fs_ds_file_group_deleter>;
136 * This is an _ordered_ array of data stream file infos which
137 * belong to this group (a single stream instance).
139 * You can call ctf_fs_ds_file_create() with one of those paths
140 * and the trace IR stream below.
142 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
145 struct ctf_stream_class *sc = nullptr;
148 bt_stream *stream = nullptr;
150 /* Stream (instance) ID; -1ULL means none */
151 uint64_t stream_id = 0;
153 /* Weak, belongs to component */
154 struct ctf_fs_trace *ctf_fs_trace = nullptr;
159 struct ctf_fs_ds_index *index = nullptr;
163 struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
164 const char *path, const bt2_common::LogCfg& logCfg);
167 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream);
170 ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
171 struct ctf_fs_ds_file_info *ds_file_info,
172 struct ctf_msg_iter *msg_iter);
175 ctf_fs_ds_index::UP ctf_fs_ds_index_create(const bt2_common::LogCfg& logCfg);
178 void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index);
180 BT_HIDDEN ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
182 BT_HIDDEN ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
183 struct ctf_stream_class *sc,
184 uint64_t stream_instance_id,
185 struct ctf_fs_ds_index *index);
188 * Medium operations to iterate on a single ctf_fs_ds_file.
190 * The data pointer when using this must be a pointer to the ctf_fs_ds_file.
192 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
195 * Medium operations to iterate on the packet of a ctf_fs_ds_group.
197 * The iteration is done based on the index of the group.
199 * The data pointer when using these medops must be a pointer to a ctf_fs_ds
200 * group_medops_data structure.
203 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops;
206 enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
207 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
208 const bt2_common::LogCfg& logCfg, struct ctf_fs_ds_group_medops_data **out);
211 void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
214 void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data);
216 #endif /* CTF_FS_DS_FILE_H */