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