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