Skip to contentSkip to conversation

Generate and export the sequence number

PATCH New Julien Desfossez 1 participant 2 messages Jul 13, 2015 1 message 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/3 Generate and export the sequence number

This allows the viewer to identify the gaps between trace packets.

This is a locked-step with the corresponding commit in lttng-tools.

---
 include/lttng/ust-ctl.h                 |  2 ++
 liblttng-ust-ctl/ustctl.c               | 17 +++++++++++++
 liblttng-ust/lttng-rb-clients.h         |  2 ++
 liblttng-ust/lttng-ring-buffer-client.h | 29 ++++++++++++++++++++++
 libringbuffer/backend_internal.h        | 43 +++++++++++++++++++++++++++++++++
 5 files changed, 93 insertions(+)
include/lttng/ust-ctl.h +2 -0
index 78e0cf7..d27ca8a 100644
@@ -241,6 +241,8 @@ int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
 		uint64_t *stream_id);
 int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
 		uint64_t *ts);
+int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
+		uint64_t *seq);
 
 /* returns whether UST has perf counters support. */
 int ustctl_has_perf_counters(void);
liblttng-ust-ctl/ustctl.c +17 -0
index 5801bc6..010dfd8 100644
@@ -1646,6 +1646,23 @@ int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
 	return client_cb->current_timestamp(buf, handle, ts);
 }
 
+int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
+		uint64_t *seq)
+{
+	struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct lttng_ust_shm_handle *handle;
+
+	if (!stream || !seq)
+		return -EINVAL;
+	buf = stream->buf;
+	handle = stream->chan->chan->handle;
+	client_cb = get_client_cb(buf, handle);
+	if (!client_cb || !client_cb->sequence_number)
+		return -ENOSYS;
+	return client_cb->sequence_number(buf, handle, seq);
+}
+
 #if defined(__x86_64__) || defined(__i386__)
 
 int ustctl_has_perf_counters(void)
liblttng-ust/lttng-rb-clients.h +2 -0
index 85d4e1b..788f075 100644
@@ -43,6 +43,8 @@ struct lttng_ust_client_lib_ring_buffer_client_cb {
 	int (*current_timestamp) (struct lttng_ust_lib_ring_buffer *buf,
 			struct lttng_ust_shm_handle *handle,
 			uint64_t *ts);
+	int (*sequence_number) (struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle, uint64_t *seq);
 };
 
 #endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +29 -0
index 41baab0..1e93cff 100644
@@ -53,6 +53,7 @@ struct packet_header {
 		uint64_t timestamp_end;		/* Cycle count at subbuffer end */
 		uint64_t content_size;		/* Size of data in subbuffer */
 		uint64_t packet_size;		/* Subbuffer size (include padding) */
+		uint64_t packet_seq_num;	/* Packet sequence number */
 		unsigned long events_discarded;	/*
 						 * Events lost in this subbuffer since
 						 * the beginning of the trace.
@@ -339,6 +340,9 @@ static void client_buffer_begin(struct lttng_ust_lib_ring_buffer *buf, uint64_t
 				subbuf_idx * chan->backend.subbuf_size,
 				handle);
 	struct lttng_channel *lttng_chan = channel_get_private(chan);
+	unsigned long seq_num_offset =
+		get_count_order64(chan->backend.subbuf_size);
+	unsigned int field_size = sizeof(header->ctx.packet_seq_num) * CHAR_BIT;
 
 	header->magic = CTF_MAGIC_NUMBER;
 	memcpy(header->uuid, lttng_chan->uuid, sizeof(lttng_chan->uuid));
@@ -348,6 +352,14 @@ static void client_buffer_begin(struct lttng_ust_lib_ring_buffer *buf, uint64_t
 	header->ctx.timestamp_end = 0;
 	header->ctx.content_size = ~0ULL; /* for debugging */
 	header->ctx.packet_size = ~0ULL;
+	header->ctx.packet_seq_num = 0;
+	/*
+	 * vread returns an unsigned long, the bt_bitfield_write adds the
+	 * complement of padding.
+	 */
+	bt_bitfield_write(&header->ctx.packet_seq_num, unsigned long,
+			seq_num_offset, field_size - seq_num_offset,
+			v_read(&client_config, &buf->offset) >> seq_num_offset);
 	header->ctx.events_discarded = 0;
 	header->ctx.cpu_id = buf->backend.cpu;
 }
