Skip to contentSkip to conversation

LTTng ringbuffer ABI calls for index generation

PATCH New Julien Desfossez 2 participants 4 messages Aug 15, 2013 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/2 LTTng ringbuffer ABI calls for index generation

These new calls export the data required for the consumer to generate the index while tracing :
- timestamp begin
- timestamp end
- events discarded
- context size
- packet size
- stream id

---
 include/lttng/ust-ctl.h                 |   14 ++++
 liblttng-ust-ctl/ustctl.c               |   90 ++++++++++++++++++++++
 liblttng-ust/lttng-rb-clients.h         |   19 +++++
 liblttng-ust/lttng-ring-buffer-client.h |   91 ++++++++++++++++++++++
 libringbuffer/frontend.h                |   19 +++++
 libringbuffer/ring_buffer_frontend.c    |  127 +++++++++++++++++++++++++++++++
 6 files changed, 360 insertions(+)
include/lttng/ust-ctl.h +14 -0
index 3c81e50..88112ad 100644
@@ -220,6 +220,20 @@ int ustctl_put_subbuf(struct ustctl_consumer_stream *stream);
 void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
 		int producer_active);
 
+/* index */
+int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
+		uint64_t *timestamp_begin);
+int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
+	uint64_t *timestamp_end);
+int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
+	uint64_t *events_discarded);
+int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
+	uint64_t *content_size);
+int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
+	uint64_t *packet_size);
+int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
+		uint64_t *stream_id);
+
 /* event registry management */
 
 enum ustctl_socket_type {
liblttng-ust-ctl/ustctl.c +90 -0

96 lines not on this page · raw message

liblttng-ust/lttng-rb-clients.h +19 -0
index 37fd842..3a22e03 100644
@@ -3,6 +3,25 @@
 
 struct specialized_lttng_ust_lib_ring_buffer_client_cb {
 	struct lttng_ust_lib_ring_buffer_client_cb parent;
+
+	int (*timestamp_begin) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *timestamp_begin);
+	int (*timestamp_end) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *timestamp_end);
+	int (*events_discarded) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *events_discarded);
+	int (*content_size) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *content_size);
+	int (*packet_size) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *packet_size);
+	int (*stream_id) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *stream_id);
 };
 
 #endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +91 -0

103 lines not on this page · raw message

libringbuffer/frontend.h +19 -0
index 89613d4..92399d2 100644
@@ -269,4 +269,23 @@ unsigned long lib_ring_buffer_get_records_read(
 	return v_read(config, &buf->backend.records_read);
 }
 
+extern int lib_ring_buffer_get_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_begin);
+extern int lib_ring_buffer_get_timestamp_end(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_end);
+extern int lib_ring_buffer_get_events_discarded(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *events_discarded);
+extern int lib_ring_buffer_get_content_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *content_size);
+extern int lib_ring_buffer_get_packet_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *packet_size);
+extern int lib_ring_buffer_get_stream_id(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *stream_id);
+
 #endif /* _LTTNG_RING_BUFFER_FRONTEND_H */
libringbuffer/ring_buffer_frontend.c +127 -0

139 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

Re: [UST PATCH 1/2] Specialize lttng_ust_lib_ring_buffer_client_cb

In reply to a message not in the archive
Quoted 20 lines · * Julien Desfossez ([email protected]) wrote:

Prepare the ring-buffer config to have custom callbacks. These custom callbacks are not related to the ring-buffer operations but allow applications to add custom functions.
No additional feature or change in behaviour in this patch.

---
 include/lttng/ringbuffer-config.h                |    1 +
 include/lttng/ust-events.h                       |    6 +++---
 liblttng-ust/lttng-rb-clients.h                  |    8 ++++++++
 liblttng-ust/lttng-ring-buffer-client.h          |   18 +++++++++++++++++-
 liblttng-ust/lttng-ring-buffer-metadata-client.h |   18 +++++++++++++++++-
 5 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 liblttng-ust/lttng-rb-clients.h
include/lttng/ringbuffer-config.h +0 -0
index 3b7d348..e81b827 100644

