Commit | Line | Data |
---|---|---|
e98a2d6e | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
e98a2d6e | 3 | * |
0235b0db | 4 | * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com> |
e98a2d6e PP |
5 | */ |
6 | ||
0235b0db MJ |
7 | #ifndef CTF_FS_DS_FILE_H |
8 | #define CTF_FS_DS_FILE_H | |
9 | ||
fe2e19c4 | 10 | #include <memory> |
4d199954 | 11 | #include <string> |
f3d74124 | 12 | #include <vector> |
fe2e19c4 | 13 | |
e98a2d6e | 14 | #include <glib.h> |
c802cacb SM |
15 | #include <stdio.h> |
16 | ||
3fadfbc0 | 17 | #include <babeltrace2/babeltrace.h> |
e98a2d6e | 18 | |
be215bcd | 19 | #include "cpp-common/bt2/trace-ir.hpp" |
873c329a | 20 | #include "cpp-common/bt2c/data-len.hpp" |
0f5c5d5c SM |
21 | #include "cpp-common/bt2c/logging.hpp" |
22 | ||
5656cea5 | 23 | #include "../common/src/msg-iter/msg-iter.hpp" |
c44dc433 | 24 | #include "file.hpp" |
b6c3dcb2 | 25 | |
4164020e SM |
26 | struct ctf_fs_ds_file_info |
27 | { | |
2cef6403 SM |
28 | using UP = std::unique_ptr<ctf_fs_ds_file_info>; |
29 | ||
4d199954 | 30 | std::string path; |
97ade20b | 31 | |
4164020e | 32 | /* Guaranteed to be set, as opposed to the index. */ |
afb0f12b | 33 | int64_t begin_ns = 0; |
97ade20b JG |
34 | }; |
35 | ||
4164020e SM |
36 | struct ctf_fs_ds_file |
37 | { | |
89f88383 SM |
38 | using UP = std::unique_ptr<ctf_fs_ds_file>; |
39 | ||
0f5c5d5c SM |
40 | explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) : |
41 | logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"} | |
42 | { | |
43 | } | |
98903a3e | 44 | |
3199f1ba SM |
45 | ctf_fs_ds_file(const ctf_fs_ds_file&) = delete; |
46 | ctf_fs_ds_file& operator=(const ctf_fs_ds_file&) = delete; | |
47 | ~ctf_fs_ds_file(); | |
48 | ||
0f5c5d5c | 49 | bt2c::Logger logger; |
4c65a157 | 50 | |
4164020e | 51 | /* Weak */ |
afb0f12b | 52 | struct ctf_fs_metadata *metadata = nullptr; |
5c563278 | 53 | |
c44dc433 | 54 | ctf_fs_file::UP file; |
97ade20b | 55 | |
265d4ba2 | 56 | bt2::Stream::Shared stream; |
97ade20b | 57 | |
afb0f12b | 58 | void *mmap_addr = nullptr; |
97ade20b | 59 | |
4164020e SM |
60 | /* |
61 | * Max length of chunk to mmap() when updating the current mapping. | |
62 | * This value must be page-aligned. | |
63 | */ | |
afb0f12b | 64 | size_t mmap_max_len = 0; |
97ade20b | 65 | |
4164020e | 66 | /* Length of the current mapping. Never exceeds the file's length. */ |
afb0f12b | 67 | size_t mmap_len = 0; |
97ade20b | 68 | |
4164020e | 69 | /* Offset in the file where the current mapping starts. */ |
afb0f12b | 70 | off_t mmap_offset_in_file = 0; |
97ade20b | 71 | |
4164020e SM |
72 | /* |
73 | * Offset, in the current mapping, of the address to return on the next | |
74 | * request. | |
75 | */ | |
afb0f12b | 76 | off_t request_offset_in_mapping = 0; |
b6c3dcb2 | 77 | }; |
e98a2d6e | 78 | |
873c329a SM |
79 | struct ctf_fs_ds_index_entry |
80 | { | |
c05e1405 SM |
81 | using UP = std::unique_ptr<ctf_fs_ds_index_entry>; |
82 | ||
873c329a SM |
83 | explicit ctf_fs_ds_index_entry(const bt2c::DataLen offsetParam, |
84 | const bt2c::DataLen packetSizeParam) noexcept : | |
85 | offset(offsetParam), | |
86 | packetSize(packetSizeParam) | |
87 | { | |
88 | } | |
89 | ||
90 | /* Weak, belongs to ctf_fs_ds_file_info. */ | |
91 | const char *path = nullptr; | |
92 | ||
93 | /* Position of the packet from the beginning of the file. */ | |
94 | bt2c::DataLen offset; | |
95 | ||
96 | /* Size of the packet. */ | |
97 | bt2c::DataLen packetSize; | |
98 | ||
99 | /* | |
100 | * Extracted from the packet context, relative to the respective fields' | |
101 | * mapped clock classes (in cycles). | |
102 | */ | |
103 | uint64_t timestamp_begin = 0, timestamp_end = 0; | |
104 | ||
105 | /* | |
106 | * Converted from the packet context, relative to the trace's EPOCH | |
107 | * (in ns since EPOCH). | |
108 | */ | |
109 | int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0; | |
110 | ||
111 | /* | |
112 | * Packet sequence number, or UINT64_MAX if not present in the index. | |
113 | */ | |
114 | uint64_t packet_seq_num = 0; | |
115 | }; | |
116 | ||
117 | struct ctf_fs_ds_index | |
118 | { | |
bfd852f0 | 119 | using UP = std::unique_ptr<ctf_fs_ds_index>; |
441fa755 | 120 | |
2fb7af12 | 121 | std::vector<ctf_fs_ds_index_entry::UP> entries; |
873c329a SM |
122 | }; |
123 | ||
124 | struct ctf_fs_ds_file_group | |
125 | { | |
235f9fd9 | 126 | using UP = std::unique_ptr<ctf_fs_ds_file_group>; |
fe2e19c4 | 127 | |
873c329a | 128 | /* |
873c329a SM |
129 | * This is an _ordered_ array of data stream file infos which |
130 | * belong to this group (a single stream instance). | |
131 | * | |
132 | * You can call ctf_fs_ds_file_create() with one of those paths | |
133 | * and the trace IR stream below. | |
134 | */ | |
f3d74124 | 135 | std::vector<ctf_fs_ds_file_info::UP> ds_file_infos; |
873c329a SM |
136 | |
137 | /* Owned by this */ | |
138 | struct ctf_stream_class *sc = nullptr; | |
139 | ||
be215bcd | 140 | bt2::Stream::Shared stream; |
873c329a SM |
141 | |
142 | /* Stream (instance) ID; -1ULL means none */ | |
143 | uint64_t stream_id = 0; | |
144 | ||
145 | /* Weak, belongs to component */ | |
146 | struct ctf_fs_trace *ctf_fs_trace = nullptr; | |
147 | ||
fe2f9cda | 148 | ctf_fs_ds_index::UP index; |
873c329a SM |
149 | }; |
150 | ||
89f88383 SM |
151 | ctf_fs_ds_file::UP ctf_fs_ds_file_create(ctf_fs_trace *ctf_fs_trace, bt2::Stream::Shared stream, |
152 | const char *path, const bt2c::Logger& logger); | |
e98a2d6e | 153 | |
441fa755 SM |
154 | ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file, |
155 | struct ctf_fs_ds_file_info *ds_file_info, | |
156 | struct ctf_msg_iter *msg_iter); | |
97ade20b | 157 | |
2fb7af12 | 158 | ctf_fs_ds_index::UP ctf_fs_ds_index_create(); |
7ed5243a | 159 | |
2cef6403 | 160 | ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns); |
873c329a | 161 | |
fe2e19c4 SM |
162 | ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace, |
163 | struct ctf_stream_class *sc, | |
164 | uint64_t stream_instance_id, | |
fe2f9cda | 165 | ctf_fs_ds_index::UP index); |
873c329a | 166 | |
f6e68e70 SM |
167 | /* |
168 | * Medium operations to iterate on a single ctf_fs_ds_file. | |
169 | * | |
170 | * The data pointer when using this must be a pointer to the ctf_fs_ds_file. | |
171 | */ | |
18a1979b | 172 | extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops; |
6de92955 | 173 | |
f6e68e70 SM |
174 | /* |
175 | * Medium operations to iterate on the packet of a ctf_fs_ds_group. | |
176 | * | |
177 | * The iteration is done based on the index of the group. | |
178 | * | |
179 | * The data pointer when using these medops must be a pointer to a ctf_fs_ds | |
180 | * group_medops_data structure. | |
181 | */ | |
182 | extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops; | |
183 | ||
3cf88182 SM |
184 | struct ctf_fs_ds_group_medops_data_deleter |
185 | { | |
186 | void operator()(struct ctf_fs_ds_group_medops_data *data) noexcept; | |
187 | }; | |
188 | ||
189 | using ctf_fs_ds_group_medops_data_up = | |
190 | std::unique_ptr<ctf_fs_ds_group_medops_data, ctf_fs_ds_group_medops_data_deleter>; | |
191 | ||
192 | enum ctf_msg_iter_medium_status | |
193 | ctf_fs_ds_group_medops_data_create(struct ctf_fs_ds_file_group *ds_file_group, | |
194 | bt_self_message_iterator *self_msg_iter, | |
195 | const bt2c::Logger& logger, ctf_fs_ds_group_medops_data_up& out); | |
f6e68e70 | 196 | |
f6e68e70 SM |
197 | void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data); |
198 | ||
94cf822e | 199 | #endif /* CTF_FS_DS_FILE_H */ |