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