src.ctf.fs: make ds_file_group_insert_ds_file_info_sorted a method of ctf_fs_ds_file_...
[deliverable/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
e98a2d6e 10#include <stdio.h>
94cf822e 11#include <stdbool.h>
e98a2d6e 12#include <glib.h>
f0ab0592 13#include <memory>
473546f5 14#include <string>
91d81473 15#include "common/macros.h"
3fadfbc0 16#include <babeltrace2/babeltrace.h>
49befcfd 17#include <vector>
e98a2d6e 18
364f5320 19#include "../common/src/msg-iter/msg-iter.hpp"
0b067334 20#include "cpp-common/data-len.hpp"
087cd0f5 21#include "lttng-index.hpp"
27a14e13 22#include "cpp-common/log-cfg.hpp"
17d8205a 23#include "cpp-common/bt2/trace-ir.hpp"
2d54e7ff 24#include "file.hpp"
b6c3dcb2
JG
25
26struct ctf_fs_component;
27struct ctf_fs_file;
1a9f7075 28struct ctf_fs_trace;
f6e68e70 29struct ctf_fs_ds_group_medops_data;
b6c3dcb2 30
4164020e
SM
31struct ctf_fs_ds_file_info
32{
f2b5ec1f
SM
33 using UP = std::unique_ptr<ctf_fs_ds_file_info>;
34
473546f5 35 std::string path;
97ade20b 36
4164020e 37 /* Guaranteed to be set, as opposed to the index. */
6269f212 38 int64_t begin_ns = 0;
97ade20b
JG
39};
40
44c440bc
PP
41struct ctf_fs_metadata;
42
4164020e
SM
43struct ctf_fs_ds_file
44{
6d0b3c49
SM
45 using UP = std::unique_ptr<ctf_fs_ds_file>;
46
27a14e13
SM
47 explicit ctf_fs_ds_file(const bt2_common::LogCfg& logCfgParam) noexcept : logCfg {logCfgParam}
48 {
49 }
98903a3e 50
42871aa4
SM
51 ~ctf_fs_ds_file();
52
27a14e13 53 const bt2_common::LogCfg logCfg;
4c65a157 54
4164020e 55 /* Weak */
6269f212 56 struct ctf_fs_metadata *metadata = nullptr;
5c563278 57
2d54e7ff 58 ctf_fs_file::UP file;
97ade20b 59
4164020e 60 /* Owned by this */
22c7ae6c 61 nonstd::optional<bt2::Stream::Shared> stream;
97ade20b 62
6269f212 63 void *mmap_addr = nullptr;
97ade20b 64
4164020e
SM
65 /*
66 * Max length of chunk to mmap() when updating the current mapping.
67 * This value must be page-aligned.
68 */
6269f212 69 size_t mmap_max_len = 0;
97ade20b 70
4164020e 71 /* Length of the current mapping. Never exceeds the file's length. */
6269f212 72 size_t mmap_len = 0;
97ade20b 73
4164020e 74 /* Offset in the file where the current mapping starts. */
6269f212 75 off_t mmap_offset_in_file = 0;
97ade20b 76
4164020e
SM
77 /*
78 * Offset, in the current mapping, of the address to return on the next
79 * request.
80 */
6269f212 81 off_t request_offset_in_mapping = 0;
b6c3dcb2 82};
e98a2d6e 83
0b067334
SM
84struct ctf_fs_ds_index_entry
85{
86 ctf_fs_ds_index_entry(bt2_common::DataLen offsetParam, bt2_common::DataLen packetSizeParam) :
87 offset(offsetParam), packetSize(packetSizeParam)
88 {
89 }
90
91 /* Weak, belongs to ctf_fs_ds_file_info. */
92 const char *path = nullptr;
93
94 /* Position of the packet from the beginning of the file. */
3505f709 95 bt2_common::DataLen offset;
0b067334
SM
96
97 /* Size of the packet. */
3505f709 98 bt2_common::DataLen packetSize;
0b067334
SM
99
100 /*
101 * Extracted from the packet context, relative to the respective fields'
102 * mapped clock classes (in cycles).
103 */
104 uint64_t timestamp_begin = 0, timestamp_end = 0;
105
106 /*
107 * Converted from the packet context, relative to the trace's EPOCH
108 * (in ns since EPOCH).
109 */
110 int64_t timestamp_begin_ns = 0, timestamp_end_ns = 0;
111
112 /*
113 * Packet sequence number, or UINT64_MAX if not present in the index.
114 */
59f9f57e 115 uint64_t packet_seq_num = UINT64_MAX;
0b067334
SM
116};
117
118struct ctf_fs_ds_index
119{
3505f709 120 std::vector<ctf_fs_ds_index_entry> entries;
0b067334
SM
121};
122
123struct ctf_fs_ds_file_group
124{
1857ccb8 125 using UP = std::unique_ptr<ctf_fs_ds_file_group>;
f0ab0592 126
a6791b37
SM
127 /*
128 * Insert ds_file_info in the list of ds_file_infos at the right
129 * place to keep it sorted.
130 */
131 void insert_ds_file_info_sorted(ctf_fs_ds_file_info::UP ds_file_info);
132
0b067334 133 /*
0b067334
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 */
49befcfd 140 std::vector<ctf_fs_ds_file_info::UP> ds_file_infos;
0b067334
SM
141
142 /* Owned by this */
143 struct ctf_stream_class *sc = nullptr;
144
145 /* Owned by this */
17d8205a 146 nonstd::optional<bt2::Stream::Shared> stream;
0b067334
SM
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
979732e3 154 ctf_fs_ds_index index;
0b067334
SM
155};
156
e98a2d6e 157BT_HIDDEN
6d0b3c49
SM
158ctf_fs_ds_file::UP ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
159 nonstd::optional<bt2::Stream::Shared> stream,
160 const char *path, const bt2_common::LogCfg& logCfg);
e98a2d6e 161
97ade20b 162BT_HIDDEN
979732e3
SM
163nonstd::optional<ctf_fs_ds_index>
164ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file, struct ctf_fs_ds_file_info *ds_file_info,
165 struct ctf_msg_iter *msg_iter);
97ade20b 166
f2b5ec1f 167BT_HIDDEN ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns);
0b067334 168
f0ab0592
SM
169BT_HIDDEN ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
170 struct ctf_stream_class *sc,
171 uint64_t stream_instance_id,
979732e3 172 ctf_fs_ds_index index);
0b067334 173
f6e68e70
SM
174/*
175 * Medium operations to iterate on a single ctf_fs_ds_file.
176 *
177 * The data pointer when using this must be a pointer to the ctf_fs_ds_file.
178 */
18a1979b 179extern struct ctf_msg_iter_medium_ops ctf_fs_ds_file_medops;
6de92955 180
f6e68e70
SM
181/*
182 * Medium operations to iterate on the packet of a ctf_fs_ds_group.
183 *
184 * The iteration is done based on the index of the group.
185 *
186 * The data pointer when using these medops must be a pointer to a ctf_fs_ds
187 * group_medops_data structure.
188 */
dfcb42a6 189BT_HIDDEN
f6e68e70
SM
190extern struct ctf_msg_iter_medium_ops ctf_fs_ds_group_medops;
191
37638dce
SM
192struct ctf_fs_ds_group_medops_data_deleter
193{
194 void operator()(ctf_fs_ds_group_medops_data *data);
195};
196
197using ctf_fs_ds_group_medops_data_up =
198 std::unique_ptr<ctf_fs_ds_group_medops_data, ctf_fs_ds_group_medops_data_deleter>;
199
f6e68e70
SM
200BT_HIDDEN
201enum ctf_msg_iter_medium_status ctf_fs_ds_group_medops_data_create(
4164020e 202 struct ctf_fs_ds_file_group *ds_file_group, bt_self_message_iterator *self_msg_iter,
37638dce 203 const bt2_common::LogCfg& logCfg, ctf_fs_ds_group_medops_data_up& out);
f6e68e70
SM
204
205BT_HIDDEN
206void ctf_fs_ds_group_medops_data_reset(struct ctf_fs_ds_group_medops_data *data);
207
94cf822e 208#endif /* CTF_FS_DS_FILE_H */
This page took 0.082525 seconds and 5 git commands to generate.