fed80c61585f73c18d801fa8ff2222416692151b
[babeltrace.git] / src / plugins / ctf / fs-src / data-stream-file.hpp
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2016 Philippe Proulx <pproulx@efficios.com>
5 */
6
7 #ifndef CTF_FS_DS_FILE_H
8 #define CTF_FS_DS_FILE_H
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include <glib.h>
15 #include <stdio.h>
16
17 #include <babeltrace2/babeltrace.h>
18
19 #include "cpp-common/bt2/trace-ir.hpp"
20 #include "cpp-common/bt2c/data-len.hpp"
21 #include "cpp-common/bt2c/logging.hpp"
22
23 #include "../common/src/msg-iter/msg-iter.hpp"
24
25 struct ctf_fs_ds_file_info
26 {
27 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
28
29 std::string path;
30
31 /* Guaranteed to be set, as opposed to the index. */
32 int64_t begin_ns = 0;
33 };
34
35 struct ctf_fs_ds_file
36 {
37 explicit ctf_fs_ds_file(const bt2c::Logger& parentLogger) :
38 logger {parentLogger, "PLUGIN/SRC.CTF.FS/DS"}
39 {
40 }
41
42 bt2c::Logger logger;
43
44 /* Weak */
45 struct ctf_fs_metadata *metadata = nullptr;
46
47 /* Owned by this */
48 struct ctf_fs_file *file = nullptr;
49
50 /* Owned by this */
51 bt_stream *stream = nullptr;
52
53 void *mmap_addr = nullptr;
54
55 /*
56 * Max length of chunk to mmap() when updating the current mapping.
57 * This value must be page-aligned.
58 */
59 size_t mmap_max_len = 0;
60
61 /* Length of the current mapping. Never exceeds the file's length. */
62 size_t mmap_len = 0;
63
64 /* Offset in the file where the current mapping starts. */
65 off_t mmap_offset_in_file = 0;
66
67 /*
68 * Offset, in the current mapping, of the address to return on the next
69 * request.
70 */
71 off_t request_offset_in_mapping = 0;
72 };
73
74 struct ctf_fs_ds_index_entry
75 {
76 using UP = std::unique_ptr<ctf_fs_ds_index_entry>;
77
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 {
114 using UP = std::unique_ptr<ctf_fs_ds_index>;
115
116 std::vector<ctf_fs_ds_index_entry::UP> entries;
117 };
118
119 struct ctf_fs_ds_file_group
120 {
121 using UP = std::unique_ptr<ctf_fs_ds_file_group>;
122
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 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
131
132 /* Owned by this */
133 struct ctf_stream_class *sc = nullptr;
134
135 bt2::Stream::Shared stream;
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
143 ctf_fs_ds_index::UP index;
144 };
145
146 struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
147 const char *path, const bt2c::Logger& logger);
148
149 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *stream);
150
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);
154
155 ctf_fs_ds_index::UP ctf_fs_ds_index_create();
156
157 ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
158
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,
162 ctf_fs_ds_index::UP index);
163
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 */
169 extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
170
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
181 enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
182 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
183 const bt2c::Logger& logger, struct ctf_fs_ds_group_medops_data **out);
184
185 void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
186
187 void ctf_fs_ds_group_medops_data_destroy(struct ctf_fs_ds_group_medops_data *data);
188
189 #endif /* CTF_FS_DS_FILE_H */
This page took 0.033708 seconds and 3 git commands to generate.