include/lttng/ringbuffer-config.h struct lttng_ust_lib_ring_buffer_config { · line 208

Quoted 5 lines
include/lttng/ringbuffer-config.h +1 -0
@@ -204,6 +204,7 @@ struct lttng_ust_lib_ring_buffer_config {
 	 * callbacks and update the cb pointers.
 	 */
 	int client_type;
+	const struct lttng_ust_lib_ring_buffer_client_cb *cb_ptr;
 	char padding[LTTNG_UST_RING_BUFFER_CONFIG_PADDING];

we need to change the padding size.

Quoted 25 lines
include/lttng/ringbuffer-config.h +0 -0
 };
 
include/lttng/ust-events.h +3 -3
index f40c044..153c0ff 100644
@@ -569,9 +569,9 @@ int lttng_add_ip_to_ctx(struct lttng_ctx **ctx);
 void lttng_context_vtid_reset(void);
 void lttng_context_vpid_reset(void);
 
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
 
 struct lttng_transport *lttng_transport_find(const char *name);
 
liblttng-ust/lttng-rb-clients.h new file +0 -0
new file mode 100644
index 0000000..37fd842

liblttng-ust/lttng-rb-clients.h line 2

Quoted 2 lines
liblttng-ust/lttng-rb-clients.h new file +2 -0
@@ -0,0 +1,8 @@
+#ifndef _LTTNG_RB_CLIENT_H
+#define _LTTNG_RB_CLIENT_H

missing file copyright/license header.

liblttng-ust/lttng-rb-clients.h line 4

Quoted 2 lines
liblttng-ust/lttng-rb-clients.h new file +2 -0
+
+struct specialized_lttng_ust_lib_ring_buffer_client_cb {

maybe we could find another name than "specialized" ?

Thanks,

Mathieu

Quoted 97 lines
liblttng-ust/lttng-rb-clients.h new file +4 -0
+	struct lttng_ust_lib_ring_buffer_client_cb parent;
+};
+
+#endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +17 -1
index 72b6d2c..94db97e 100644
@@ -161,6 +161,7 @@ unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *
 }
 
 #include "../libringbuffer/api.h"
+#include "lttng-rb-clients.h"
 
 static
 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
@@ -385,6 +386,19 @@ static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *
 {
 }
 
+static const
+struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
+	.parent = {
+		.ring_buffer_clock_read = client_ring_buffer_clock_read,
+		.record_header_size = client_record_header_size,
+		.subbuffer_header_size = client_packet_header_size,
+		.buffer_begin = client_buffer_begin,
+		.buffer_end = client_buffer_end,
+		.buffer_create = client_buffer_create,
+		.buffer_finalize = client_buffer_finalize,
+	},
+};
+
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
 	.cb.record_header_size = client_record_header_size,
@@ -404,9 +418,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.ipi = RING_BUFFER_NO_IPI_BARRIER,
 	.wakeup = LTTNG_CLIENT_WAKEUP,
 	.client_type = LTTNG_CLIENT_TYPE,
+
+	.cb_ptr = &client_cb.parent,
 };
 
-const struct lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_config.cb;
+const struct specialized_lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_cb;
 
 static
 struct lttng_channel *_channel_create(const char *name,
liblttng-ust/lttng-ring-buffer-metadata-client.h +17 -1
index 89f2620..5098f21 100644
@@ -61,6 +61,7 @@ unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *
 }
 
 #include "../libringbuffer/api.h"
+#include "lttng-rb-clients.h"
 
 static uint64_t client_ring_buffer_clock_read(struct channel *chan)
 {
@@ -153,6 +154,19 @@ static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf,
 {
 }
 
+static const
+struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
+	.parent = {
+		.ring_buffer_clock_read = client_ring_buffer_clock_read,
+		.record_header_size = client_record_header_size,
+		.subbuffer_header_size = client_packet_header_size,
+		.buffer_begin = client_buffer_begin,
+		.buffer_end = client_buffer_end,
+		.buffer_create = client_buffer_create,
+		.buffer_finalize = client_buffer_finalize,
+	},
+};
+
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
 	.cb.record_header_size = client_record_header_size,
@@ -172,9 +186,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.ipi = RING_BUFFER_NO_IPI_BARRIER,
 	.wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
 	.client_type = LTTNG_CLIENT_TYPE,
+
+	 .cb_ptr = &client_cb.parent,
 };
 
