The last event in a packet is seen with the timestamp of the beginning
of the next packet due to an incorrect handling of ctf_move_pos() : the
"ctf_move_pos_slow" that switches between packets needs to be called at
the next event, rather than at the end of the last event of the packet.
When the position was getting to the end of the payload of the last
event, it was immediately changing packet, which changed all packet
context information, including the current timestamp.
This is fixed by explicitely calling the ctf_move_pos_slow() on packet
boundaries at the beginning of event read rather than at each
ctf_move_pos call.
We also fix handling of empty trace packets here: when an empty packet
is detected, we need to move on to the next packet immediately within
ctf_move_pos_slow() rather than let the caller think there is some event
data in the empty packet.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
uint64_t id = 0;
int ret;
uint64_t id = 0;
int ret;
+ ctf_pos_get_event(pos);
+
if (pos->offset == EOF)
return EOF;
if (pos->offset == EOF)
return EOF;
+ assert(pos->offset < pos->content_size);
/* Read event header */
if (stream->stream_event_header) {
/* Read event header */
if (stream->stream_event_header) {
assert(off >= 0);
pos->offset = 0;
} else {
assert(off >= 0);
pos->offset = 0;
} else {
switch (whence) {
case SEEK_CUR:
switch (whence) {
case SEEK_CUR:
+ if (pos->offset == EOF)
+ return;
/* The reader will expect us to skip padding */
assert(pos->offset + offset == pos->content_size);
++pos->cur_index;
/* The reader will expect us to skip padding */
assert(pos->offset + offset == pos->content_size);
++pos->cur_index;
file_stream->parent.timestamp = index->timestamp_begin;
pos->content_size = index->content_size;
pos->packet_size = index->packet_size;
file_stream->parent.timestamp = index->timestamp_begin;
pos->content_size = index->content_size;
pos->packet_size = index->packet_size;
- if (index->data_offset <= index->content_size) {
+ if (index->data_offset < index->content_size) {
pos->offset = 0; /* will read headers */
pos->offset = 0; /* will read headers */
+ } else if (index->data_offset == index->content_size) {
+ /* empty packet */
+ pos->offset = index->data_offset;
+ offset = 0;
+ goto read_next_packet;
} else {
pos->offset = EOF;
return;
} else {
pos->offset = EOF;
return;
return;
if (pos->fd >= 0) {
return;
if (pos->fd >= 0) {
- if (((pos->prot == PROT_READ)
- && (pos->offset + bit_offset >= pos->content_size))
- || ((pos->prot == PROT_WRITE)
- && (pos->offset + bit_offset >= pos->packet_size))) {
+ /*
+ * PROT_READ ctf_move_pos_slow is called from within
+ * ctf_pos_get_event so end of packet does not change
+ * the packet context on for the last event of the
+ * packet.
+ */
+ if ((pos->prot == PROT_WRITE)
+ && (pos->offset + bit_offset >= pos->packet_size)) {
printf_debug("ctf_move_pos_slow (before call): %zd\n",
pos->offset);
ctf_move_pos_slow(pos, bit_offset, SEEK_CUR);
printf_debug("ctf_move_pos_slow (before call): %zd\n",
pos->offset);
ctf_move_pos_slow(pos, bit_offset, SEEK_CUR);
+/*
+ * Update the stream position for to the current event. This moves to
+ * the next packet if we are located at the end of the current packet.
+ */
+static inline
+void ctf_pos_get_event(struct ctf_stream_pos *pos)
+{
+ assert(pos->offset <= pos->content_size);
+ if (pos->offset == pos->content_size) {
+ printf_debug("ctf_move_pos_slow (before call): %zd\n",
+ pos->offset);
+ ctf_move_pos_slow(pos, 0, SEEK_CUR);
+ printf_debug("ctf_move_pos_slow (after call): %zd\n",
+ pos->offset);
+ }
+}
+
#endif /* _BABELTRACE_CTF_TYPES_H */
#endif /* _BABELTRACE_CTF_TYPES_H */