From 15055ce5780557ef1053fcb4bd91a0746ffa30a0 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Mon, 11 Dec 2017 16:50:23 -0500 Subject: [PATCH] Common consumer functions to read current positions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Introduce lttng_consumer_sample_snapshot_positions and lttng_consumer_get_consumed_snapshotconsumer_flush_buffer to take a snapshot of the positions and read the consumed position. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- src/common/consumer/consumer.c | 40 ++++++++++++++++++++++++++++++++++ src/common/consumer/consumer.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index 2fa65f4d4..07de67578 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -1971,6 +1971,25 @@ end: return written; } +/* + * Sample the snapshot positions for a specific fd + * + * Returns 0 on success, < 0 on error + */ +int lttng_consumer_sample_snapshot_positions(struct lttng_consumer_stream *stream) +{ + switch (consumer_data.type) { + case LTTNG_CONSUMER_KERNEL: + return lttng_kconsumer_sample_snapshot_positions(stream); + case LTTNG_CONSUMER32_UST: + case LTTNG_CONSUMER64_UST: + return lttng_ustconsumer_sample_snapshot_positions(stream); + default: + ERR("Unknown consumer_data type"); + assert(0); + return -ENOSYS; + } +} /* * Take a snapshot for a specific fd * @@ -2012,6 +2031,27 @@ int lttng_consumer_get_produced_snapshot(struct lttng_consumer_stream *stream, } } +/* + * Get the consumed position (free-running counter position in bytes). + * + * Returns 0 on success, < 0 on error + */ +int lttng_consumer_get_consumed_snapshot(struct lttng_consumer_stream *stream, + unsigned long *pos) +{ + switch (consumer_data.type) { + case LTTNG_CONSUMER_KERNEL: + return lttng_kconsumer_get_consumed_snapshot(stream, pos); + case LTTNG_CONSUMER32_UST: + case LTTNG_CONSUMER64_UST: + return lttng_ustconsumer_get_consumed_snapshot(stream, pos); + default: + ERR("Unknown consumer_data type"); + assert(0); + return -ENOSYS; + } +} + int lttng_consumer_recv_cmd(struct lttng_consumer_local_data *ctx, int sock, struct pollfd *consumer_sockpoll) { diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index a7d0ee1a7..8a780e7f8 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -744,9 +744,12 @@ ssize_t lttng_consumer_on_read_subbuffer_splice( struct lttng_consumer_stream *stream, unsigned long len, unsigned long padding, struct ctf_packet_index *index); +int lttng_consumer_sample_snapshot_positions(struct lttng_consumer_stream *stream); int lttng_consumer_take_snapshot(struct lttng_consumer_stream *stream); int lttng_consumer_get_produced_snapshot(struct lttng_consumer_stream *stream, unsigned long *pos); +int lttng_consumer_get_consumed_snapshot(struct lttng_consumer_stream *stream, + unsigned long *pos); int lttng_ustconsumer_get_wakeup_fd(struct lttng_consumer_stream *stream); int lttng_ustconsumer_close_wakeup_fd(struct lttng_consumer_stream *stream); void *consumer_thread_metadata_poll(void *data); -- 2.34.1