-const struct lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_config.cb;
+const struct specialized_lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_cb;
 
 static
 struct lttng_channel *_channel_create(const char *name,
Signature · 1 line
1.7.10.4
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 55 lines · * Julien Desfossez ([email protected]) wrote:

These new calls export the data required for the consumer to generate the index while tracing :
- timestamp begin
- timestamp end
- events discarded
- context size
- packet size
- stream id

---
 include/lttng/ust-ctl.h                 |   14 ++++
 liblttng-ust-ctl/ustctl.c               |   90 ++++++++++++++++++++++
 liblttng-ust/lttng-rb-clients.h         |   19 +++++
 liblttng-ust/lttng-ring-buffer-client.h |   91 ++++++++++++++++++++++
 libringbuffer/frontend.h                |   19 +++++
 libringbuffer/ring_buffer_frontend.c    |  127 +++++++++++++++++++++++++++++++
 6 files changed, 360 insertions(+)
include/lttng/ust-ctl.h +14 -0
index 3c81e50..88112ad 100644
@@ -220,6 +220,20 @@ int ustctl_put_subbuf(struct ustctl_consumer_stream *stream);
 void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
 		int producer_active);
 
+/* index */
+int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
+		uint64_t *timestamp_begin);
+int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
+	uint64_t *timestamp_end);
+int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
+	uint64_t *events_discarded);
+int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
+	uint64_t *content_size);
+int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
+	uint64_t *packet_size);
+int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
+		uint64_t *stream_id);
+
 /* event registry management */
 
 enum ustctl_socket_type {
liblttng-ust-ctl/ustctl.c +3 -0
index 28dee5e..a53ba3f 100644
@@ -1461,6 +1461,96 @@ void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
 		consumer_chan->chan->handle);
 }
 
+int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
+		uint64_t *timestamp_begin)
+{

liblttng-ust-ctl/ustctl.c void ustctl_flush_buffer(struct ustctl_consumer_stream *stream, · line 1476

Quoted 10 lines
liblttng-ust-ctl/ustctl.c +10 -0
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_timestamp_begin(buf, consumer_chan->chan->handle,
+			timestamp_begin);

these should not call a lib_ring_buffer function to do get_timestamp_begin, but rather call a callback specific to the client. It should test if the callback is NULL and return an error if it is (in the case the stream is a metadata stream).

Quoted 224 lines
liblttng-ust-ctl/ustctl.c +77 -0
+}
+
+int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
+	uint64_t *timestamp_end)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_timestamp_end(buf, consumer_chan->chan->handle,
+			timestamp_end);
+}
+
+int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
+	uint64_t *events_discarded)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_events_discarded(buf, consumer_chan->chan->handle,
+			events_discarded);
+}
+
+int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
+	uint64_t *content_size)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_content_size(buf, consumer_chan->chan->handle,
+			content_size);
+}
+
+int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
+	uint64_t *packet_size)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_packet_size(buf, consumer_chan->chan->handle,
+			packet_size);
+}
+
+int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
+		uint64_t *stream_id)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+
+	return lib_ring_buffer_get_stream_id(buf, consumer_chan->chan->handle,
+			stream_id);
+}
+
 /*
  * Returns 0 on success, negative error value on error.
  */
liblttng-ust/lttng-rb-clients.h +19 -0
index 37fd842..3a22e03 100644
@@ -3,6 +3,25 @@
 
 struct specialized_lttng_ust_lib_ring_buffer_client_cb {
 	struct lttng_ust_lib_ring_buffer_client_cb parent;
+
+	int (*timestamp_begin) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *timestamp_begin);
+	int (*timestamp_end) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *timestamp_end);
+	int (*events_discarded) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *events_discarded);
+	int (*content_size) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *content_size);
+	int (*packet_size) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *packet_size);
+	int (*stream_id) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle,
+			uint64_t *stream_id);
 };
 
 #endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +91 -0
index 94db97e..942a624 100644
@@ -386,6 +386,91 @@ static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *
 {
 }
 
