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