From 3bac1a1f2f88bc39f1f2eb09efe508f4c59d4428 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Mon, 10 Feb 2014 17:52:37 -0500 Subject: [PATCH] fix sync with last babeltrace updates to live handling Signed-off-by: Julien Desfossez --- lib/babeltrace/ctf/events-internal.h | 3 + lib/babeltrace/ctf/types.h | 12 ++-- src/Makefile.am | 4 +- src/{liblttng-live.c => lttng-live-comm.c} | 81 +++++++++++++++++----- src/{liblttng-live.h => lttng-live-comm.h} | 0 src/network-live.c | 2 +- 6 files changed, 76 insertions(+), 26 deletions(-) rename src/{liblttng-live.c => lttng-live-comm.c} (94%) rename src/{liblttng-live.h => lttng-live-comm.h} (100%) diff --git a/lib/babeltrace/ctf/events-internal.h b/lib/babeltrace/ctf/events-internal.h index be111c1..2e37693 100644 --- a/lib/babeltrace/ctf/events-internal.h +++ b/lib/babeltrace/ctf/events-internal.h @@ -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 */ diff --git a/lib/babeltrace/ctf/types.h b/lib/babeltrace/ctf/types.h index 338dad1..f268e13 100644 --- a/lib/babeltrace/ctf/types.h +++ b/lib/babeltrace/ctf/types.h @@ -44,15 +44,20 @@ struct bt_stream_callbacks; +struct packet_index_time { + uint64_t timestamp_begin; + uint64_t timestamp_end; +}; + struct packet_index { off_t offset; /* offset of the packet in the file, in bytes */ int64_t data_offset; /* offset of data within the packet, in bits */ uint64_t packet_size; /* packet size, in bits */ uint64_t content_size; /* content size, in bits */ - uint64_t timestamp_begin; - uint64_t timestamp_end; uint64_t events_discarded; uint64_t events_discarded_len; /* length of the field, in bits */ + struct packet_index_time ts_cycles; /* timestamp in cycles */ + struct packet_index_time ts_real; /* realtime timestamp */ }; /* @@ -62,8 +67,7 @@ struct ctf_stream_pos { struct bt_stream_pos parent; int fd; /* backing file fd. -1 if unset. */ FILE *index_fp; /* backing index file fp. NULL if unset. */ - GArray *packet_cycles_index; /* contains struct packet_index in cycles */ - GArray *packet_real_index; /* contains struct packet_index in ns */ + GArray *packet_index; /* contains struct packet_index */ int prot; /* mmap protection */ int flags; /* mmap flags */ diff --git a/src/Makefile.am b/src/Makefile.am index 9c351a8..72599e2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/lib -DBABELTRACE_HAVE_LIBUUID lib_LTLIBRARIES = libbabeltrace-lttngtop-live.la libbabeltrace_lttngtop_live_la_SOURCES = \ - network-live.c liblttng-live.c + network-live.c lttng-live-comm.c bin_PROGRAMS = lttngtop @@ -15,7 +15,7 @@ noinst_HEADERS = \ iostreamtop.h \ mmap-live.h \ network-live.h \ - liblttng-live.h \ + lttng-live-comm.h \ lttng-viewer-abi.h \ lttngtop.h diff --git a/src/liblttng-live.c b/src/lttng-live-comm.c similarity index 94% rename from src/liblttng-live.c rename to src/lttng-live-comm.c index d531882..988742e 100644 --- a/src/liblttng-live.c +++ b/src/lttng-live-comm.c @@ -54,7 +54,7 @@ replaced with #include "network-live.h" #include "lttngtop.h" -#include "liblttng-live.h" +#include "lttng-live-comm.h" #include "lttng-viewer-abi.h" /* @@ -861,7 +861,7 @@ retry: case LTTNG_VIEWER_INDEX_INACTIVE: printf_verbose("get_next_index: inactive\n"); memset(index, 0, sizeof(struct packet_index)); - index->timestamp_end = be64toh(rp.timestamp_end); + index->ts_cycles.timestamp_end = be64toh(rp.timestamp_end); break; case LTTNG_VIEWER_INDEX_OK: printf_verbose("get_next_index: Ok, need metadata update : %u\n", @@ -869,8 +869,8 @@ retry: index->offset = be64toh(rp.offset); index->packet_size = be64toh(rp.packet_size); index->content_size = be64toh(rp.content_size); - index->timestamp_begin = be64toh(rp.timestamp_begin); - index->timestamp_end = be64toh(rp.timestamp_end); + index->ts_cycles.timestamp_begin = be64toh(rp.timestamp_begin); + index->ts_cycles.timestamp_end = be64toh(rp.timestamp_end); index->events_discarded = be64toh(rp.events_discarded); if (rp.flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { @@ -922,7 +922,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; @@ -933,31 +933,73 @@ 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.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.timestamp_end); + &file_stream->parent, + cur_index->ts_cycles.timestamp_end); } else { - file_stream->parent.cycles_timestamp = packet_index.timestamp_begin; - file_stream->parent.real_timestamp = ctf_get_real_timestamp( - &file_stream->parent, packet_index.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) { @@ -967,8 +1009,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) { @@ -980,8 +1022,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.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) { diff --git a/src/liblttng-live.h b/src/lttng-live-comm.h similarity index 100% rename from src/liblttng-live.h rename to src/lttng-live-comm.h diff --git a/src/network-live.c b/src/network-live.c index 8f2a7ef..4f5caef 100644 --- a/src/network-live.c +++ b/src/network-live.c @@ -36,7 +36,7 @@ #include "lttng-viewer-abi.h" #include "network-live.h" -#include "liblttng-live.h" +#include "lttng-live-comm.h" #include #include -- 2.34.1