Compute discarded events in live
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 29 Jan 2014 03:15:48 +0000 (22:15 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 8 Feb 2014 15:39:01 +0000 (10:39 -0500)
We now save the indexes received in live in the two first elements of a
packet index. This allows us to compute the number of discarded events.

We only keep the packet index elements we need in live so we don't leak
packet indexes when reading a live trace over many days (or longer).

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c
formats/lttng-live/lttng-live-functions.c
include/babeltrace/ctf/events-internal.h

index 7d98eb7a8f9ae61cd055ccea6ed37b95f20600f6..9f807c9e2d9910dcfe0a089c2ffaf200da766f12 100644 (file)
@@ -781,6 +781,42 @@ int ctf_fini_pos(struct ctf_stream_pos *pos)
        return 0;
 }
 
+void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
+               struct packet_index *prev_index,
+               struct packet_index *cur_index)
+{
+       uint64_t events_discarded_diff;
+
+       /* Update packet index time information */
+       stream->prev_cycles_timestamp_end =
+               cur_index->ts_cycles.timestamp_end;
+       stream->prev_cycles_timestamp =
+               cur_index->ts_cycles.timestamp_begin;
+       stream->prev_real_timestamp_end =
+               cur_index->ts_real.timestamp_end;
+       stream->prev_real_timestamp =
+               cur_index->ts_real.timestamp_begin;
+
+       stream->prev_real_timestamp =
+               stream->real_timestamp;
+       stream->prev_cycles_timestamp =
+               stream->cycles_timestamp;
+
+       /* Update packet index discarded event information */
+       events_discarded_diff = cur_index->events_discarded;
+       if (prev_index) {
+               events_discarded_diff -= prev_index->events_discarded;
+               /*
+                * Deal with 32-bit wrap-around if the tracer provided a
+                * 32-bit field.
+                */
+               if (prev_index->events_discarded_len == 32) {
+                       events_discarded_diff = (uint32_t) events_discarded_diff;
+               }
+       }
+       stream->events_discarded = events_discarded_diff;
+}
+
 /*
  * for SEEK_CUR: go to next packet.
  * for SEEK_SET: go to packet numer (index).
@@ -845,42 +881,19 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                switch (whence) {
                case SEEK_CUR:
                {
-                       uint64_t events_discarded_diff;
+                       struct packet_index *prev_index = NULL;
 
                        if (pos->offset == EOF) {
                                return;
                        }
                        assert(pos->cur_index < pos->packet_index->len);
-
-                       /* For printing discarded event count */
-                       packet_index = &g_array_index(pos->packet_index,
-                                       struct packet_index, pos->cur_index);
-                       file_stream->parent.prev_cycles_timestamp_end =
-                                       packet_index->ts_cycles.timestamp_end;
-                       file_stream->parent.prev_cycles_timestamp =
-                                       packet_index->ts_cycles.timestamp_begin;
-                       file_stream->parent.prev_real_timestamp_end =
-                                       packet_index->ts_real.timestamp_end;
-                       file_stream->parent.prev_real_timestamp =
-                                       packet_index->ts_real.timestamp_begin;
-
-                       events_discarded_diff = packet_index->events_discarded;
-                       if (pos->cur_index > 0) {
-                               packet_index = &g_array_index(pos->packet_index,
-                                               struct packet_index,
-                                               pos->cur_index - 1);
-                               events_discarded_diff -= packet_index->events_discarded;
-                               /*
-                                * Deal with 32-bit wrap-around if the
-                                * tracer provided a 32-bit field.
-                                */
-                               if (packet_index->events_discarded_len == 32) {
-                                       events_discarded_diff = (uint32_t) events_discarded_diff;
-                               }
+                       if (index > 0) {
+                               prev_index = &g_array_index(pos->packet_index,
+                                               struct packet_index, index - 1);
                        }
-                       file_stream->parent.events_discarded = events_discarded_diff;
-                       file_stream->parent.prev_real_timestamp = file_stream->parent.real_timestamp;
-                       file_stream->parent.prev_cycles_timestamp = file_stream->parent.cycles_timestamp;
+                       ctf_update_current_packet_index(&file_stream->parent,
+                                       prev_index, packet_index);
+
                        /* The reader will expect us to skip padding */
                        ++pos->cur_index;
                        break;
@@ -2179,12 +2192,13 @@ void ctf_init_mmap_pos(struct ctf_stream_pos *pos,
        pos->offset = 0;
        pos->dummy = false;
        pos->cur_index = 0;
-       pos->packet_index = NULL;
        pos->prot = PROT_READ;
        pos->flags = MAP_PRIVATE;
        pos->parent.rw_table = read_dispatch_table;
        pos->parent.event_cb = ctf_read_event;
        pos->priv = mmap_info->priv;
+       pos->packet_index = g_array_new(FALSE, TRUE,
+                       sizeof(struct packet_index));
 }
 
 static
index 375a05edeafd52b468a4f1b61709641eb7f99ec5..aa3844778ef27cb9f3da2a7a2c8d9e96967f0091 100644 (file)
@@ -774,7 +774,7 @@ void ctf_live_packet_seek(struct bt_stream_pos *stream_pos, size_t index,
 {
        struct ctf_stream_pos *pos;
        struct ctf_file_stream *file_stream;
-       struct packet_index packet_index;
+       struct packet_index *prev_index = NULL, *cur_index;
        struct lttng_live_viewer_stream *viewer_stream;
        struct lttng_live_session *session;
        int ret;
@@ -785,31 +785,72 @@ retry:
        viewer_stream = (struct lttng_live_viewer_stream *) pos->priv;
        session = viewer_stream->session;
 
+       switch (pos->packet_index->len) {
+       case 0:
+               g_array_set_size(pos->packet_index, 1);
+               cur_index = &g_array_index(pos->packet_index,
+                               struct packet_index, 0);
+               break;
+       case 1:
+               g_array_set_size(pos->packet_index, 2);
+               prev_index = &g_array_index(pos->packet_index,
+                               struct packet_index, 0);
+               cur_index = &g_array_index(pos->packet_index,
+                               struct packet_index, 1);
+               break;
+       case 2:
+               g_array_index(pos->packet_index,
+                       struct packet_index, 0) =
+                               g_array_index(pos->packet_index,
+                                       struct packet_index, 1);
+               prev_index = &g_array_index(pos->packet_index,
+                               struct packet_index, 0);
+               cur_index = &g_array_index(pos->packet_index,
+                               struct packet_index, 1);
+               break;
+       default:
+               abort();
+               break;
+       }
        printf_verbose("get_next_index for stream %" PRIu64 "\n", viewer_stream->id);
-       ret = get_next_index(session->ctx, viewer_stream, &packet_index);
+       ret = get_next_index(session->ctx, viewer_stream, cur_index);
        if (ret < 0) {
                pos->offset = EOF;
                fprintf(stderr, "[error] get_next_index failed\n");
                return;
        }
 
-       pos->packet_size = packet_index.packet_size;
-       pos->content_size = packet_index.content_size;
+       pos->packet_size = cur_index->packet_size;
+       pos->content_size = cur_index->content_size;
        pos->mmap_base_offset = 0;
-       if (packet_index.offset == EOF) {
+       if (cur_index->offset == EOF) {
                pos->offset = EOF;
        } else {
                pos->offset = 0;
        }
 
-       if (packet_index.content_size == 0) {
-               file_stream->parent.cycles_timestamp = packet_index.ts_cycles.timestamp_end;
+       if (cur_index->content_size == 0) {
+               file_stream->parent.cycles_timestamp =
+                               cur_index->ts_cycles.timestamp_end;
                file_stream->parent.real_timestamp = ctf_get_real_timestamp(
-                               &file_stream->parent, packet_index.ts_cycles.timestamp_end);
+                               &file_stream->parent,
+                               cur_index->ts_cycles.timestamp_end);
        } else {
-               file_stream->parent.cycles_timestamp = packet_index.ts_cycles.timestamp_begin;
-               file_stream->parent.real_timestamp = ctf_get_real_timestamp(
-                               &file_stream->parent, packet_index.ts_cycles.timestamp_begin);
+               /* Convert the timestamps and append to the real_index. */
+               cur_index->ts_real.timestamp_begin = ctf_get_real_timestamp(
+                               &file_stream->parent,
+                               cur_index->ts_cycles.timestamp_begin);
+               cur_index->ts_real.timestamp_end = ctf_get_real_timestamp(
+                               &file_stream->parent,
+                               cur_index->ts_cycles.timestamp_end);
+
+               ctf_update_current_packet_index(&file_stream->parent,
+                               prev_index, cur_index);
+
+               file_stream->parent.cycles_timestamp =
+                               cur_index->ts_cycles.timestamp_begin;
+               file_stream->parent.real_timestamp =
+                               cur_index->ts_real.timestamp_begin;
        }
 
        if (pos->packet_size == 0 || pos->offset == EOF) {
@@ -819,8 +860,8 @@ retry:
        printf_verbose("get_data_packet for stream %" PRIu64 "\n",
                        viewer_stream->id);
        ret = get_data_packet(session->ctx, pos, viewer_stream,
-                       be64toh(packet_index.offset),
-                       packet_index.packet_size / CHAR_BIT);
+                       be64toh(cur_index->offset),
+                       cur_index->packet_size / CHAR_BIT);
        if (ret == -2) {
                goto retry;
        } else if (ret < 0) {
@@ -832,9 +873,9 @@ retry:
        printf_verbose("Index received : packet_size : %" PRIu64
                        ", offset %" PRIu64 ", content_size %" PRIu64
                        ", timestamp_end : %" PRIu64 "\n",
-                       packet_index.packet_size, packet_index.offset,
-                       packet_index.content_size,
-                       packet_index.ts_cycles.timestamp_end);
+                       cur_index->packet_size, cur_index->offset,
+                       cur_index->content_size,
+                       cur_index->ts_cycles.timestamp_end);
 
        /* update trace_packet_header and stream_packet_context */
        if (pos->prot != PROT_WRITE && file_stream->parent.trace_packet_header) {
index be111c1710144a86056cb6441ab8357a2a31ba65..2e37693ab689afa089eebb4dc84ed60b8303df53 100644 (file)
@@ -81,5 +81,8 @@ struct bt_ctf_iter {
 
 void ctf_print_discarded(FILE *fp, struct ctf_stream_definition *stream,
                        int end_stream);
+void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
+               struct packet_index *prev_index,
+               struct packet_index *cur_index);
 
 #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
This page took 0.028899 seconds and 4 git commands to generate.