From 5b29e7995dce9ec633e05e4272ae562bb2c980c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 9 Nov 2016 14:18:42 -0500 Subject: [PATCH] Merge streams in ctf fs component MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- .../babeltrace/plugin/notification/iterator.h | 4 +- plugins/ctf/common/notif-iter/notif-iter.c | 3 +- plugins/ctf/fs/data-stream.c | 99 +--- plugins/ctf/fs/data-stream.h | 6 - plugins/ctf/fs/fs.c | 455 ++++++++++++++---- plugins/ctf/fs/fs.h | 14 +- plugins/ctf/fs/metadata.c | 26 +- 7 files changed, 423 insertions(+), 184 deletions(-) diff --git a/include/babeltrace/plugin/notification/iterator.h b/include/babeltrace/plugin/notification/iterator.h index db4164fd..06f1c8a5 100644 --- a/include/babeltrace/plugin/notification/iterator.h +++ b/include/babeltrace/plugin/notification/iterator.h @@ -48,8 +48,10 @@ enum bt_notification_iterator_status { BT_NOTIFICATION_ITERATOR_STATUS_INVAL = -1, /** General error. */ BT_NOTIFICATION_ITERATOR_STATUS_ERROR = -2, + /** Out of memory. */ + BT_NOTIFICATION_ITERATOR_STATUS_NOMEM = -3, /** Unsupported iterator feature. */ - BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED = -3, + BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED = -4, }; diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 9c6134f9..56bf9fff 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -579,8 +579,7 @@ enum bt_ctf_notif_iter_status set_current_stream_class(struct bt_ctf_notif_iter BT_PUT(notit->meta.stream_class); - // TODO: get by ID - notit->meta.stream_class = bt_ctf_trace_get_stream_class( + notit->meta.stream_class = bt_ctf_trace_get_stream_class_by_id( notit->meta.trace, stream_id); if (!notit->meta.stream_class) { PERR("Cannot find stream class with ID %" PRIu64 "\n", diff --git a/plugins/ctf/fs/data-stream.c b/plugins/ctf/fs/data-stream.c index 6b500519..36625097 100644 --- a/plugins/ctf/fs/data-stream.c +++ b/plugins/ctf/fs/data-stream.c @@ -35,35 +35,20 @@ #include "metadata.h" #include "../common/notif-iter/notif-iter.h" #include +#include "data-stream.h" #define PRINT_ERR_STREAM ctf_fs->error_fp #define PRINT_PREFIX "ctf-fs-data-stream" #include "print.h" -BT_HIDDEN -void ctf_fs_stream_destroy(struct ctf_fs_stream *stream) -{ - if (stream->file) { - ctf_fs_file_destroy(stream->file); - } - - if (stream->stream) { - BT_PUT(stream->stream); - } - - if (stream->notif_iter) { - bt_ctf_notif_iter_destroy(stream->notif_iter); - } - - g_free(stream); -} - -static size_t remaining_mmap_bytes(struct ctf_fs_stream *stream) +static +size_t remaining_mmap_bytes(struct ctf_fs_stream *stream) { return stream->mmap_valid_len - stream->request_offset; } -static int stream_munmap(struct ctf_fs_stream *stream) +static +int stream_munmap(struct ctf_fs_stream *stream) { int ret = 0; struct ctf_fs_component *ctf_fs = stream->file->ctf_fs; @@ -80,7 +65,8 @@ end: return ret; } -static int mmap_next(struct ctf_fs_stream *stream) +static +int mmap_next(struct ctf_fs_stream *stream) { int ret = 0; struct ctf_fs_component *ctf_fs = stream->file->ctf_fs; @@ -120,7 +106,8 @@ end: return ret; } -static enum bt_ctf_notif_iter_medium_status medop_request_bytes( +static +enum bt_ctf_notif_iter_medium_status medop_request_bytes( size_t request_sz, uint8_t **buffer_addr, size_t *buffer_sz, void *data) { @@ -171,7 +158,8 @@ end: return status; } -static struct bt_ctf_stream *medop_get_stream( +static +struct bt_ctf_stream *medop_get_stream( struct bt_ctf_stream_class *stream_class, void *data) { struct ctf_fs_stream *fs_stream = data; @@ -208,11 +196,12 @@ struct ctf_fs_stream *ctf_fs_stream_create( } stream->file = file; - stream->notif_iter = bt_ctf_notif_iter_create(ctf_fs->metadata.trace, + stream->notif_iter = bt_ctf_notif_iter_create(ctf_fs->metadata->trace, ctf_fs->page_size, medops, stream, ctf_fs->error_fp); if (!stream->notif_iter) { goto error; } + stream->mmap_max_len = ctf_fs->page_size * 2048; goto end; error: @@ -224,60 +213,24 @@ end: return stream; } -enum bt_notification_iterator_status ctf_fs_data_stream_get_next_notification( - struct ctf_fs_component *ctf_fs, - struct bt_notification **notification, - size_t stream_id) +BT_HIDDEN +void ctf_fs_stream_destroy(struct ctf_fs_stream *stream) { - enum bt_ctf_notif_iter_status status; - enum bt_notification_iterator_status ret; - /* FIXME, only iterating on one stream for the moment. */ - struct ctf_fs_stream *stream = g_ptr_array_index(ctf_fs->streams, - stream_id); - - if (stream->end_reached) { - status = BT_CTF_NOTIF_ITER_STATUS_EOF; - goto end; + if (!stream) { + return; } - status = bt_ctf_notif_iter_get_next_notification(stream->notif_iter, - notification); - if (status != BT_CTF_NOTIF_ITER_STATUS_OK && - status != BT_CTF_NOTIF_ITER_STATUS_EOF) { - goto end; + if (stream->file) { + ctf_fs_file_destroy(stream->file); } - /* Should be handled in bt_ctf_notif_iter_get_next_notification. */ - if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) { - *notification = bt_notification_stream_end_create( - stream->stream); - if (!*notification) { - status = BT_CTF_NOTIF_ITER_STATUS_ERROR; - } - status = BT_CTF_NOTIF_ITER_STATUS_OK; - stream->end_reached = true; + if (stream->stream) { + BT_PUT(stream->stream); } -end: - switch (status) { - case BT_CTF_NOTIF_ITER_STATUS_EOF: - ret = BT_NOTIFICATION_ITERATOR_STATUS_END; - break; - case BT_CTF_NOTIF_ITER_STATUS_OK: - ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; - break; - case BT_CTF_NOTIF_ITER_STATUS_AGAIN: - /* - * Should not make it this far as this is medium-specific; - * there is nothing for the user to do and it should have been - * handled upstream. - */ - assert(0); - case BT_CTF_NOTIF_ITER_STATUS_INVAL: - /* No argument provided by the user, so don't return INVAL. */ - case BT_CTF_NOTIF_ITER_STATUS_ERROR: - default: - ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; - break; + + if (stream->notif_iter) { + bt_ctf_notif_iter_destroy(stream->notif_iter); } - return ret; + + g_free(stream); } diff --git a/plugins/ctf/fs/data-stream.h b/plugins/ctf/fs/data-stream.h index c567c13e..6e7d0e72 100644 --- a/plugins/ctf/fs/data-stream.h +++ b/plugins/ctf/fs/data-stream.h @@ -40,10 +40,4 @@ void ctf_fs_stream_destroy(struct ctf_fs_stream *stream); BT_HIDDEN int ctf_fs_data_stream_open_streams(struct ctf_fs_component *ctf_fs); -BT_HIDDEN -enum bt_notification_iterator_status ctf_fs_data_stream_get_next_notification( - struct ctf_fs_component *ctf_fs, - struct bt_notification **notification, - size_t stream_id); - #endif /* CTF_FS_DATA_STREAM_H */ diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index bf834f3f..495540b4 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -27,7 +27,12 @@ */ #include +#include #include +#include +#include +#include +#include #include #include #include @@ -46,137 +51,332 @@ static struct bt_notification *ctf_fs_iterator_get( struct bt_notification_iterator *iterator) { - struct bt_notification *notification = NULL; - struct ctf_fs_component *ctf_fs; - struct bt_component *component = bt_notification_iterator_get_component( - iterator); - - if (!component) { - goto end; - } + struct ctf_fs_iterator *ctf_it = + bt_notification_iterator_get_private_data(iterator); - ctf_fs = bt_component_get_private_data(component); - if (!ctf_fs) { - goto end; - } - - notification = bt_get(ctf_fs->current_notification); -end: - BT_PUT(component); - return notification; + return bt_get(ctf_it->current_notification); } static -enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_notification_iterator *iterator) +enum bt_notification_iterator_status ctf_fs_iterator_get_next_notification( + struct ctf_fs_iterator *it, + struct ctf_fs_stream *stream, + struct bt_notification **notification) { + enum bt_ctf_notif_iter_status status; enum bt_notification_iterator_status ret; - struct bt_notification *notification = NULL; - struct ctf_fs_component *ctf_fs; - struct bt_component *component = bt_notification_iterator_get_component( - iterator); - if (!component) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + if (stream->end_reached) { + status = BT_CTF_NOTIF_ITER_STATUS_EOF; goto end; } - ctf_fs = bt_component_get_private_data(component); - assert(ctf_fs); - - ret = ctf_fs_data_stream_get_next_notification(ctf_fs, ¬ification, 0); - if (ret || !notification) { + status = bt_ctf_notif_iter_get_next_notification(stream->notif_iter, + notification); + if (status != BT_CTF_NOTIF_ITER_STATUS_OK && + status != BT_CTF_NOTIF_ITER_STATUS_EOF) { goto end; } - bt_put(ctf_fs->current_notification); - ctf_fs->current_notification = notification; + /* Should be handled in bt_ctf_notif_iter_get_next_notification. */ + if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) { + *notification = bt_notification_stream_end_create( + stream->stream); + if (!*notification) { + status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + } + status = BT_CTF_NOTIF_ITER_STATUS_OK; + stream->end_reached = true; + } end: - BT_PUT(component); + switch (status) { + case BT_CTF_NOTIF_ITER_STATUS_EOF: + ret = BT_NOTIFICATION_ITERATOR_STATUS_END; + break; + case BT_CTF_NOTIF_ITER_STATUS_OK: + ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; + break; + case BT_CTF_NOTIF_ITER_STATUS_AGAIN: + /* + * Should not make it this far as this is medium-specific; + * there is nothing for the user to do and it should have been + * handled upstream. + */ + assert(0); + case BT_CTF_NOTIF_ITER_STATUS_INVAL: + /* No argument provided by the user, so don't return INVAL. */ + case BT_CTF_NOTIF_ITER_STATUS_ERROR: + default: + ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + break; + } return ret; } +/* + * Remove me. This is a temporary work-around due to our inhability to use + * libbabeltrace-ctf from libbabeltrace-plugin. + */ static -void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it) +struct bt_ctf_stream *internal_bt_notification_get_stream( + struct bt_notification *notification) { - g_free(ctf_it); + struct bt_ctf_stream *stream = NULL; + + assert(notification); + switch (bt_notification_get_type(notification)) { + case BT_NOTIFICATION_TYPE_EVENT: + { + struct bt_ctf_event *event; + + event = bt_notification_event_get_event(notification); + stream = bt_ctf_event_get_stream(event); + bt_put(event); + break; + } + case BT_NOTIFICATION_TYPE_PACKET_START: + { + struct bt_ctf_packet *packet; + + packet = bt_notification_packet_start_get_packet(notification); + stream = bt_ctf_packet_get_stream(packet); + bt_put(packet); + break; + } + case BT_NOTIFICATION_TYPE_PACKET_END: + { + struct bt_ctf_packet *packet; + + packet = bt_notification_packet_end_get_packet(notification); + stream = bt_ctf_packet_get_stream(packet); + bt_put(packet); + break; + } + case BT_NOTIFICATION_TYPE_STREAM_END: + stream = bt_notification_stream_end_get_stream(notification); + break; + default: + goto end; + } +end: + return stream; } static -void ctf_fs_iterator_destroy(struct bt_notification_iterator *it) +enum bt_notification_iterator_status populate_heap(struct ctf_fs_iterator *it) { - void *data = bt_notification_iterator_get_private_data(it); + size_t i, pending_streams_count = it->pending_streams->len; + enum bt_notification_iterator_status ret = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + + /* Insert one stream-associated notification for each stream. */ + for (i = 0; i < pending_streams_count; i++) { + struct bt_notification *notification; + struct ctf_fs_stream *fs_stream; + struct bt_ctf_stream *stream; + size_t pending_stream_index = pending_streams_count - 1 - i; + + fs_stream = g_ptr_array_index(it->pending_streams, + pending_stream_index); + + do { + int heap_ret; + + ret = ctf_fs_iterator_get_next_notification( + it, fs_stream, ¬ification); + if (ret && ret != BT_NOTIFICATION_ITERATOR_STATUS_END) { + printf_debug("Failed to populate heap at stream %zu\n", + pending_stream_index); + goto end; + } + + stream = internal_bt_notification_get_stream( + notification); + if (stream) { + gboolean inserted; + + /* + * Associate pending ctf_fs_stream to + * bt_ctf_stream. Ownership of stream + * is passed to the stream ht. + */ + inserted = g_hash_table_insert(it->stream_ht, + stream, fs_stream); + if (!inserted) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + printf_debug("Failed to associate fs stream to ctf stream\n"); + goto end; + } + } + + heap_ret = bt_notification_heap_insert( + it->pending_notifications, + notification); + bt_put(notification); + if (heap_ret) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + printf_debug("Failed to insert notification in heap\n"); + goto end; + } + } while (!stream && ret != BT_NOTIFICATION_ITERATOR_STATUS_END); + /* + * Set NULL so the destruction callback registered with the + * array is not invoked on the stream (its ownership was + * transferred to the streams hashtable). + */ + g_ptr_array_index(it->pending_streams, + pending_stream_index) = NULL; + g_ptr_array_remove_index(it->pending_streams, + pending_stream_index); + } - ctf_fs_iterator_destroy_data(data); + g_ptr_array_free(it->pending_streams, TRUE); + it->pending_streams = NULL; +end: + return ret; } static -enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, - struct bt_notification_iterator *it) +enum bt_notification_iterator_status ctf_fs_iterator_next( + struct bt_notification_iterator *iterator) { - struct ctf_fs_iterator *ctf_it; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - assert(source && it); - ctf_it = g_new0(struct ctf_fs_iterator, 1); - if (!ctf_it) { - ret = BT_COMPONENT_STATUS_NOMEM; + int heap_ret; + struct bt_ctf_stream *stream; + struct ctf_fs_stream *fs_stream; + struct bt_notification *notification; + struct bt_notification *next_stream_notification; + enum bt_notification_iterator_status ret = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct ctf_fs_iterator *ctf_it = + bt_notification_iterator_get_private_data(iterator); + + notification = bt_notification_heap_pop(ctf_it->pending_notifications); + if (!notification && !ctf_it->pending_streams) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_END; goto end; } - ret = bt_notification_iterator_set_get_cb(it, ctf_fs_iterator_get); - if (ret) { - goto error; + if (!notification && ctf_it->pending_streams) { + /* + * Insert at one notification per stream in the heap and pop + * one. + */ + ret = populate_heap(ctf_it); + if (ret) { + goto end; + } + + notification = bt_notification_heap_pop( + ctf_it->pending_notifications); + if (!notification) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_END; + goto end; + } } - ret = bt_notification_iterator_set_next_cb(it, ctf_fs_iterator_next); - if (ret) { - goto error; + /* notification is set from here. */ + + stream = internal_bt_notification_get_stream(notification); + if (!stream) { + /* + * The current notification is not associated to a particular + * stream, there is no need to insert a new notification from + * a stream in the heap. + */ + goto end; } - ret = bt_notification_iterator_set_destroy_cb(it, - ctf_fs_iterator_destroy); - if (ret) { - goto error; + fs_stream = g_hash_table_lookup(ctf_it->stream_ht, stream); + if (!fs_stream) { + /* We have reached this stream's end. */ + goto end; } - ret = bt_notification_iterator_set_private_data(it, ctf_it); - if (ret) { - goto error; + ret = ctf_fs_iterator_get_next_notification(ctf_it, fs_stream, + &next_stream_notification); + if ((ret && ret != BT_NOTIFICATION_ITERATOR_STATUS_END)) { + heap_ret = bt_notification_heap_insert( + ctf_it->pending_notifications, notification); + + assert(!next_stream_notification); + if (heap_ret) { + /* + * We're dropping the most recent notification, but at + * this point, something is seriously wrong... + */ + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + } + BT_PUT(notification); + goto end; + } + + if (ret == BT_NOTIFICATION_ITERATOR_STATUS_END) { + gboolean success; + + /* Remove stream. */ + success = g_hash_table_remove(ctf_it->stream_ht, stream); + assert(success); + ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; + } else { + heap_ret = bt_notification_heap_insert(ctf_it->pending_notifications, + next_stream_notification); + BT_PUT(next_stream_notification); + if (heap_ret) { + /* + * We're dropping the most recent notification... + */ + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + } } + + /* + * Ensure that the stream is removed from both pending_streams and + * the streams hashtable on reception of the "end of stream" + * notification. + */ end: - return ret; -error: - (void) bt_notification_iterator_set_private_data(it, NULL); - ctf_fs_iterator_destroy_data(ctf_it); + BT_MOVE(ctf_it->current_notification, notification); return ret; } static -void ctf_fs_destroy_data(struct ctf_fs_component *component) +void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it) { - if (component->trace_path) { - g_string_free(component->trace_path, TRUE); + bt_put(ctf_it->current_notification); + bt_put(ctf_it->pending_notifications); + if (ctf_it->pending_streams) { + g_ptr_array_free(ctf_it->pending_streams, TRUE); } - - ctf_fs_metadata_fini(&component->metadata); - BT_PUT(component->current_notification); - if (component->streams) { - g_ptr_array_free(component->streams, TRUE); + if (ctf_it->stream_ht) { + g_hash_table_destroy(ctf_it->stream_ht); } - g_free(component); + g_free(ctf_it); } static -void ctf_fs_destroy(struct bt_component *component) +void ctf_fs_iterator_destroy(struct bt_notification_iterator *it) { - void *data = bt_component_get_private_data(component); + void *data = bt_notification_iterator_get_private_data(it); - ctf_fs_destroy_data(data); + ctf_fs_iterator_destroy_data(data); } static -int open_trace_streams(struct ctf_fs_component *ctf_fs) +bool compare_notifications(struct bt_notification *a, struct bt_notification *b, + void *unused) +{ + return a < b; +} + +static +void stream_destroy(void *stream) +{ + ctf_fs_stream_destroy((struct ctf_fs_stream *) stream); +} + +static +int open_trace_streams(struct ctf_fs_component *ctf_fs, + struct ctf_fs_iterator *ctf_it) { int ret = 0; const char *name; @@ -236,7 +436,7 @@ int open_trace_streams(struct ctf_fs_component *ctf_fs) goto error; } - g_ptr_array_add(ctf_fs->streams, stream); + g_ptr_array_add(ctf_it->pending_streams, stream); } goto end; @@ -254,9 +454,95 @@ end: } static -void stream_destroy(void *stream) +enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, + struct bt_notification_iterator *it) { - ctf_fs_stream_destroy((struct ctf_fs_stream *) stream); + struct ctf_fs_iterator *ctf_it; + struct ctf_fs_component *ctf_fs; + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + assert(source && it); + + ctf_fs = bt_component_get_private_data(source); + if (!ctf_fs) { + ret = BT_COMPONENT_STATUS_INVALID; + goto end; + } + + ctf_it = g_new0(struct ctf_fs_iterator, 1); + if (!ctf_it) { + ret = BT_COMPONENT_STATUS_NOMEM; + goto end; + } + + ctf_it->stream_ht = g_hash_table_new_full(g_direct_hash, + g_direct_equal, bt_put, stream_destroy); + if (!ctf_it->stream_ht) { + goto error; + } + ctf_it->pending_streams = g_ptr_array_new_with_free_func( + stream_destroy); + if (!ctf_it->pending_streams) { + goto error; + } + ctf_it->pending_notifications = bt_notification_heap_create( + compare_notifications, NULL); + if (!ctf_it->pending_notifications) { + goto error; + } + + ret = open_trace_streams(ctf_fs, ctf_it); + if (ret) { + goto error; + } + + ret = bt_notification_iterator_set_get_cb(it, ctf_fs_iterator_get); + if (ret) { + goto error; + } + + ret = bt_notification_iterator_set_next_cb(it, ctf_fs_iterator_next); + if (ret) { + goto error; + } + + ret = bt_notification_iterator_set_destroy_cb(it, + ctf_fs_iterator_destroy); + if (ret) { + goto error; + } + + ret = bt_notification_iterator_set_private_data(it, ctf_it); + if (ret) { + goto error; + } +end: + return ret; +error: + (void) bt_notification_iterator_set_private_data(it, NULL); + ctf_fs_iterator_destroy_data(ctf_it); + goto end; +} + +static +void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs) +{ + if (ctf_fs->trace_path) { + g_string_free(ctf_fs->trace_path, TRUE); + } + if (ctf_fs->metadata) { + ctf_fs_metadata_fini(ctf_fs->metadata); + g_free(ctf_fs->metadata); + } + g_free(ctf_fs); +} + +static +void ctf_fs_destroy(struct bt_component *component) +{ + void *data = bt_component_get_private_data(component); + + ctf_fs_destroy_data(data); } static @@ -287,18 +573,15 @@ struct ctf_fs_component *ctf_fs_create(struct bt_value *params) if (!ctf_fs->trace_path) { goto error; } - - ctf_fs->streams = g_ptr_array_new_with_free_func(stream_destroy); ctf_fs->error_fp = stderr; ctf_fs->page_size = (size_t) getpagesize(); // FIXME: check error. - ctf_fs_metadata_set_trace(ctf_fs); - - ret = open_trace_streams(ctf_fs); - if (ret) { + ctf_fs->metadata = g_new0(struct ctf_fs_metadata, 1); + if (!ctf_fs->metadata) { goto error; } + ctf_fs_metadata_set_trace(ctf_fs); goto end; error: diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index cf574c8b..30665a33 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -78,6 +78,16 @@ struct ctf_fs_stream { struct ctf_fs_iterator { struct bt_notification_heap *pending_notifications; + struct bt_notification *current_notification; + /* + * struct ctf_fs_data_stream* which have not yet been associated to a + * bt_ctf_stream. The association is performed on the first packet + * read by the stream (since, at that point, we have read a packet + * header). + */ + GPtrArray *pending_streams; + /* bt_ctf_stream -> ctf_fs_stream */ + GHashTable *stream_ht; }; struct ctf_fs_component_options { @@ -88,10 +98,8 @@ struct ctf_fs_component { GString *trace_path; FILE *error_fp; size_t page_size; - struct bt_notification *current_notification; - struct ctf_fs_metadata metadata; struct ctf_fs_component_options options; - GPtrArray *streams; /* struct ctf_fs_data_stream * */ + struct ctf_fs_metadata *metadata; }; BT_HIDDEN diff --git a/plugins/ctf/fs/metadata.c b/plugins/ctf/fs/metadata.c index 38283680..03309dd3 100644 --- a/plugins/ctf/fs/metadata.c +++ b/plugins/ctf/fs/metadata.c @@ -98,10 +98,10 @@ bool is_packetized(struct ctf_fs_component *ctf_fs, struct ctf_fs_file *file) if (magic == TSDL_MAGIC) { ret = 1; - ctf_fs->metadata.bo = BYTE_ORDER; + ctf_fs->metadata->bo = BYTE_ORDER; } else if (magic == GUINT32_SWAP_LE_BE(TSDL_MAGIC)) { ret = 1; - ctf_fs->metadata.bo = BYTE_ORDER == BIG_ENDIAN ? + ctf_fs->metadata->bo = BYTE_ORDER == BIG_ENDIAN ? LITTLE_ENDIAN : BIG_ENDIAN; } @@ -133,7 +133,7 @@ int decode_packet(struct ctf_fs_component *ctf_fs, FILE *in_fp, FILE *out_fp) goto error; } - if (ctf_fs->metadata.bo != BYTE_ORDER) { + if (ctf_fs->metadata->bo != BYTE_ORDER) { header.magic = GUINT32_SWAP_LE_BE(header.magic); header.checksum = GUINT32_SWAP_LE_BE(header.checksum); header.content_size = GUINT32_SWAP_LE_BE(header.content_size); @@ -162,10 +162,10 @@ int decode_packet(struct ctf_fs_component *ctf_fs, FILE *in_fp, FILE *out_fp) } /* Set expected trace UUID if not set; otherwise validate it */ - if (!ctf_fs->metadata.is_uuid_set) { - memcpy(ctf_fs->metadata.uuid, header.uuid, sizeof(header.uuid)); - ctf_fs->metadata.is_uuid_set = true; - } else if (bt_uuid_compare(header.uuid, ctf_fs->metadata.uuid)) { + if (!ctf_fs->metadata->is_uuid_set) { + memcpy(ctf_fs->metadata->uuid, header.uuid, sizeof(header.uuid)); + ctf_fs->metadata->is_uuid_set = true; + } else if (bt_uuid_compare(header.uuid, ctf_fs->metadata->uuid)) { PERR("Metadata UUID mismatch between packets of the same file\n"); goto error; } @@ -305,7 +305,7 @@ void ctf_fs_metadata_set_trace(struct ctf_fs_component *ctf_fs) } cbuf = (char *) buf; - ctf_fs->metadata.text = (char *) cbuf; + ctf_fs->metadata->text = (char *) cbuf; /* Convert the real file pointer to a memory file pointer */ ret = fclose(file->fp); @@ -363,7 +363,7 @@ void ctf_fs_metadata_set_trace(struct ctf_fs_component *ctf_fs) } ret = ctf_visitor_generate_ir(ctf_fs->error_fp, &scanner->ast->root, - &ctf_fs->metadata.trace); + &ctf_fs->metadata->trace); if (ret) { PERR("Cannot create trace object from metadata AST\n"); goto error; @@ -372,9 +372,9 @@ void ctf_fs_metadata_set_trace(struct ctf_fs_component *ctf_fs) goto end; error: - if (ctf_fs->metadata.text) { - free(ctf_fs->metadata.text); - ctf_fs->metadata.text = NULL; + if (ctf_fs->metadata->text) { + free(ctf_fs->metadata->text); + ctf_fs->metadata->text = NULL; } end: @@ -389,7 +389,7 @@ end: int ctf_fs_metadata_init(struct ctf_fs_metadata *metadata) { - /* Nothing to initialize for the moment */ + /* Nothing to initialize for the moment. */ return 0; } -- 2.34.1