From: Julien Desfossez Date: Tue, 11 Sep 2012 02:04:09 +0000 (-0400) Subject: API Fix: bt_ctf_iter_read_event_flags X-Git-Tag: v1.0.0-rc6~25 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=f60efc0e475b3c2fca3b2afc584615f6c482c9e7 API Fix: bt_ctf_iter_read_event_flags 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 Signed-off-by: Mathieu Desnoyers --- diff --git a/doc/API.txt b/doc/API.txt index 5c06198e..bc3a4a10 100644 --- a/doc/API.txt +++ b/doc/API.txt @@ -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 diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index f43fe917..f1fdba17 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -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; diff --git a/formats/ctf/iterator.c b/formats/ctf/iterator.c index ec74e590..0ac04191 100644 --- a/formats/ctf/iterator.c +++ b/formats/ctf/iterator.c @@ -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; +} diff --git a/include/babeltrace/ctf/events-internal.h b/include/babeltrace/ctf/events-internal.h index aaa09262..71f73539 100644 --- a/include/babeltrace/ctf/events-internal.h +++ b/include/babeltrace/ctf/events-internal.h @@ -68,6 +68,7 @@ struct bt_ctf_iter { * bt_iter. */ GPtrArray *dep_gc; + uint64_t events_lost; }; #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */ diff --git a/include/babeltrace/ctf/iterator.h b/include/babeltrace/ctf/iterator.h index 9370583a..449ddfeb 100644 --- a/include/babeltrace/ctf/iterator.h +++ b/include/babeltrace/ctf/iterator.h @@ -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 */ diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 94231555..6a76c6bb 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -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 */ diff --git a/include/babeltrace/iterator.h b/include/babeltrace/iterator.h index 3f7984fb..7eb3c5eb 100644 --- a/include/babeltrace/iterator.h +++ b/include/babeltrace/iterator.h @@ -24,6 +24,11 @@ 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;