Generate and export the sequence number
[lttng-ust.git] / liblttng-ust / lttng-ring-buffer-client.h
index 3f1e2656437a13b20d4fcbfd8f2b429622b83c78..07dc4700afdd842066a03ccd41c460db1f7f949a 100644 (file)
@@ -45,6 +45,7 @@ struct packet_header {
                                         */
        uint8_t uuid[LTTNG_UST_UUID_LEN];
        uint32_t stream_id;
+       uint64_t stream_instance_id;
 
        struct {
                /* Stream packet context */
@@ -52,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.
@@ -78,7 +80,7 @@ size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx)
                return 0;
        offset += lib_ring_buffer_align(offset, ctx->largest_align);
        for (i = 0; i < ctx->nr_fields; i++)
-               offset += ctx->fields[i].get_size(offset);
+               offset += ctx->fields[i].get_size(&ctx->fields[i], offset);
        return offset - orig_offset;
 }
 
@@ -185,7 +187,7 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con
                            uint32_t event_id)
 {
        struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
-       struct lttng_event *event = ctx->priv;
+       struct lttng_stack_ctx *lttng_ctx = ctx->priv2;
 
        if (caa_unlikely(ctx->rflags))
                goto slow_path;
@@ -220,8 +222,8 @@ void lttng_write_event_header(const struct lttng_ust_lib_ring_buffer_config *con
                WARN_ON_ONCE(1);
        }
 
-       ctx_record(ctx, lttng_chan, lttng_chan->ctx);
-       ctx_record(ctx, lttng_chan, event->ctx);
+       ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx);
        lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
 
        return;
@@ -236,7 +238,7 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
                                 uint32_t event_id)
 {
        struct lttng_channel *lttng_chan = channel_get_private(ctx->chan);
-       struct lttng_event *event = ctx->priv;
+       struct lttng_stack_ctx *lttng_ctx = ctx->priv2;
 
        switch (lttng_chan->header_type) {
        case 1: /* compact */
@@ -293,8 +295,8 @@ void lttng_write_event_header_slow(const struct lttng_ust_lib_ring_buffer_config
        default:
                WARN_ON_ONCE(1);
        }
-       ctx_record(ctx, lttng_chan, lttng_chan->ctx);
-       ctx_record(ctx, lttng_chan, event->ctx);
+       ctx_record(ctx, lttng_chan, lttng_ctx->chan_ctx);
+       ctx_record(ctx, lttng_chan, lttng_ctx->event_ctx);
        lib_ring_buffer_align_ctx(ctx, ctx->largest_align);
 }
 
@@ -338,6 +340,7 @@ 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);
+       uint64_t cnt = shmp_index(handle, buf->backend.buf_cnt, subbuf_idx)->seq_cnt;
 
        assert(header);
        if (!header)
@@ -345,10 +348,12 @@ static void client_buffer_begin(struct lttng_ust_lib_ring_buffer *buf, uint64_t
        header->magic = CTF_MAGIC_NUMBER;
        memcpy(header->uuid, lttng_chan->uuid, sizeof(lttng_chan->uuid));
        header->stream_id = lttng_chan->id;
+       header->stream_instance_id = buf->backend.cpu;
        header->ctx.timestamp_begin = tsc;
        header->ctx.timestamp_end = 0;
        header->ctx.content_size = ~0ULL; /* for debugging */
        header->ctx.packet_size = ~0ULL;
+       header->ctx.packet_seq_num = chan->backend.num_subbuf * cnt + subbuf_idx;
        header->ctx.events_discarded = 0;
        header->ctx.cpu_id = buf->backend.cpu;
 }
@@ -504,6 +509,17 @@ 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;
+
+       header = client_packet_header(buf, handle);
+       *seq = header->ctx.packet_seq_num;
+       return 0;
+}
+
 static const
 struct lttng_ust_client_lib_ring_buffer_client_cb client_cb = {
        .parent = {
@@ -524,6 +540,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 = {
This page took 0.02558 seconds and 4 git commands to generate.