+static struct packet_header *client_packet_header(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	struct lttng_channel *lttng_chan = channel_get_private(chan);
+	unsigned long sb_index;
+	struct lttng_ust_lib_ring_buffer_backend *bufb;
+	struct packet_header *header;
+
+	bufb = &buf->backend;
+	sb_index = subbuffer_id_get_index(&lttng_chan->chan->backend.config,
+			bufb->buf_rsb.id);
+
+	header = lib_ring_buffer_offset_address(bufb,
+			sb_index * lttng_chan->chan->backend.subbuf_size,
+			handle);
+
+	return header;
+}
+
+static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_begin)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*timestamp_begin = header->ctx.timestamp_begin;
+
+	return 0;
+}
+
+static int client_timestamp_end(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_end)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*timestamp_end = header->ctx.timestamp_end;
+
+	return 0;
+}
+
+static int client_events_discarded(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *events_discarded)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*events_discarded = header->ctx.events_discarded;
+
+	return 0;
+}
+
+static int client_content_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *content_size)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*content_size = header->ctx.content_size;
+
+	return 0;
+}
+
+static int client_packet_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *packet_size)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*packet_size = header->ctx.packet_size;
+
+	return 0;
+}
+
+static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *stream_id)
+{
+	struct packet_header *header = client_packet_header(buf, handle);
+
+	*stream_id = header->stream_id;
+
+	return 0;
+}
 static const
 struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
 	.parent = {
@@ -397,6 +482,12 @@ struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
 		.buffer_create = client_buffer_create,
 		.buffer_finalize = client_buffer_finalize,
 	},
+	.timestamp_begin = client_timestamp_begin,
+	.timestamp_end = client_timestamp_end,
+	.events_discarded = client_events_discarded,
+	.content_size = client_content_size,
+	.packet_size = client_packet_size,
+	.stream_id = client_stream_id,
 };
 
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
libringbuffer/frontend.h +0 -0
index 89613d4..92399d2 100644

libringbuffer/frontend.h unsigned long lib_ring_buffer_get_records_read( · line 271

Quoted 3 lines
libringbuffer/frontend.h +0 -0
@@ -269,4 +269,23 @@ unsigned long lib_ring_buffer_get_records_read(
 	return v_read(config, &buf->backend.records_read);
 }
 

All the per-client stuff don't belong in the frontend.h file. This is specific to the lttng ring buffer client.

libringbuffer/ring_buffer_frontend.c

Quoted 24 lines
libringbuffer/frontend.h +19 -0
+extern int lib_ring_buffer_get_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_begin);
+extern int lib_ring_buffer_get_timestamp_end(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_end);
+extern int lib_ring_buffer_get_events_discarded(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *events_discarded);
+extern int lib_ring_buffer_get_content_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *content_size);
+extern int lib_ring_buffer_get_packet_size(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *packet_size);
+extern int lib_ring_buffer_get_stream_id(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *stream_id);
+
 #endif /* _LTTNG_RING_BUFFER_FRONTEND_H */
libringbuffer/ring_buffer_frontend.c +0 -0
index e99ba8a..6664935 100644

The stuff below should be moved to the lttng ringbuffer client file.

Thanks,

Mathieu

Quoted 144 lines
libringbuffer/ring_buffer_frontend.c +127 -0
@@ -72,6 +72,7 @@
 #include "shm.h"
 #include "tlsfixup.h"
 #include "../liblttng-ust/compat.h"	/* For ENODATA */
+#include "../liblttng-ust/lttng-rb-clients.h"
 
 #ifndef max
 #define max(a, b)	((a) > (b) ? (a) : (b))
@@ -1869,6 +1870,132 @@ int lib_ring_buffer_reserve_slow(struct lttng_ust_lib_ring_buffer_ctx *ctx)
 	return 0;
 }
 
