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).
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;
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
{
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;
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) {
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) {
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) {