ctf: add weak ref to stream file in index entry
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 14 Jun 2019 16:23:36 +0000 (12:23 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 16 Aug 2019 15:35:50 +0000 (11:35 -0400)
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 <francis.deslauriers@efficios.com>
Change-Id: Ie7173af60330b601bd755822198ed650e3b9b9b4
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1434
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/fs-src/data-stream-file.c
src/plugins/ctf/fs-src/data-stream-file.h
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/fs.h

index 4351ae72c1a0566c417c817711ddc8fbca6e8e65..352efa89711facfff163105bb4f601c0d631a217 100644 (file)
@@ -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;
 }
index 622f6d424c9625edf49bdb7f867633bec322a391..af81915d829705ca3a43fbe8e4912822ac18b112 100644 (file)
@@ -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,
index e33107aea4d661e00d5d2432223024e933e3a6d3..9282f932e209a464efa68e6d077422d101fcc792 100644 (file)
@@ -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;
 
index 8968fcba88412a3bc71408de7b686ff54e16d713..5ba3d571436ed11ef5de121243f737183119fce9 100644 (file)
@@ -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;
 
This page took 0.028357 seconds and 4 git commands to generate.