static enum ctf_msg_iter_medium_status medop_group_switch_packet(void *void_data)
{
struct ctf_fs_ds_group_medops_data *data = (struct ctf_fs_ds_group_medops_data *) void_data;
- struct ctf_fs_ds_index_entry *index_entry;
/* If we have gone through all index entries, we are done. */
if (data->next_index_entry_index >= data->ds_file_group->index->entries.size()) {
* Otherwise, look up the next index entry / packet and prepare it
* for reading.
*/
- index_entry = data->ds_file_group->index->entries[data->next_index_entry_index].get();
+ ctf_fs_ds_index_entry& index_entry =
+ 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);
+ ctf_msg_iter_medium_status status = ctf_fs_ds_group_medops_set_file(data, &index_entry);
if (status != CTF_MSG_ITER_MEDIUM_STATUS_OK) {
return status;
}
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::UP index_entry;
ctf_fs_ds_index_entry *prev_index_entry = NULL;
bt2_common::DataLen totalPacketsSize = bt2_common::DataLen::fromBytes(0);
size_t file_index_entry_size;
return nullptr;
}
- index_entry = bt2_common::makeUnique<ctf_fs_ds_index_entry>(offset, packetSize);
- if (!index_entry) {
- BT_CLOGE_APPEND_CAUSE("Failed to create a ctf_fs_ds_index_entry.");
- return nullptr;
- }
+ ctf_fs_ds_index_entry index_entry {offset, packetSize};
/* Set path to stream file. */
- index_entry->path = file_info->path.c_str();
+ index_entry.path = file_info->path.c_str();
- index_entry->timestamp_begin = be64toh(file_index->timestamp_begin);
- index_entry->timestamp_end = be64toh(file_index->timestamp_end);
- if (index_entry->timestamp_end < index_entry->timestamp_begin) {
+ index_entry.timestamp_begin = be64toh(file_index->timestamp_begin);
+ index_entry.timestamp_end = be64toh(file_index->timestamp_end);
+ if (index_entry.timestamp_end < index_entry.timestamp_begin) {
BT_CLOGW(
"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);
+ index_entry.timestamp_begin, index_entry.timestamp_end);
return nullptr;
}
/* Convert the packet's bound to nanoseconds since Epoch. */
- ret = convert_cycles_to_ns(sc->default_clock_class, index_entry->timestamp_begin,
- &index_entry->timestamp_begin_ns);
+ ret = convert_cycles_to_ns(sc->default_clock_class, index_entry.timestamp_begin,
+ &index_entry.timestamp_begin_ns);
if (ret) {
BT_CLOGI_STR(
"Failed to convert raw timestamp to nanoseconds since Epoch during index parsing");
return nullptr;
}
- ret = convert_cycles_to_ns(sc->default_clock_class, index_entry->timestamp_end,
- &index_entry->timestamp_end_ns);
+ 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");
}
if (version_minor >= 1) {
- index_entry->packet_seq_num = be64toh(file_index->packet_seq_num);
+ index_entry.packet_seq_num = be64toh(file_index->packet_seq_num);
}
totalPacketsSize += packetSize;
file_pos += file_index_entry_size;
- prev_index_entry = index_entry.get();
+ index->entries.emplace_back(index_entry);
- index->entries.emplace_back(std::move(index_entry));
+ prev_index_entry = &index->entries.back();
}
/* Validate that the index addresses the complete stream. */
return index;
}
-static int init_index_entry(struct ctf_fs_ds_index_entry *entry, struct ctf_fs_ds_file *ds_file,
+static int init_index_entry(ctf_fs_ds_index_entry& entry, struct ctf_fs_ds_file *ds_file,
struct ctf_msg_iter_packet_properties *props)
{
struct ctf_stream_class *sc;
const bt2_common::LogCfg& logCfg = ds_file->logCfg;
if (props->snapshots.beginning_clock != UINT64_C(-1)) {
- entry->timestamp_begin = props->snapshots.beginning_clock;
+ entry.timestamp_begin = props->snapshots.beginning_clock;
/* Convert the packet's bound to nanoseconds since Epoch. */
int ret = convert_cycles_to_ns(sc->default_clock_class, props->snapshots.beginning_clock,
- &entry->timestamp_begin_ns);
+ &entry.timestamp_begin_ns);
if (ret) {
BT_CLOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
return ret;
}
} else {
- entry->timestamp_begin = UINT64_C(-1);
- entry->timestamp_begin_ns = UINT64_C(-1);
+ entry.timestamp_begin = UINT64_C(-1);
+ entry.timestamp_begin_ns = UINT64_C(-1);
}
if (props->snapshots.end_clock != UINT64_C(-1)) {
- entry->timestamp_end = props->snapshots.end_clock;
+ entry.timestamp_end = props->snapshots.end_clock;
/* Convert the packet's bound to nanoseconds since Epoch. */
int ret = convert_cycles_to_ns(sc->default_clock_class, props->snapshots.end_clock,
- &entry->timestamp_end_ns);
+ &entry.timestamp_end_ns);
if (ret) {
BT_CLOGI_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
return ret;
}
} else {
- entry->timestamp_end = UINT64_C(-1);
- entry->timestamp_end_ns = UINT64_C(-1);
+ entry.timestamp_end = UINT64_C(-1);
+ entry.timestamp_end_ns = UINT64_C(-1);
}
return 0;
ctf_fs_ds_index::UP index = bt2_common::makeUnique<ctf_fs_ds_index>();
while (true) {
- ctf_fs_ds_index_entry::UP index_entry;
struct ctf_msg_iter_packet_properties props;
if (currentPacketOffset.bytes() > ds_file->file->size) {
return nullptr;
}
- index_entry =
- bt2_common::makeUnique<ctf_fs_ds_index_entry>(currentPacketOffset, currentPacketSize);
- if (!index_entry) {
- BT_CLOGE_APPEND_CAUSE("Failed to create a ctf_fs_ds_index_entry.");
- return nullptr;
- }
+ ctf_fs_ds_index_entry index_entry {currentPacketOffset, currentPacketSize};
/* Set path to stream file. */
- index_entry->path = file_info->path.c_str();
+ index_entry.path = file_info->path.c_str();
- ret = init_index_entry(index_entry.get(), ds_file, &props);
+ ret = init_index_entry(index_entry, ds_file, &props);
if (ret) {
return nullptr;
}
ds_file_group->ds_file_infos.insert(it, std::move(ds_file_info));
}
-static bool ds_index_entries_equal(const struct ctf_fs_ds_index_entry *left,
- const struct ctf_fs_ds_index_entry *right)
+static bool ds_index_entries_equal(const struct ctf_fs_ds_index_entry& left,
+ const struct ctf_fs_ds_index_entry& right)
{
- if (left->packetSize != right->packetSize) {
+ if (left.packetSize != right.packetSize) {
return false;
}
- if (left->timestamp_begin != right->timestamp_begin) {
+ if (left.timestamp_begin != right.timestamp_begin) {
return false;
}
- if (left->timestamp_end != right->timestamp_end) {
+ if (left.timestamp_end != right.timestamp_end) {
return false;
}
- if (left->packet_seq_num != right->packet_seq_num) {
+ if (left.packet_seq_num != right.packet_seq_num) {
return false;
}
*/
static void ds_index_insert_ds_index_entry_sorted(struct ctf_fs_ds_index *index,
- ctf_fs_ds_index_entry::UP entry)
+ const ctf_fs_ds_index_entry& entry)
{
/* Find the spot where to insert this index entry. */
auto otherEntry = index->entries.begin();
for (; otherEntry != index->entries.end(); ++otherEntry) {
- if (entry->timestamp_begin_ns <= (*otherEntry)->timestamp_begin_ns) {
+ if (entry.timestamp_begin_ns <= otherEntry->timestamp_begin_ns) {
break;
}
}
* snapshots of the same trace. We then want the index to contain
* a reference to only one copy of that packet.
*/
- if (otherEntry == index->entries.end() ||
- !ds_index_entries_equal(entry.get(), otherEntry->get())) {
- index->entries.insert(otherEntry, std::move(entry));
+ if (otherEntry == index->entries.end() || !ds_index_entries_equal(entry, *otherEntry)) {
+ index->entries.emplace(otherEntry, entry);
}
}
static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index::UP src)
{
- for (ctf_fs_ds_index_entry::UP& entry : src->entries) {
- ds_index_insert_ds_index_entry_sorted(dest, std::move(entry));
+ for (const ctf_fs_ds_index_entry& entry : src->entries) {
+ ds_index_insert_ds_index_entry_sorted(dest, entry);
}
}
static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_clock_class *default_cc,
- struct ctf_fs_ds_index_entry *index_entry,
+ const ctf_fs_ds_index_entry& index_entry,
enum target_event target_event, uint64_t *cs,
int64_t *ts_ns)
{
const bt2_common::LogCfg& logCfg = ctf_fs_trace->logCfg;
BT_ASSERT(ctf_fs_trace);
- BT_ASSERT(index_entry);
- BT_ASSERT(index_entry->path);
+ BT_ASSERT(index_entry.path);
ctf_fs_ds_file::UP ds_file =
- ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, index_entry->path, logCfg);
+ ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, index_entry.path, logCfg);
if (!ds_file) {
BT_CLOGE_APPEND_CAUSE("Failed to create a ctf_fs_ds_file");
return -1;
ctf_msg_iter_set_dry_run(msg_iter.get(), true);
/* Seek to the beginning of the target packet. */
- iter_status = ctf_msg_iter_seek(msg_iter.get(), index_entry->offset.bytes());
+ iter_status = ctf_msg_iter_seek(msg_iter.get(), index_entry.offset.bytes());
if (iter_status) {
/* ctf_msg_iter_seek() logs errors. */
return -1;
static int decode_packet_first_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_clock_class *default_cc,
- struct ctf_fs_ds_index_entry *index_entry,
+ const ctf_fs_ds_index_entry& index_entry,
uint64_t *cs, int64_t *ts_ns)
{
return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, FIRST_EVENT, cs,
static int decode_packet_last_event_timestamp(struct ctf_fs_trace *ctf_fs_trace,
struct ctf_clock_class *default_cc,
- struct ctf_fs_ds_index_entry *index_entry,
+ const ctf_fs_ds_index_entry& index_entry,
uint64_t *cs, int64_t *ts_ns)
{
return decode_clock_snapshot_after_event(ctf_fs_trace, default_cc, index_entry, LAST_EVENT, cs,
* fixed differently after.
*/
for (size_t entry_i = 0; entry_i < index->entries.size() - 1; ++entry_i) {
- ctf_fs_ds_index_entry *curr_entry = index->entries[entry_i].get();
- ctf_fs_ds_index_entry *next_entry = index->entries[entry_i + 1].get();
+ ctf_fs_ds_index_entry& curr_entry = index->entries[entry_i];
+ const ctf_fs_ds_index_entry& next_entry = index->entries[entry_i + 1];
/*
* 1. Set the current index entry `end` timestamp to
* the next index entry `begin` timestamp.
*/
- curr_entry->timestamp_end = next_entry->timestamp_begin;
- curr_entry->timestamp_end_ns = next_entry->timestamp_begin_ns;
+ curr_entry.timestamp_end = next_entry.timestamp_begin;
+ curr_entry.timestamp_end_ns = next_entry.timestamp_begin_ns;
}
/*
* 2. Fix the last entry by decoding the last event of the last
* packet.
*/
- ctf_fs_ds_index_entry *last_entry = index->entries.back().get();
- BT_ASSERT(last_entry);
+ ctf_fs_ds_index_entry& last_entry = index->entries.back();
BT_ASSERT(ds_file_group->sc->default_clock_class);
default_cc = ds_file_group->sc->default_clock_class;
* Decode packet to read the timestamp of the last event of the
* entry.
*/
- int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
- &last_entry->timestamp_end,
- &last_entry->timestamp_end_ns);
+ int ret = decode_packet_last_event_timestamp(
+ trace, default_cc, last_entry, &last_entry.timestamp_end, &last_entry.timestamp_end_ns);
if (ret) {
BT_CLOGE_APPEND_CAUSE(
"Failed to decode stream's last packet to get its last event's clock snapshot.");
* (index = 1).
*/
for (size_t entry_i = 1; entry_i < index->entries.size(); ++entry_i) {
- ctf_fs_ds_index_entry *prev_entry = index->entries[entry_i - 1].get();
- ctf_fs_ds_index_entry *curr_entry = index->entries[entry_i].get();
+ ctf_fs_ds_index_entry& prev_entry = index->entries[entry_i - 1];
+ ctf_fs_ds_index_entry& curr_entry = index->entries[entry_i];
/*
* 2. Set the current entry `begin` timestamp to the
* timestamp of the first event of the current packet.
*/
int ret = decode_packet_first_event_timestamp(trace, default_cc, curr_entry,
- &curr_entry->timestamp_begin,
- &curr_entry->timestamp_begin_ns);
+ &curr_entry.timestamp_begin,
+ &curr_entry.timestamp_begin_ns);
if (ret) {
BT_CLOGE_APPEND_CAUSE("Failed to decode first event's clock snapshot");
return ret;
* 3. Set the previous entry `end` timestamp to the
* timestamp of the first event of the current packet.
*/
- prev_entry->timestamp_end = curr_entry->timestamp_begin;
- prev_entry->timestamp_end_ns = curr_entry->timestamp_begin_ns;
+ prev_entry.timestamp_end = curr_entry.timestamp_begin;
+ prev_entry.timestamp_end_ns = curr_entry.timestamp_begin_ns;
}
}
BT_ASSERT(index);
BT_ASSERT(!index->entries.empty());
- ctf_fs_ds_index_entry *last_entry = index->entries.back().get();
- BT_ASSERT(last_entry);
+ ctf_fs_ds_index_entry& last_entry = index->entries.back();
/* 1. Fix the last entry first. */
- if (last_entry->timestamp_end == 0 && last_entry->timestamp_begin != 0) {
+ if (last_entry.timestamp_end == 0 && last_entry.timestamp_begin != 0) {
/*
* Decode packet to read the timestamp of the
* last event of the stream file.
*/
int ret = decode_packet_last_event_timestamp(trace, default_cc, last_entry,
- &last_entry->timestamp_end,
- &last_entry->timestamp_end_ns);
+ &last_entry.timestamp_end,
+ &last_entry.timestamp_end_ns);
if (ret) {
BT_CLOGE_APPEND_CAUSE("Failed to decode last event's clock snapshot");
return ret;
/* Iterate over all entries but the last one. */
for (size_t entry_idx = 0; entry_idx < index->entries.size() - 1; ++entry_idx) {
- ctf_fs_ds_index_entry *curr_entry = index->entries[entry_idx].get();
- ctf_fs_ds_index_entry *next_entry = index->entries[entry_idx + 1].get();
+ ctf_fs_ds_index_entry& curr_entry = index->entries[entry_idx];
+ const ctf_fs_ds_index_entry& next_entry = index->entries[entry_idx + 1];
- if (curr_entry->timestamp_end == 0 && curr_entry->timestamp_begin != 0) {
+ if (curr_entry.timestamp_end == 0 && curr_entry.timestamp_begin != 0) {
/*
* 2. Set the current index entry `end` timestamp to
* the next index entry `begin` timestamp.
*/
- curr_entry->timestamp_end = next_entry->timestamp_begin;
- curr_entry->timestamp_end_ns = next_entry->timestamp_begin_ns;
+ curr_entry.timestamp_end = next_entry.timestamp_begin;
+ curr_entry.timestamp_end_ns = next_entry.timestamp_begin_ns;
}
}
}