From bf012bdeed813d8cb261a630655887080388f465 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Fri, 14 Jun 2019 12:23:36 -0400 Subject: [PATCH] ctf: add weak ref to stream file in index entry This will be useful to create `bt_msg_iter` without having access to the `ctf_fs_ds_file_info` struct owning the path to the stream file. Signed-off-by: Francis Deslauriers Change-Id: Ie7173af60330b601bd755822198ed650e3b9b9b4 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1434 Tested-by: jenkins Reviewed-by: Philippe Proulx --- src/plugins/ctf/fs-src/data-stream-file.c | 19 ++++++--- src/plugins/ctf/fs-src/data-stream-file.h | 3 +- src/plugins/ctf/fs-src/fs.c | 50 ++++------------------- src/plugins/ctf/fs-src/fs.h | 3 ++ 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 4351ae72..352efa89 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -284,7 +284,8 @@ int convert_cycles_to_ns(struct ctf_clock_class *clock_class, static struct ctf_fs_ds_index *build_index_from_idx_file( - struct ctf_fs_ds_file *ds_file) + struct ctf_fs_ds_file *ds_file, + struct ctf_fs_ds_file_info *file_info) { int ret; gchar *directory = NULL; @@ -403,6 +404,9 @@ struct ctf_fs_ds_index *build_index_from_idx_file( goto error; } + /* Set path to stream file. */ + index_entry->path = file_info->path->str; + /* Convert size in bits to bytes. */ packet_size /= CHAR_BIT; index_entry->packet_size = packet_size; @@ -521,7 +525,8 @@ end: static struct ctf_fs_ds_index *build_index_from_stream_file( - struct ctf_fs_ds_file *ds_file) + struct ctf_fs_ds_file *ds_file, + struct ctf_fs_ds_file_info *file_info) { int ret; struct ctf_fs_ds_index *index = NULL; @@ -588,6 +593,9 @@ struct ctf_fs_ds_index *build_index_from_stream_file( goto error; } + /* Set path to stream file. */ + index_entry->path = file_info->path->str; + ret = init_index_entry(index_entry, ds_file, &props, current_packet_size_bytes, current_packet_offset_bytes); if (ret) { @@ -672,18 +680,19 @@ end: BT_HIDDEN struct ctf_fs_ds_index *ctf_fs_ds_file_build_index( - struct ctf_fs_ds_file *ds_file) + struct ctf_fs_ds_file *ds_file, + struct ctf_fs_ds_file_info *file_info) { struct ctf_fs_ds_index *index; - index = build_index_from_idx_file(ds_file); + index = build_index_from_idx_file(ds_file, file_info); if (index) { goto end; } BT_COMP_LOGI("Failed to build index from .index file; " "falling back to stream indexing."); - index = build_index_from_stream_file(ds_file); + index = build_index_from_stream_file(ds_file, file_info); end: return index; } diff --git a/src/plugins/ctf/fs-src/data-stream-file.h b/src/plugins/ctf/fs-src/data-stream-file.h index 622f6d42..af81915d 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.h +++ b/src/plugins/ctf/fs-src/data-stream-file.h @@ -109,7 +109,8 @@ bt_component_class_message_iterator_next_method_status ctf_fs_ds_file_next( BT_HIDDEN struct ctf_fs_ds_index *ctf_fs_ds_file_build_index( - struct ctf_fs_ds_file *ds_file); + struct ctf_fs_ds_file *ds_file, + struct ctf_fs_ds_file_info *ds_file_info); BT_HIDDEN struct ctf_fs_ds_index *ctf_fs_ds_index_create(bt_logging_level log_level, diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index e33107ae..9282f932 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -697,36 +697,6 @@ void ds_file_group_insert_ds_index_entry_sorted( array_insert(ds_file_group->index->entries, entry, i); } -/* - * Create a new ds_file_info using the provided path, begin_ns and index, then - * add it to ds_file_group's list of ds_file_infos. - */ - -static -int ctf_fs_ds_file_group_add_ds_file_info( - struct ctf_fs_ds_file_group *ds_file_group, - const char *path, int64_t begin_ns) -{ - struct ctf_fs_ds_file_info *ds_file_info; - int ret = 0; - - ds_file_info = ctf_fs_ds_file_info_create(path, begin_ns); - if (!ds_file_info) { - goto error; - } - - ds_file_group_insert_ds_file_info_sorted(ds_file_group, ds_file_info); - - ds_file_info = NULL; - goto end; - -error: - ctf_fs_ds_file_info_destroy(ds_file_info); - ret = -1; -end: - return ret; -} - static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const char *path) @@ -738,6 +708,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, int ret; size_t i; struct ctf_fs_ds_file *ds_file = NULL; + struct ctf_fs_ds_file_info *ds_file_info = NULL; struct ctf_fs_ds_index *index = NULL; struct bt_msg_iter *msg_iter = NULL; struct ctf_stream_class *sc = NULL; @@ -785,7 +756,12 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, } } - index = ctf_fs_ds_file_build_index(ds_file); + ds_file_info = ctf_fs_ds_file_info_create(path, begin_ns); + if (!ds_file_info) { + goto error; + } + + index = ctf_fs_ds_file_build_index(ds_file, ds_file_info); if (!index) { BT_COMP_LOGW("Failed to index CTF stream file \'%s\'", ds_file->file->path->str); @@ -817,11 +793,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, goto error; } - ret = ctf_fs_ds_file_group_add_ds_file_info(ds_file_group, - path, begin_ns); - if (ret) { - goto error; - } + ds_file_group_insert_ds_file_info_sorted(ds_file_group, ds_file_info); add_group = true; goto end; @@ -856,11 +828,7 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, add_group = true; } - ret = ctf_fs_ds_file_group_add_ds_file_info(ds_file_group, path, - begin_ns); - if (ret) { - goto error; - } + ds_file_group_insert_ds_file_info_sorted(ds_file_group, ds_file_info); goto end; diff --git a/src/plugins/ctf/fs-src/fs.h b/src/plugins/ctf/fs-src/fs.h index 8968fcba..5ba3d571 100644 --- a/src/plugins/ctf/fs-src/fs.h +++ b/src/plugins/ctf/fs-src/fs.h @@ -113,6 +113,9 @@ struct ctf_fs_trace { }; struct ctf_fs_ds_index_entry { + /* Weak, belongs to ctf_fs_ds_file_info. */ + const char *path; + /* Position, in bytes, of the packet from the beginning of the file. */ uint64_t offset; -- 2.34.1