From: Julien Desfossez Date: Tue, 2 Jul 2013 18:22:08 +0000 (-0400) Subject: Introduce ustctl_write_one_packet_to_channel X-Git-Tag: v2.3.0-rc1~10 X-Git-Url: http://git.lttng.org/?p=lttng-ust.git;a=commitdiff_plain;h=3ef94b0eba0a0ed8c8552e0284d4084f98be475f Introduce ustctl_write_one_packet_to_channel This function allows the consumer to write at most one packet of data to the channel, that way we can push data to the ring buffer without risking to block on subbuffer switch. Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-ctl.h b/include/lttng/ust-ctl.h index f9315a61..3c81e509 100644 --- a/include/lttng/ust-ctl.h +++ b/include/lttng/ust-ctl.h @@ -164,6 +164,10 @@ int ustctl_write_metadata_to_channel( struct ustctl_consumer_channel *channel, const char *metadata_str, /* NOT null-terminated */ size_t len); /* metadata length */ +ssize_t ustctl_write_one_packet_to_channel( + struct ustctl_consumer_channel *channel, + const char *metadata_str, /* NOT null-terminated */ + size_t len); /* metadata length */ /* * Send a NULL stream to finish iteration over all streams of a given diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 0361f184..28dee5e9 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -1054,6 +1054,40 @@ end: return ret; } +/* + * Write at most one packet in the channel. + * Returns the number of bytes written on success, < 0 on error. + */ +ssize_t ustctl_write_one_packet_to_channel( + struct ustctl_consumer_channel *channel, + const char *metadata_str, /* NOT null-terminated */ + size_t len) /* metadata length */ +{ + struct lttng_ust_lib_ring_buffer_ctx ctx; + struct lttng_channel *chan = channel->chan; + const char *str = metadata_str; + ssize_t reserve_len; + int ret; + + reserve_len = min_t(ssize_t, + chan->ops->packet_avail_size(chan->chan, chan->handle), + len); + lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len, + sizeof(char), -1, chan->handle); + ret = chan->ops->event_reserve(&ctx, 0); + if (ret != 0) { + DBG("LTTng: event reservation failed"); + assert(ret < 0); + reserve_len = ret; + goto end; + } + chan->ops->event_write(&ctx, str, reserve_len); + chan->ops->event_commit(&ctx); + +end: + return reserve_len; +} + int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan) { struct channel *chan;