From 6de929550157bc46ee19fa5aaca3ea2e50a12c9e Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 20 Jun 2017 14:36:52 -0400 Subject: [PATCH] src.ctf.fs: use one CTF notif iter per notification iterator MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Use only one bt_ctf_notif_iter per src.ctf.fs notification iterator, instead of one per data stream file, so that this object can keep a state for the whole packet sequence. ctf_fs_ds_file_create() now receives the notif iter to use and sets itself as its current medops user data. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- plugins/ctf/common/notif-iter/notif-iter.c | 8 +++++ plugins/ctf/common/notif-iter/notif-iter.h | 4 +++ plugins/ctf/fs-src/data-stream-file.c | 13 ++++----- plugins/ctf/fs-src/data-stream-file.h | 5 +++- plugins/ctf/fs-src/fs.c | 34 ++++++++++++++++++++-- plugins/ctf/fs-src/fs.h | 3 ++ 6 files changed, 57 insertions(+), 10 deletions(-) diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 06818d0e..06125b23 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -3129,3 +3129,11 @@ set_fields: end: return status; } + +BT_HIDDEN +void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit, + void *medops_data) +{ + assert(notit); + notit->medium.data = medops_data; +} diff --git a/plugins/ctf/common/notif-iter/notif-iter.h b/plugins/ctf/common/notif-iter/notif-iter.h index 988e54ba..428dd2ec 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.h +++ b/plugins/ctf/common/notif-iter/notif-iter.h @@ -302,6 +302,10 @@ enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_packet_header_context_fields struct bt_ctf_field **packet_header_field, struct bt_ctf_field **packet_context_field); +BT_HIDDEN +void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit, + void *medops_data); + static inline const char *bt_ctf_notif_iter_medium_status_string( enum bt_ctf_notif_iter_medium_status status) diff --git a/plugins/ctf/fs-src/data-stream-file.c b/plugins/ctf/fs-src/data-stream-file.c index 5d255ab7..0ca01a61 100644 --- a/plugins/ctf/fs-src/data-stream-file.c +++ b/plugins/ctf/fs-src/data-stream-file.c @@ -199,10 +199,12 @@ end: return stream; } -static struct bt_ctf_notif_iter_medium_ops medops = { +BT_HIDDEN +struct bt_ctf_notif_iter_medium_ops ctf_fs_ds_file_medops = { .request_bytes = medop_request_bytes, .get_stream = medop_get_stream, }; + static struct ctf_fs_ds_index *ctf_fs_ds_index_create(size_t length) { @@ -521,6 +523,7 @@ error: BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, + struct bt_ctf_notif_iter *notif_iter, struct bt_ctf_stream *stream, const char *path) { int ret; @@ -544,8 +547,8 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create( goto error; } - ds_file->notif_iter = bt_ctf_notif_iter_create( - ctf_fs_trace->metadata->trace, page_size, medops, ds_file); + ds_file->notif_iter = notif_iter; + bt_ctf_notif_iter_set_medops_data(ds_file->notif_iter, ds_file); if (!ds_file->notif_iter) { goto error; } @@ -585,10 +588,6 @@ void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file) ctf_fs_file_destroy(ds_file->file); } - if (ds_file->notif_iter) { - bt_ctf_notif_iter_destroy(ds_file->notif_iter); - } - g_free(ds_file); } diff --git a/plugins/ctf/fs-src/data-stream-file.h b/plugins/ctf/fs-src/data-stream-file.h index 99efd36f..8b2d7247 100644 --- a/plugins/ctf/fs-src/data-stream-file.h +++ b/plugins/ctf/fs-src/data-stream-file.h @@ -94,7 +94,7 @@ struct ctf_fs_ds_file { /* Owned by this */ struct bt_clock_class_priority_map *cc_prio_map; - /* Owned by this */ + /* Weak */ struct bt_ctf_notif_iter *notif_iter; void *mmap_addr; @@ -123,6 +123,7 @@ struct ctf_fs_ds_file { BT_HIDDEN struct ctf_fs_ds_file *ctf_fs_ds_file_create( struct ctf_fs_trace *ctf_fs_trace, + struct bt_ctf_notif_iter *notif_iter, struct bt_ctf_stream *stream, const char *path); BT_HIDDEN @@ -145,4 +146,6 @@ struct ctf_fs_ds_index *ctf_fs_ds_file_build_index( BT_HIDDEN void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index); +extern struct bt_ctf_notif_iter_medium_ops ctf_fs_ds_file_medops; + #endif /* CTF_FS_DS_FILE_H */ diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 07aa8cf3..7d004fe4 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -47,6 +47,7 @@ #include "data-stream-file.h" #include "file.h" #include "../common/metadata/decoder.h" +#include "../common/notif-iter/notif-iter.h" #include "query.h" #define BT_LOG_TAG "PLUGIN-CTF-FS-SRC" @@ -67,6 +68,7 @@ int notif_iter_data_set_current_ds_file(struct ctf_fs_notif_iter_data *notif_ite ctf_fs_ds_file_destroy(notif_iter_data->ds_file); notif_iter_data->ds_file = ctf_fs_ds_file_create( notif_iter_data->ds_file_group->ctf_fs_trace, + notif_iter_data->notif_iter, notif_iter_data->ds_file_group->stream, ds_file_info->path->str); if (!notif_iter_data->ds_file) { @@ -85,6 +87,11 @@ void ctf_fs_notif_iter_data_destroy( } ctf_fs_ds_file_destroy(notif_iter_data->ds_file); + + if (notif_iter_data->notif_iter) { + bt_ctf_notif_iter_destroy(notif_iter_data->notif_iter); + } + g_free(notif_iter_data); } @@ -168,6 +175,16 @@ enum bt_notification_iterator_status ctf_fs_iterator_init( goto error; } + notif_iter_data->notif_iter = bt_ctf_notif_iter_create( + port_data->ds_file_group->ctf_fs_trace->metadata->trace, + bt_common_get_page_size() * 8, + ctf_fs_ds_file_medops, NULL); + if (!notif_iter_data->notif_iter) { + BT_LOGE_STR("Cannot create a CTF notification iterator."); + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + goto error; + } + notif_iter_data->ds_file_group = port_data->ds_file_group; iret = notif_iter_data_set_current_ds_file(notif_iter_data); if (iret) { @@ -636,10 +653,18 @@ int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, bool add_group = false; int ret; size_t i; - struct ctf_fs_ds_file *ds_file; + struct ctf_fs_ds_file *ds_file = NULL; struct ctf_fs_ds_index *index = NULL; + struct bt_ctf_notif_iter *notif_iter = NULL; - ds_file = ctf_fs_ds_file_create(ctf_fs_trace, NULL, path); + notif_iter = bt_ctf_notif_iter_create(ctf_fs_trace->metadata->trace, + bt_common_get_page_size() * 8, ctf_fs_ds_file_medops, NULL); + if (!notif_iter) { + BT_LOGE_STR("Cannot create a CTF notification iterator."); + goto error; + } + + ds_file = ctf_fs_ds_file_create(ctf_fs_trace, notif_iter, NULL, path); if (!ds_file) { goto error; } @@ -757,6 +782,11 @@ end: g_ptr_array_add(ctf_fs_trace->ds_file_groups, ds_file_group); } ctf_fs_ds_file_destroy(ds_file); + + if (notif_iter) { + bt_ctf_notif_iter_destroy(notif_iter); + } + ctf_fs_ds_index_destroy(index); bt_put(packet_header_field); bt_put(packet_context_field); diff --git a/plugins/ctf/fs-src/fs.h b/plugins/ctf/fs-src/fs.h index 13b0d07c..64eab95b 100644 --- a/plugins/ctf/fs-src/fs.h +++ b/plugins/ctf/fs-src/fs.h @@ -123,6 +123,9 @@ struct ctf_fs_notif_iter_data { /* Which file the iterator is _currently_ operating on */ size_t ds_file_info_index; + + /* Owned by this */ + struct bt_ctf_notif_iter *notif_iter; }; BT_HIDDEN -- 2.34.1