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