API Fix: bt_ctf_iter_read_event_flags
authorJulien Desfossez <jdesfossez@efficios.com>
Tue, 11 Sep 2012 02:04:09 +0000 (22:04 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 11 Sep 2012 02:04:09 +0000 (22:04 -0400)
The new bt_ctf_iter_read_event_flags function behaves like
bt_ctf_iter_read_event but takes a flag pointer.
This flag is used by the trace reading code to inform the user if some
events were discarded by the tracer in the current packet.

The new bt_ctf_get_lost_events_count function allows the user to get the
the number of events discarded immediately prior to the last event read.

[ Edit by Mathieu Desnoyers: use enum instead of define for
  BT_ITER_FLAG_LOST_EVENTS. ]

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
doc/API.txt
formats/ctf/ctf.c
formats/ctf/iterator.c
include/babeltrace/ctf/events-internal.h
include/babeltrace/ctf/iterator.h
include/babeltrace/ctf/types.h
include/babeltrace/iterator.h

index 5c06198ec1f3a721414fd221cdf089db143ff82c..bc3a4a10512e1aef477ee950de8a61d009250159 100644 (file)
@@ -76,6 +76,14 @@ creation will return NULL. The previous iterator must be destroyed before
 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
index f43fe91789d21d109c0adf407a0b7e951201ca39..f1fdba178f0a773d28a2286dae9eee133c29e929 100644 (file)
@@ -699,6 +699,9 @@ void ctf_packet_seek(struct stream_pos *stream_pos, size_t index, int whence)
                        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;
index ec74e59029381e73acc5cbf97a7c43ae4889fedf..0ac041910f7aedf9d967600efd24e718318b6891 100644 (file)
@@ -94,11 +94,13 @@ struct bt_iter *bt_ctf_get_iter(struct bt_ctf_iter *iter)
        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
@@ -116,6 +118,24 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
        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;
 
@@ -126,3 +146,16 @@ 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;
+}
index aaa09262321dfc32f62dddb185430bc7d4e771f3..71f73539c9692c6e3d8aabd62557bec57bb0bec1 100644 (file)
@@ -68,6 +68,7 @@ struct bt_ctf_iter {
         * bt_iter.
         */
        GPtrArray *dep_gc;
+       uint64_t events_lost;
 };
 
 #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
index 9370583a58df3e6042b92f74932305234ba0bc51..449ddfeb370b1cd8baba7efce664c1046c8bb809 100644 (file)
@@ -78,4 +78,26 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter);
 }
 #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 */
index 94231555c10dad3763a785b837040d08f410d52e..6a76c6bbf945c3c2e351a191cdf5b015e368f3ad 100644 (file)
@@ -67,6 +67,7 @@ struct ctf_stream_pos {
        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 */
 
index 3f7984fbe66ea00c01e6e5c95090acbf07f634fc..7eb3c5ebc4c34ffea7232afd80f8fd041fb739de 100644 (file)
 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;
This page took 0.02889 seconds and 4 git commands to generate.