creation of the new iterator. In the future, creation of multiples iterators
will be allowed.
+The bt_ctf_iter_read_event_flags() function has the same behaviour as
+bt_ctf_iter_read_event() but takes an additionnal flag pointer. This flag is
+used to inform the user if a special condition occured while reading the event.
+As of now, only the BT_ITER_LOST_EVENTS is handled, it informs the user that
+some events were discarded by the tracer. To get the number of events lost
+immediately prior to the last event read, the user can call the
+bt_ctf_get_lost_events_count() function.
+
Finally, we have the bt_ctf_get_iter() function which returns a struct bt_iter
with which the iterator can be moved using one of these functions:
bt_iter_next(), moves the iterator to the next event
break;
}
case SEEK_SET:
+ packet_index = &g_array_index(pos->packet_cycles_index,
+ struct packet_index, index);
+ pos->last_events_discarded = packet_index->events_discarded;
pos->cur_index = index;
file_stream->parent.prev_real_timestamp = 0;
file_stream->parent.prev_real_timestamp_end = 0;
return &iter->parent;
}
-struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
+struct bt_ctf_event *bt_ctf_iter_read_event_flags(struct bt_ctf_iter *iter,
+ int *flags)
{
struct ctf_file_stream *file_stream;
struct bt_ctf_event *ret;
struct ctf_stream_definition *stream;
+ struct packet_index *packet_index;
/*
* We do not want to fail for any other reason than end of
ret->parent = g_ptr_array_index(stream->events_by_id,
stream->event_id);
+ if (flags)
+ *flags = 0;
+ if (!file_stream->pos.packet_cycles_index)
+ packet_index = NULL;
+ else
+ packet_index = &g_array_index(file_stream->pos.packet_cycles_index,
+ struct packet_index, file_stream->pos.cur_index);
+ iter->events_lost = 0;
+ if (packet_index && packet_index->events_discarded >
+ file_stream->pos.last_events_discarded) {
+ if (flags)
+ *flags |= BT_ITER_FLAG_LOST_EVENTS;
+ iter->events_lost += packet_index->events_discarded -
+ file_stream->pos.last_events_discarded;
+ file_stream->pos.last_events_discarded =
+ packet_index->events_discarded;
+ }
+
if (ret->parent->stream->stream_id > iter->callbacks->len)
goto end;
stop:
return NULL;
}
+
+struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
+{
+ return bt_ctf_iter_read_event_flags(iter, NULL);
+}
+
+uint64_t bt_ctf_get_lost_events_count(struct bt_ctf_iter *iter)
+{
+ if (!iter)
+ return -1ULL;
+
+ return iter->events_lost;
+}
* bt_iter.
*/
GPtrArray *dep_gc;
+ uint64_t events_lost;
};
#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
}
#endif
+/*
+ * bt_ctf_iter_read_event_flags: Read the iterator's current event data.
+ *
+ * @iter: trace collection iterator (input). Should NOT be NULL.
+ * @flags: pointer passed by the user, in which the trace reader populates
+ * flags on special condition (BT_ITER_FLAG_*).
+ *
+ * Return current event on success, NULL on end of trace.
+ */
+struct bt_ctf_event *bt_ctf_iter_read_event_flags(struct bt_ctf_iter *iter,
+ int *flags);
+
+/*
+ * bt_ctf_get_lost_events_count: returns the number of events discarded
+ * immediately prior to the last event read
+ *
+ * @iter: trace collection iterator (input). Should NOT be NULL.
+ *
+ * Return the number of lost events or -1ULL on error.
+ */
+uint64_t bt_ctf_get_lost_events_count(struct bt_ctf_iter *iter);
+
#endif /* _BABELTRACE_CTF_ITERATOR_H */
ssize_t offset; /* offset from base, in bits. EOF for end of file. */
ssize_t last_offset; /* offset before the last read_event */
size_t cur_index; /* current index in packet index */
+ uint64_t last_events_discarded; /* last known amount of event discarded */
void (*packet_seek)(struct stream_pos *pos, size_t index,
int whence); /* function called to switch packet */
extern "C" {
#endif
+/* Flags for the iterator read_event */
+enum {
+ BT_ITER_FLAG_LOST_EVENTS = (1 << 0),
+};
+
/* Forward declarations */
struct bt_iter;
struct bt_saved_pos;