From: Mathieu Desnoyers Date: Tue, 8 Nov 2011 14:42:17 +0000 (-0500) Subject: UST consumer: perform buffer flush on hang up X-Git-Tag: v2.0-pre15~148 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d056b47720cf547dd8c4ca59076ffcd215d58f2c;p=lttng-tools.git UST consumer: perform buffer flush on hang up Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/lttng-consumer.h b/include/lttng/lttng-consumer.h index 256293b81..6f893a53a 100644 --- a/include/lttng/lttng-consumer.h +++ b/include/lttng/lttng-consumer.h @@ -118,6 +118,7 @@ struct lttng_consumer_stream { /* For UST */ struct lttng_ust_lib_ring_buffer *buf; int cpu; + int hangup_flush_done; }; /* diff --git a/include/lttng/lttng-ustconsumer.h b/include/lttng/lttng-ustconsumer.h index 90d6588b9..217c592d7 100644 --- a/include/lttng/lttng-ustconsumer.h +++ b/include/lttng/lttng-ustconsumer.h @@ -70,6 +70,8 @@ int lttng_ustconsumer_read_subbuffer(struct lttng_consumer_stream *stream, struct lttng_consumer_local_data *ctx); int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream); +void lttng_ustconsumer_on_stream_hangup(struct lttng_consumer_stream *stream); + #else /* HAVE_LIBLTTNG_UST_CTL */ static inline @@ -146,6 +148,11 @@ int lttng_ustconsumer_on_recv_stream(struct lttng_consumer_stream *stream) return -ENOSYS; } +static inline +void lttng_ustconsumer_on_stream_hangup(struct lttng_consumer_stream *stream) +{ +} + #endif /* HAVE_LIBLTTNG_UST_CTL */ #endif /* _LTTNG_USTCONSUMER_H */ diff --git a/liblttng-consumer/lttng-consumer.c b/liblttng-consumer/lttng-consumer.c index de15dd3b7..54338e800 100644 --- a/liblttng-consumer/lttng-consumer.c +++ b/liblttng-consumer/lttng-consumer.c @@ -847,7 +847,21 @@ void *lttng_consumer_thread_poll_fds(void *data) num_hup++; } else if ((pollfd[i].revents & POLLHUP) && !(pollfd[i].revents & POLLIN)) { - DBG("Polling fd %d tells it has hung up.", pollfd[i].fd); + if (consumer_data.type == LTTNG_CONSUMER_UST) { + DBG("Polling fd %d tells it has hung up. Attempting flush and read.", + pollfd[i].fd); + if (!local_stream[i]->hangup_flush_done) { + lttng_ustconsumer_on_stream_hangup(local_stream[i]); + /* try reading after flush */ + ret = ctx->on_buffer_ready(local_stream[i], ctx); + /* it's ok to have an unavailable sub-buffer */ + if (ret == EAGAIN) { + ret = 0; + } + } + } else { + DBG("Polling fd %d tells it has hung up.", pollfd[i].fd); + } consumer_del_stream(local_stream[i]); num_hup++; } diff --git a/liblttng-ustconsumer/lttng-ustconsumer.c b/liblttng-ustconsumer/lttng-ustconsumer.c index 29f735249..806ebd3c0 100644 --- a/liblttng-ustconsumer/lttng-ustconsumer.c +++ b/liblttng-ustconsumer/lttng-ustconsumer.c @@ -175,6 +175,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, msg.u.channel.mmap_len, msg.u.channel.max_sb_size); if (new_channel == NULL) { + fprintf(stderr, "AAAAA\n"); lttng_consumer_send_error(ctx, CONSUMERD_OUTFD_ERROR); goto end_nosignal; } @@ -217,6 +218,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, msg.u.stream.output, msg.u.stream.path_name); if (new_stream == NULL) { + fprintf(stderr, "BBBBBB\n"); lttng_consumer_send_error(ctx, CONSUMERD_OUTFD_ERROR); goto end; } @@ -281,6 +283,11 @@ int lttng_ustconsumer_allocate_channel(struct lttng_consumer_channel *chan) return 0; } +void lttng_ustconsumer_on_stream_hangup(struct lttng_consumer_stream *stream) +{ + ustctl_flush_buffer(stream->chan->handle, stream->buf, 0); +} + void lttng_ustconsumer_del_channel(struct lttng_consumer_channel *chan) { ustctl_unmap_channel(chan->handle);