struct ctf_fs_ds_group_medops_data *data = (struct ctf_fs_ds_group_medops_data *) void_data;
/* If we have gone through all index entries, we are done. */
- if (data->next_index_entry_index >= data->ds_file_group->index->entries.size()) {
+ if (data->next_index_entry_index >= data->ds_file_group->index.entries.size()) {
return CTF_MSG_ITER_MEDIUM_STATUS_EOF;
}
* for reading.
*/
ctf_fs_ds_index_entry& index_entry =
- data->ds_file_group->index->entries[data->next_index_entry_index];
+ data->ds_file_group->index.entries[data->next_index_entry_index];
ctf_msg_iter_medium_status status = ctf_fs_ds_group_medops_set_file(data, &index_entry);
if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
{
BT_ASSERT(self_msg_iter);
BT_ASSERT(ds_file_group);
- BT_ASSERT(ds_file_group->index);
- BT_ASSERT(!ds_file_group->index->entries.empty());
+ BT_ASSERT(!ds_file_group->index.entries.empty());
out.reset(new ctf_fs_ds_group_medops_data {logCfg});
clock_class->offset_cycles, ns);
}
-static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+static nonstd::optional<ctf_fs_ds_index>
+build_index_from_idx_file(struct ctf_fs_ds_file *ds_file, struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
bt2_common::GCharUP directory;
bt2_common::GCharUP basename;
gsize filesize;
const char *mmap_begin = NULL, *file_pos = NULL;
const struct ctf_packet_index_file_hdr *header = NULL;
- ctf_fs_ds_index::UP index;
ctf_fs_ds_index_entry *prev_index_entry = NULL;
bt2_common::DataLen totalPacketsSize = bt2_common::DataLen::fromBytes(0);
size_t file_index_entry_size;
int ret = ctf_msg_iter_get_packet_properties(msg_iter, &props);
if (ret) {
BT_CLOGI_STR("Cannot read first packet's header and context fields.");
- return nullptr;
+ return nonstd::nullopt;
}
sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc, props.stream_class_id);
BT_ASSERT(sc);
if (!sc->default_clock_class) {
BT_CLOGI_STR("Cannot find stream class's default clock class.");
- return nullptr;
+ return nonstd::nullopt;
}
/* Look for index file in relative path index/name.idx. */
basename.reset(g_path_get_basename(ds_file->file->path.c_str()));
if (!basename) {
BT_CLOGE("Cannot get the basename of datastream file %s", ds_file->file->path.c_str());
- return nullptr;
+ return nonstd::nullopt;
}
directory.reset(g_path_get_dirname(ds_file->file->path.c_str()));
if (!directory) {
BT_CLOGE("Cannot get dirname of datastream file %s", ds_file->file->path.c_str());
- return nullptr;
+ return nonstd::nullopt;
}
index_basename = basename.get();
mapped_file.reset(g_mapped_file_new(index_file_path.get(), FALSE, NULL));
if (!mapped_file) {
BT_CLOGD("Cannot create new mapped file %s", index_file_path.get());
- return nullptr;
+ return nonstd::nullopt;
}
/*
BT_CLOGW("Invalid LTTng trace index file: "
"file size (%zu bytes) < header size (%zu bytes)",
filesize, sizeof(*header));
- return nullptr;
+ return nonstd::nullopt;
}
mmap_begin = g_mapped_file_get_contents(mapped_file.get());
file_pos = g_mapped_file_get_contents(mapped_file.get()) + sizeof(*header);
if (be32toh(header->magic) != CTF_INDEX_MAGIC) {
BT_CLOGW_STR("Invalid LTTng trace index: \"magic\" field validation failed");
- return nullptr;
+ return nonstd::nullopt;
}
version_major = be32toh(header->index_major);
BT_CLOGW("Unknown LTTng trace index version: "
"major=%" PRIu32 ", minor=%" PRIu32,
version_major, version_minor);
- return nullptr;
+ return nonstd::nullopt;
}
file_index_entry_size = be32toh(header->packet_index_len);
"Invalid `packet_index_len` in LTTng trace index file (`packet_index_len` < CTF index 1.0 index entry size): "
"packet_index_len=%zu, CTF_INDEX_1_0_SIZE=%zu",
file_index_entry_size, CTF_INDEX_1_0_SIZE);
- return nullptr;
+ return nonstd::nullopt;
}
file_entry_count = (filesize - sizeof(*header)) / file_index_entry_size;
"(%zu bytes) is not a multiple of the index entry size "
"(%zu bytes)",
(filesize - sizeof(*header)), sizeof(*header));
- return nullptr;
+ return nonstd::nullopt;
}
- index = bt2_common::makeUnique<ctf_fs_ds_index>();
+ ctf_fs_ds_index index;
for (i = 0; i < file_entry_count; i++) {
struct ctf_packet_index *file_index = (struct ctf_packet_index *) file_pos;
if (packetSize.hasExtraBits()) {
BT_CLOGW("Invalid packet size encountered in LTTng trace index file");
- return nullptr;
+ return nonstd::nullopt;
}
bt2_common::DataLen offset = bt2_common::DataLen::fromBytes(be64toh(file_index->offset));
BT_CLOGW("Invalid, non-monotonic, packet offset encountered in LTTng trace index file: "
"previous offset=%llu bytes, current offset=%llu bytes",
prev_index_entry->offset.bytes(), offset.bytes());
- return nullptr;
+ return nonstd::nullopt;
}
ctf_fs_ds_index_entry index_entry {offset, packetSize};
"Invalid packet time bounds encountered in LTTng trace index file (begin > end): "
"timestamp_begin=%" PRIu64 "timestamp_end=%" PRIu64,
index_entry.timestamp_begin, index_entry.timestamp_end);
- return nullptr;
+ return nonstd::nullopt;
}
/* Convert the packet's bound to nanoseconds since Epoch. */
if (ret) {
BT_CLOGI_STR(
"Failed to convert raw timestamp to nanoseconds since Epoch during index parsing");
- return nullptr;
+ return nonstd::nullopt;
}
ret = convert_cycles_to_ns(sc->default_clock_class, index_entry.timestamp_end,
&index_entry.timestamp_end_ns);
if (ret) {
BT_CLOGI_STR(
"Failed to convert raw timestamp to nanoseconds since Epoch during LTTng trace index parsing");
- return nullptr;
+ return nonstd::nullopt;
}
if (version_minor >= 1) {
totalPacketsSize += packetSize;
file_pos += file_index_entry_size;
- index->entries.emplace_back(index_entry);
+ index.entries.emplace_back(index_entry);
- prev_index_entry = &index->entries.back();
+ prev_index_entry = &index.entries.back();
}
/* Validate that the index addresses the complete stream. */
BT_CLOGW("Invalid LTTng trace index file; indexed size != stream file size: "
"file-size=%" PRIu64 " bytes, total-packets-size=%llu bytes",
ds_file->file->size, totalPacketsSize.bytes());
- return nullptr;
+ return nonstd::nullopt;
}
return index;
return 0;
}
-static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+static nonstd::optional<ctf_fs_ds_index>
+build_index_from_stream_file(struct ctf_fs_ds_file *ds_file, struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
int ret;
enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK;
BT_CLOGI("Indexing stream file %s", ds_file->file->path.c_str());
- ctf_fs_ds_index::UP index = bt2_common::makeUnique<ctf_fs_ds_index>();
+ ctf_fs_ds_index index;
while (true) {
struct ctf_msg_iter_packet_properties props;
if (currentPacketOffset.bytes() > ds_file->file->size) {
BT_CLOGE_STR("Unexpected current packet's offset (larger than file).");
- return nullptr;
+ return nonstd::nullopt;
} else if (currentPacketOffset.bytes() == ds_file->file->size) {
/* No more data */
break;
iter_status = ctf_msg_iter_seek(msg_iter, currentPacketOffset.bytes());
if (iter_status != CTF_MSG_ITER_STATUS_OK) {
- return nullptr;
+ return nonstd::nullopt;
}
iter_status = ctf_msg_iter_get_packet_properties(msg_iter, &props);
if (iter_status != CTF_MSG_ITER_STATUS_OK) {
- return nullptr;
+ return nonstd::nullopt;
}
/*
"file-size-bytes=%jd",
ds_file->file->path.c_str(), currentPacketOffset.bytes(),
currentPacketSize.bytes(), (intmax_t) ds_file->file->size);
- return nullptr;
+ return nonstd::nullopt;
}
ctf_fs_ds_index_entry index_entry {currentPacketOffset, currentPacketSize};
ret = init_index_entry(index_entry, ds_file, &props);
if (ret) {
- return nullptr;
+ return nonstd::nullopt;
}
- index->entries.emplace_back(std::move(index_entry));
+ index.entries.emplace_back(std::move(index_entry));
currentPacketOffset += currentPacketSize;
BT_CLOGD("Seeking to next packet: current-packet-offset-bytes=%llu, "
}
BT_HIDDEN
-ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+nonstd::optional<ctf_fs_ds_index> ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
+ struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
- ctf_fs_ds_index::UP index;
const bt2_common::LogCfg& logCfg = ds_file->logCfg;
- index = build_index_from_idx_file(ds_file, file_info, msg_iter);
+ nonstd::optional<ctf_fs_ds_index> index =
+ build_index_from_idx_file(ds_file, file_info, msg_iter);
if (index) {
return index;
}
BT_HIDDEN ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_stream_class *sc,
uint64_t stream_instance_id,
- ctf_fs_ds_index::UP index)
+ ctf_fs_ds_index index)
{
ctf_fs_ds_file_group::UP ds_file_group {new ctf_fs_ds_file_group};
}
}
-static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index::UP src)
+static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index src)
{
- for (const ctf_fs_ds_index_entry& entry : src->entries) {
+ for (const ctf_fs_ds_index_entry& entry : src.entries) {
ds_index_insert_ds_index_entry_sorted(dest, entry);
}
}
struct ctf_fs_ds_file_group *ds_file_group = NULL;
ctf_fs_ds_file_group::UP new_ds_file_group;
ctf_fs_ds_file_info::UP ds_file_info;
- ctf_fs_ds_index::UP index;
ctf_msg_iter_up msg_iter;
struct ctf_stream_class *sc = NULL;
struct ctf_msg_iter_packet_properties props;
return -1;
}
- index = ctf_fs_ds_file_build_index(ds_file.get(), ds_file_info.get(), msg_iter.get());
+ nonstd::optional<ctf_fs_ds_index> index =
+ ctf_fs_ds_file_build_index(ds_file.get(), ds_file_info.get(), msg_iter.get());
if (!index) {
BT_CLOGE_APPEND_CAUSE("Failed to index CTF stream file \'%s\'",
ds_file->file->path.c_str());
* group.
*/
new_ds_file_group =
- ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), std::move(index));
+ ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), std::move(*index));
if (!new_ds_file_group) {
return -1;
if (!ds_file_group) {
new_ds_file_group =
- ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, std::move(index));
+ ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, std::move(*index));
if (!new_ds_file_group) {
return -1;
}
ds_file_group = new_ds_file_group.get();
ctf_fs_trace->ds_file_groups.emplace_back(std::move(new_ds_file_group));
} else {
- merge_ctf_fs_ds_indexes(ds_file_group->index.get(), std::move(index));
+ merge_ctf_fs_ds_indexes(&ds_file_group->index, std::move(*index));
}
ds_file_group_insert_ds_file_info_sorted(ds_file_group, std::move(ds_file_info));
}
/* Merge both indexes. */
- merge_ctf_fs_ds_indexes(dest->index.get(), std::move(src->index));
+ merge_ctf_fs_ds_indexes(&dest->index, std::move(src->index));
}
/* Merge src_trace's data stream file groups into dest_trace's. */
src_group->sc->id);
BT_ASSERT(sc);
- ctf_fs_ds_index::UP index = bt2_common::makeUnique<ctf_fs_ds_index>();
ctf_fs_ds_file_group::UP new_dest_group =
- ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, std::move(index));
+ ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, {});
/* Ownership of index is transferred. */
- index = NULL;
if (!new_dest_group) {
return -1;
}
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index *index;
BT_ASSERT(ds_file_group);
- index = ds_file_group->index.get();
+ ctf_fs_ds_index *index = &ds_file_group->index;
BT_ASSERT(index);
BT_ASSERT(!index->entries.empty());
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index *index = ds_file_group->index.get();
+ ctf_fs_ds_index *index = &ds_file_group->index;
BT_ASSERT(index);
BT_ASSERT(!index->entries.empty());
for (ctf_fs_ds_file_group::UP& ds_file_group : trace->ds_file_groups) {
struct ctf_clock_class *default_cc;
- struct ctf_fs_ds_index *index;
BT_ASSERT(ds_file_group);
- index = ds_file_group->index.get();
+ ctf_fs_ds_index *index = &ds_file_group->index;
BT_ASSERT(ds_file_group->sc->default_clock_class);
default_cc = ds_file_group->sc->default_clock_class;