X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fctf%2Fcommon%2Fnotif-iter%2Fnotif-iter.c;h=8bb79db8f3ba64980b5081fcd0066b9280dfa9f0;hb=9d408fcae74602e3591f66623ceb85f482d948ed;hp=33ac24953ea56d89b0cd7f45c0e3f96677dd5b41;hpb=1974687e6b7a08d8383a4a5c75265d0ed3b8c5c9;p=babeltrace.git diff --git a/plugins/ctf/common/notif-iter/notif-iter.c b/plugins/ctf/common/notif-iter/notif-iter.c index 33ac2495..8bb79db8 100644 --- a/plugins/ctf/common/notif-iter/notif-iter.c +++ b/plugins/ctf/common/notif-iter/notif-iter.c @@ -33,21 +33,9 @@ #include #include #include -#include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -232,6 +220,12 @@ struct bt_ctf_notif_iter { /* Current content size (bits) (-1 if unknown) */ int64_t cur_content_size; + /* + * Offset, in the underlying media, of the current packet's start + * (-1 if unknown). + */ + off_t cur_packet_offset; + /* bt_ctf_clock_class to uint64_t. */ GHashTable *clock_states; @@ -480,7 +474,7 @@ enum bt_ctf_notif_iter_status request_medium_bytes( /* Restart at the beginning of the new medium buffer */ notit->buf.at = 0; - notit->buf.last_eh_at = -1ULL; + notit->buf.last_eh_at = SIZE_MAX; /* New medium buffer size */ notit->buf.sz = buffer_sz; @@ -1173,7 +1167,7 @@ enum bt_ctf_notif_iter_status set_current_packet_content_sizes( enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK; struct bt_ctf_field *packet_size_field = NULL; struct bt_ctf_field *content_size_field = NULL; - uint64_t content_size = -1, packet_size = -1; + uint64_t content_size = -1ULL, packet_size = -1ULL; if (!notit->dscopes.stream_packet_context) { goto end; @@ -1224,7 +1218,16 @@ enum bt_ctf_notif_iter_status set_current_packet_content_sizes( goto end; } - notit->cur_packet_size = packet_size; + if (packet_size != -1ULL) { + notit->cur_packet_size = packet_size; + } else { + /* + * Use the content size as packet size indicator if the + * packet size field is missing. This means there is no + * padding in this stream. + */ + notit->cur_packet_size = content_size; + } notit->cur_content_size = content_size; BT_LOGV("Set current packet and content sizes: " "notit-addr=%p, packet-size=%" PRIu64 ", content-size=%" PRIu64, @@ -1789,11 +1792,12 @@ void bt_ctf_notif_iter_reset(struct bt_ctf_notif_iter *notit) notit->buf.addr = NULL; notit->buf.sz = 0; notit->buf.at = 0; - notit->buf.last_eh_at = -1ULL; + notit->buf.last_eh_at = SIZE_MAX; notit->buf.packet_offset = 0; notit->state = STATE_INIT; notit->cur_content_size = -1; notit->cur_packet_size = -1; + notit->cur_packet_offset = -1; } static @@ -1807,8 +1811,12 @@ int bt_ctf_notif_iter_switch_packet(struct bt_ctf_notif_iter *notit) * iterator refer to the same stream class (the first one). */ assert(notit); - BT_LOGV("Switching packet: notit-addr=%p, cur=%zu", - notit, notit->buf.at); + if (notit->cur_packet_size != -1) { + notit->cur_packet_offset += notit->cur_packet_size; + } + BT_LOGV("Switching packet: notit-addr=%p, cur=%zu, " + "packet-offset=%" PRId64, notit, notit->buf.at, + notit->cur_packet_offset); stack_clear(notit->stack); BT_PUT(notit->meta.event_class); BT_PUT(notit->packet); @@ -3128,6 +3136,7 @@ struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace, "data=%p, notit-addr=%p", trace, bt_ctf_trace_get_name(trace), max_request_sz, data, notit); + notit->cur_packet_offset = 0; end: return notit; @@ -3262,6 +3271,7 @@ 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) { + int ret; enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK; assert(notit); @@ -3324,6 +3334,11 @@ set_fields: *packet_context_field = bt_get(notit->dscopes.stream_packet_context); } + ret = set_current_packet_content_sizes(notit); + if (ret) { + status = BT_CTF_NOTIF_ITER_STATUS_ERROR; + goto end; + } end: return status; } @@ -3335,3 +3350,57 @@ void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit, assert(notit); notit->medium.data = medops_data; } + +BT_HIDDEN +enum bt_ctf_notif_iter_status bt_ctf_notif_iter_seek( + struct bt_ctf_notif_iter *notit, off_t offset) +{ + enum bt_ctf_notif_iter_status ret = BT_CTF_NOTIF_ITER_STATUS_OK; + enum bt_ctf_notif_iter_medium_status medium_status; + + assert(notit); + if (offset < 0) { + BT_LOGE("Cannot seek to negative offset: offset=%jd", offset); + ret = BT_CTF_NOTIF_ITER_STATUS_INVAL; + goto end; + } + + if (!notit->medium.medops.seek) { + ret = BT_CTF_NOTIF_ITER_STATUS_UNSUPPORTED; + BT_LOGD("Aborting seek as the iterator's underlying media does not implement seek support."); + goto end; + } + + medium_status = notit->medium.medops.seek( + BT_CTF_NOTIF_ITER_SEEK_WHENCE_SET, offset, + notit->medium.data); + if (medium_status != BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK) { + if (medium_status == BT_CTF_NOTIF_ITER_MEDIUM_STATUS_EOF) { + ret = BT_CTF_NOTIF_ITER_STATUS_EOF; + } else { + ret = BT_CTF_NOTIF_ITER_STATUS_ERROR; + goto end; + } + } + + bt_ctf_notif_iter_reset(notit); + notit->cur_packet_offset = offset; +end: + return ret; +} + +BT_HIDDEN +off_t bt_ctf_notif_iter_get_current_packet_offset( + struct bt_ctf_notif_iter *notit) +{ + assert(notit); + return notit->cur_packet_offset; +} + +BT_HIDDEN +off_t bt_ctf_notif_iter_get_current_packet_size( + struct bt_ctf_notif_iter *notit) +{ + assert(notit); + return notit->cur_packet_size; +}