+/**
+ * lib_ring_buffer_get_timestamp_begin - get the timestamp begin of the subbuffer
+ * @buf: ring buffer
+ * @timestamp_begin: timestamp begin of the subbuffer
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *timestamp_begin)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->timestamp_begin(buf, handle, timestamp_begin);
+}
+
+/**
+ * lib_ring_buffer_get_timestamp_end - get the timestamp end of the subbuffer
+ * @buf: ring buffer
+ * @timestamp_end: timestamp end of the subbuffer
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_timestamp_end(struct lttng_ust_lib_ring_buffer *buf,
+	struct lttng_ust_shm_handle *handle,
+	uint64_t *timestamp_end)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->timestamp_end(buf, handle, timestamp_end);
+}
+
+/**
+ * lib_ring_buffer_get_events_discarded - get the number of discarded events
+ * @buf: ring buffer
+ * @events_discarded: discarded events
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_events_discarded(struct lttng_ust_lib_ring_buffer *buf,
+	struct lttng_ust_shm_handle *handle,
+	uint64_t *events_discarded)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->events_discarded(buf, handle, events_discarded);
+}
+
+/**
+ * lib_ring_buffer_get_content_size - get the content size of the subbuffer
+ * @buf: ring buffer
+ * @content_size: content size of the subbuffer
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_content_size(struct lttng_ust_lib_ring_buffer *buf,
+	struct lttng_ust_shm_handle *handle,
+	uint64_t *content_size)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->content_size(buf, handle, content_size);
+}
+
+/**
+ * lib_ring_buffer_get_packet_size - get the packet size of the subbuffer
+ * @buf: ring buffer
+ * @packet_size: packet size of the subbuffer
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_packet_size(struct lttng_ust_lib_ring_buffer *buf,
+	struct lttng_ust_shm_handle *handle,
+	uint64_t *packet_size)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->packet_size(buf, handle, packet_size);
+}
+
+/**
+ * lib_ring_buffer_get_stream_id - get the strean ID of the subbuffer
+ * @buf: ring buffer
+ * @stream_id: stream ID of the subbuffer
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+int lib_ring_buffer_get_stream_id(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *stream_id)
+{
+	struct channel *chan = shmp(handle, buf->backend.chan);
+	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
+	struct specialized_lttng_ust_lib_ring_buffer_client_cb *client_cb;
+
+	client_cb = caa_container_of(config->cb_ptr,
+			struct specialized_lttng_ust_lib_ring_buffer_client_cb,
+			parent);
+	return client_cb->stream_id(buf, handle, stream_id);
+}
+
 /*
  * Force a read (imply TLS fixup for dlopen) of TLS variables.
  */
Signature · 1 line
1.7.10.4
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): 20130815214936.GA24636@Krystal

#6 lore raw

Re: [UST PATCH 1/2] Specialize lttng_ust_lib_ring_buffer_client_cb

Quoted 11 lines · * Mathieu Desnoyers ([email protected]) wrote:
Quoted 10 lines · * Julien Desfossez ([email protected]) wrote:

Prepare the ring-buffer config to have custom callbacks. These custom callbacks are not related to the ring-buffer operations but allow applications to add custom functions.
No additional feature or change in behaviour in this patch.

---
 include/lttng/ringbuffer-config.h                |    1 +
 include/lttng/ust-events.h                       |    6 +++---
 liblttng-ust/lttng-rb-clients.h                  |    8 ++++++++

Also, this new header file should be added to Makefile.am.

Thanks,

Mathieu

Quoted 164 lines
Quoted 10 lines
 liblttng-ust/lttng-ring-buffer-client.h          |   18 +++++++++++++++++-
 liblttng-ust/lttng-ring-buffer-metadata-client.h |   18 +++++++++++++++++-
 5 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 liblttng-ust/lttng-rb-clients.h
include/lttng/ringbuffer-config.h +0 -0
index 3b7d348..e81b827 100644

