From fe2f9cda63e15a502a79677034779433986b1652 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sat, 6 Apr 2024 00:08:54 -0400 Subject: [PATCH] src.ctf.fs: make ctf_fs_ds_file_group::index a ctf_fs_ds_index::UP Change that field to be a unique_ptr. Adjust some functions in fs.cpp around that. Signed-off-by: Simon Marchi Change-Id: Ie2cdfe0b81f1d817093de74faf6c12ef2e6169a1 Reviewed-on: https://review.lttng.org/c/babeltrace/+/8252 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12290 --- src/plugins/ctf/fs-src/data-stream-file.cpp | 6 ++-- src/plugins/ctf/fs-src/data-stream-file.hpp | 7 ++--- src/plugins/ctf/fs-src/fs.cpp | 35 ++++++++------------- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.cpp b/src/plugins/ctf/fs-src/data-stream-file.cpp index d0cf562b..11dee041 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.cpp +++ b/src/plugins/ctf/fs-src/data-stream-file.cpp @@ -944,8 +944,6 @@ static void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group *ds_file_gr return; } - ctf_fs_ds_index_destroy(ds_file_group->index); - bt_stream_put_ref(ds_file_group->stream); delete ds_file_group; } @@ -958,11 +956,11 @@ void ctf_fs_ds_file_group_deleter::operator()(ctf_fs_ds_file_group *group) noexc 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, - struct ctf_fs_ds_index *index) + ctf_fs_ds_index::UP index) { ctf_fs_ds_file_group::UP ds_file_group {new ctf_fs_ds_file_group}; - ds_file_group->index = index; + ds_file_group->index = std::move(index); ds_file_group->stream_id = stream_instance_id; BT_ASSERT(sc); diff --git a/src/plugins/ctf/fs-src/data-stream-file.hpp b/src/plugins/ctf/fs-src/data-stream-file.hpp index a87877ca..9e8696e4 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.hpp +++ b/src/plugins/ctf/fs-src/data-stream-file.hpp @@ -149,10 +149,7 @@ struct ctf_fs_ds_file_group /* Weak, belongs to component */ struct ctf_fs_trace *ctf_fs_trace = nullptr; - /* - * Owned by this. - */ - struct ctf_fs_ds_index *index = nullptr; + ctf_fs_ds_index::UP index; }; struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream, @@ -173,7 +170,7 @@ ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t beg 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, - struct ctf_fs_ds_index *index); + ctf_fs_ds_index::UP index); /* * Medium operations to iterate on a single ctf_fs_ds_file. diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index 2c8a440c..b7d2d855 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -521,7 +521,7 @@ static void ds_index_insert_ds_index_entry_sorted(struct ctf_fs_ds_index *index, } } -static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, struct ctf_fs_ds_index *src) +static void merge_ctf_fs_ds_indexes(struct ctf_fs_ds_index *dest, ctf_fs_ds_index::UP src) { guint i; @@ -547,7 +547,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const int ret; struct ctf_fs_ds_file *ds_file = NULL; ctf_fs_ds_file_info::UP ds_file_info; - struct ctf_fs_ds_index *index = NULL; + ctf_fs_ds_index::UP index; struct ctf_msg_iter *msg_iter = NULL; struct ctf_stream_class *sc = NULL; struct ctf_msg_iter_packet_properties props; @@ -604,7 +604,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const goto error; } - index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter).release(); + index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter); if (!index) { BT_CPPLOGE_APPEND_CAUSE_SPEC(ctf_fs_trace->logger, "Failed to index CTF stream file \'{}\'", ds_file->file->path->str); @@ -628,10 +628,8 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const * there's no timestamp to order the file within its * group. */ - new_ds_file_group = ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), index); - - /* Ownership of index is transferred. */ - index = NULL; + new_ds_file_group = + ctf_fs_ds_file_group_create(ctf_fs_trace, sc, UINT64_C(-1), std::move(index)); if (!new_ds_file_group) { goto error; @@ -655,9 +653,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const if (!ds_file_group) { new_ds_file_group = - ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, index); - /* Ownership of index is transferred. */ - index = NULL; + ctf_fs_ds_file_group_create(ctf_fs_trace, sc, stream_instance_id, std::move(index)); if (!new_ds_file_group) { goto error; } @@ -665,7 +661,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const 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, index); + merge_ctf_fs_ds_indexes(ds_file_group->index.get(), std::move(index)); } ds_file_group_insert_ds_file_info_sorted(ds_file_group, std::move(ds_file_info)); @@ -682,7 +678,6 @@ end: ctf_msg_iter_destroy(msg_iter); } - ctf_fs_ds_index_destroy(index); return ret; } @@ -1003,7 +998,7 @@ static void merge_ctf_fs_ds_file_groups(struct ctf_fs_ds_file_group *dest, } /* Merge both indexes. */ - merge_ctf_fs_ds_indexes(dest->index, src->index); + merge_ctf_fs_ds_indexes(dest->index.get(), std::move(src->index)); } /* Merge src_trace's data stream file groups into dest_trace's. */ @@ -1064,17 +1059,15 @@ static int merge_matching_ctf_fs_ds_file_groups(struct ctf_fs_trace *dest_trace, src_group->sc->id); BT_ASSERT(sc); - auto index = ctf_fs_ds_index_create(dest_trace->logger).release(); + auto index = ctf_fs_ds_index_create(dest_trace->logger); if (!index) { ret = -1; goto end; } auto new_dest_group = - ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, index); + ctf_fs_ds_file_group_create(dest_trace, sc, src_group->stream_id, std::move(index)); - /* Ownership of index is transferred. */ - index = NULL; if (!new_dest_group) { ret = -1; goto end; @@ -1294,10 +1287,9 @@ static int fix_index_lttng_event_after_packet_bug(struct ctf_fs_trace *trace) guint entry_i; struct ctf_clock_class *default_cc; struct ctf_fs_ds_index_entry *last_entry; - struct ctf_fs_ds_index *index; BT_ASSERT(ds_file_group); - index = ds_file_group->index; + const auto index = ds_file_group->index.get(); BT_ASSERT(index); BT_ASSERT(index->entries); @@ -1372,7 +1364,7 @@ static int fix_index_barectf_event_before_packet_bug(struct ctf_fs_trace *trace) for (const auto& ds_file_group : trace->ds_file_groups) { guint entry_i; struct ctf_clock_class *default_cc; - struct ctf_fs_ds_index *index = ds_file_group->index; + const auto index = ds_file_group->index.get(); BT_ASSERT(index); BT_ASSERT(index->entries); @@ -1439,10 +1431,9 @@ static int fix_index_lttng_crash_quirk(struct ctf_fs_trace *trace) for (const auto& ds_file_group : trace->ds_file_groups) { guint entry_idx; struct ctf_clock_class *default_cc; - struct ctf_fs_ds_index *index; BT_ASSERT(ds_file_group); - index = ds_file_group->index; + const auto index = ds_file_group->index.get(); BT_ASSERT(ds_file_group->sc->default_clock_class); default_cc = ds_file_group->sc->default_clock_class; -- 2.34.1