@@ -488,6 +500,22 @@ static int client_current_timestamp(struct lttng_ust_lib_ring_buffer *buf,
 	return 0;
 }
 
+static int client_sequence_number(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *seq)
+{
+	struct packet_header *header;
+	struct channel *chan;
+
+	header = client_packet_header(buf, handle);
+	chan = shmp(handle, handle->chan);
+
+	*seq = header->ctx.packet_seq_num >>
+		(get_count_order64(chan->backend.subbuf_size));
+
+	return 0;
+}
+
 static const
 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
 	.parent = {
@@ -508,6 +536,7 @@ struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
 	.packet_size = client_packet_size,
 	.stream_id = client_stream_id,
 	.current_timestamp = client_current_timestamp,
+	.sequence_number = client_sequence_number,
 };
 
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
libringbuffer/backend_internal.h +43 -0

53 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

PATCH 3/3 Export the stream instance ID.

In reply to a message not in the archive

Allow the lttng-consumer to query the stream instance ID.

---
 include/lttng/ust-ctl.h                 |  2 ++
 liblttng-ust-ctl/ustctl.c               | 18 ++++++++++++++++++
 liblttng-ust/lttng-rb-clients.h         |  2 ++
 liblttng-ust/lttng-ring-buffer-client.h | 13 +++++++++++++
 4 files changed, 35 insertions(+)
include/lttng/ust-ctl.h +2 -0
index d27ca8a..b246a51 100644
@@ -243,6 +243,8 @@ int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
 		uint64_t *ts);
 int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
 		uint64_t *seq);
+int ustctl_get_instance_id(struct ustctl_consumer_stream *stream,
+		uint64_t *id);
 
 /* returns whether UST has perf counters support. */
 int ustctl_has_perf_counters(void);
liblttng-ust-ctl/ustctl.c +18 -0
index 010dfd8..43fce9e 100644
@@ -1663,6 +1663,24 @@ int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
 	return client_cb->sequence_number(buf, handle, seq);
 }
 
+int ustctl_get_instance_id(struct ustctl_consumer_stream *stream,
+		uint64_t *id)
+{
+	struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb;
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct lttng_ust_shm_handle *handle;
+
+	if (!stream || !id)
+		return -EINVAL;
+	buf = stream->buf;
+	handle = stream->chan->chan->handle;
+	client_cb = get_client_cb(buf, handle);
+	if (!client_cb)
+		return -ENOSYS;
+	return client_cb->instance_id(buf, handle, id);
+}
+
+
 #if defined(__x86_64__) || defined(__i386__)
 
 int ustctl_has_perf_counters(void)
liblttng-ust/lttng-rb-clients.h +2 -0
index 788f075..e54decb 100644
@@ -45,6 +45,8 @@ struct lttng_ust_client_lib_ring_buffer_client_cb {
 			uint64_t *ts);
 	int (*sequence_number) (struct lttng_ust_lib_ring_buffer *buf,
 		struct lttng_ust_shm_handle *handle, uint64_t *seq);
+	int (*instance_id) (struct lttng_ust_lib_ring_buffer *buf,
+			struct lttng_ust_shm_handle *handle, uint64_t *id);
 };
 
 #endif /* _LTTNG_RB_CLIENT_H */
liblttng-ust/lttng-ring-buffer-client.h +13 -0
index 1e93cff..63df2f9 100644
@@ -516,6 +516,18 @@ static int client_sequence_number(struct lttng_ust_lib_ring_buffer *buf,
 	return 0;
 }
 
+static int client_instance_id(struct lttng_ust_lib_ring_buffer *buf,
+		struct lttng_ust_shm_handle *handle,
+		uint64_t *id)
+{
+	struct packet_header *header;
+
+	header = client_packet_header(buf, handle);
+	*id = header->stream_instance_id;
+	return 0;
+}
+
+
 static const
 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
 	.parent = {
@@ -537,6 +549,7 @@ struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
 	.stream_id = client_stream_id,
 	.current_timestamp = client_current_timestamp,
 	.sequence_number = client_sequence_number,
+	.instance_id = client_instance_id,
 };
 
 static const struct lttng_ust_lib_ring_buffer_config client_config = {
Signature · 1 line
1.9.1