include/lttng/ringbuffer-config.h struct lttng_ust_lib_ring_buffer_config { · line 208

Quoted 5 lines
include/lttng/ringbuffer-config.h +1 -0
@@ -204,6 +204,7 @@ struct lttng_ust_lib_ring_buffer_config {
 	 * callbacks and update the cb pointers.
 	 */
 	int client_type;
+	const struct lttng_ust_lib_ring_buffer_client_cb *cb_ptr;
 	char padding[LTTNG_UST_RING_BUFFER_CONFIG_PADDING];

we need to change the padding size.

Quoted 25 lines
include/lttng/ringbuffer-config.h +0 -0
 };
 
include/lttng/ust-events.h +3 -3
index f40c044..153c0ff 100644
@@ -569,9 +569,9 @@ int lttng_add_ip_to_ctx(struct lttng_ctx **ctx);
 void lttng_context_vtid_reset(void);
 void lttng_context_vpid_reset(void);
 
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
-extern const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
+extern const struct specialized_lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
 
 struct lttng_transport *lttng_transport_find(const char *name);
 
liblttng-ust/lttng-rb-clients.h new file +0 -0
new file mode 100644
index 0000000..37fd842

liblttng-ust/lttng-rb-clients.h line 2

Quoted 2 lines
liblttng-ust/lttng-rb-clients.h new file +2 -0
@@ -0,0 +1,8 @@
+#ifndef _LTTNG_RB_CLIENT_H
+#define _LTTNG_RB_CLIENT_H

missing file copyright/license header.

liblttng-ust/lttng-rb-clients.h line 4

Quoted 2 lines
liblttng-ust/lttng-rb-clients.h new file +2 -0
+
+struct specialized_lttng_ust_lib_ring_buffer_client_cb {

maybe we could find another name than "specialized" ?

Thanks,

Mathieu

Quoted 97 lines
liblttng-ust/lttng-rb-clients.h new file +4 -0
+	struct lttng_ust_lib_ring_buffer_client_cb parent;
+};
+
+#endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +17 -1
index 72b6d2c..94db97e 100644
@@ -161,6 +161,7 @@ unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *
 }
 
 #include "../libringbuffer/api.h"
+#include "lttng-rb-clients.h"
 
 static
 void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config *config,
@@ -385,6 +386,19 @@ static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf, void *
 {
 }
 
+static const
+struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
+	.parent = {
+		.ring_buffer_clock_read = client_ring_buffer_clock_read,
+		.record_header_size = client_record_header_size,
+		.subbuffer_header_size = client_packet_header_size,
+		.buffer_begin = client_buffer_begin,
+		.buffer_end = client_buffer_end,
+		.buffer_create = client_buffer_create,
+		.buffer_finalize = client_buffer_finalize,
+	},
+};
+
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
 	.cb.record_header_size = client_record_header_size,
@@ -404,9 +418,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.ipi = RING_BUFFER_NO_IPI_BARRIER,
 	.wakeup = LTTNG_CLIENT_WAKEUP,
 	.client_type = LTTNG_CLIENT_TYPE,
+
+	.cb_ptr = &client_cb.parent,
 };
 
-const struct lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_config.cb;
+const struct specialized_lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_cb;
 
 static
 struct lttng_channel *_channel_create(const char *name,
liblttng-ust/lttng-ring-buffer-metadata-client.h +17 -1
index 89f2620..5098f21 100644
@@ -61,6 +61,7 @@ unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *
 }
 
 #include "../libringbuffer/api.h"
+#include "lttng-rb-clients.h"
 
 static uint64_t client_ring_buffer_clock_read(struct channel *chan)
 {
@@ -153,6 +154,19 @@ static void client_buffer_finalize(struct lttng_ust_lib_ring_buffer *buf,
 {
 }
 
+static const
+struct specialized_lttng_ust_lib_ring_buffer_client_cb client_cb = {
+	.parent = {
+		.ring_buffer_clock_read = client_ring_buffer_clock_read,
+		.record_header_size = client_record_header_size,
+		.subbuffer_header_size = client_packet_header_size,
+		.buffer_begin = client_buffer_begin,
+		.buffer_end = client_buffer_end,
+		.buffer_create = client_buffer_create,
+		.buffer_finalize = client_buffer_finalize,
+	},
+};
+
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.cb.ring_buffer_clock_read = client_ring_buffer_clock_read,
 	.cb.record_header_size = client_record_header_size,
@@ -172,9 +186,11 @@ static const struct lttng_ust_lib_ring_buffer_config client_config = {
 	.ipi = RING_BUFFER_NO_IPI_BARRIER,
 	.wakeup = RING_BUFFER_WAKEUP_BY_WRITER,
 	.client_type = LTTNG_CLIENT_TYPE,
+
+	 .cb_ptr = &client_cb.parent,
 };
 
-const struct lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_config.cb;
+const struct specialized_lttng_ust_lib_ring_buffer_client_cb *LTTNG_CLIENT_CALLBACKS = &client_cb;
 
 static
 struct lttng_channel *_channel_create(const char *name,
Signature · 1 line
1.7.10.4
Signature · 8 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com