X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ring-buffer-client.h;h=1ebb14e48ff05e218994dbc8710eb566b22f9fcd;hb=ba1c40c6095cdcb25c9c3be8bd72b09755f1f116;hp=79085e57a55e7dd73e4fa71b01c4b2aa21bd5142;hpb=a9ff648cc4cc06d28b522d705c467d45ab916a9d;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 79085e57..1ebb14e4 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -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; } @@ -110,13 +112,13 @@ void ctx_record(struct lttng_ust_lib_ring_buffer_ctx *bufctx, * contains. */ static __inline__ -unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, +size_t record_header_size(const struct lttng_ust_lib_ring_buffer_config *config, struct channel *chan, size_t offset, size_t *pre_header_padding, struct lttng_ust_lib_ring_buffer_ctx *ctx) { struct lttng_channel *lttng_chan = channel_get_private(chan); - struct lttng_event *event = ctx->priv; + struct lttng_stack_ctx *lttng_ctx = ctx->priv2; size_t orig_offset = offset; size_t padding; @@ -155,8 +157,8 @@ unsigned char record_header_size(const struct lttng_ust_lib_ring_buffer_config * padding = 0; WARN_ON_ONCE(1); } - offset += ctx_get_size(offset, event->ctx); - offset += ctx_get_size(offset, lttng_chan->ctx); + offset += ctx_get_size(offset, lttng_ctx->chan_ctx); + offset += ctx_get_size(offset, lttng_ctx->event_ctx); *pre_header_padding = padding; 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,14 +340,20 @@ 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) + return; 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; } @@ -366,6 +374,9 @@ static void client_buffer_end(struct lttng_ust_lib_ring_buffer *buf, uint64_t ts handle); unsigned long records_lost = 0; + assert(header); + if (!header) + return; header->ctx.timestamp_end = tsc; header->ctx.content_size = (uint64_t) data_size * CHAR_BIT; /* in bits */ @@ -415,6 +426,8 @@ static int client_timestamp_begin(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *timestamp_begin = header->ctx.timestamp_begin; return 0; } @@ -426,6 +439,8 @@ static int client_timestamp_end(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *timestamp_end = header->ctx.timestamp_end; return 0; } @@ -437,6 +452,8 @@ static int client_events_discarded(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *events_discarded = header->ctx.events_discarded; return 0; } @@ -448,6 +465,8 @@ static int client_content_size(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *content_size = header->ctx.content_size; return 0; } @@ -459,6 +478,8 @@ static int client_packet_size(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *packet_size = header->ctx.packet_size; return 0; } @@ -470,6 +491,8 @@ static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf, struct packet_header *header; header = client_packet_header(buf, handle); + if (!header) + return -1; *stream_id = header->stream_id; return 0; } @@ -486,6 +509,28 @@ 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 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 = { @@ -506,6 +551,8 @@ 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, + .instance_id = client_instance_id, }; static const struct lttng_ust_lib_ring_buffer_config client_config = { @@ -543,7 +590,7 @@ struct lttng_channel *_channel_create(const char *name, unsigned int read_timer_interval, unsigned char *uuid, uint32_t chan_id, - const char *shm_path) + const int *stream_fds, int nr_stream_fds) { struct lttng_channel chan_priv_init; struct lttng_ust_shm_handle *handle; @@ -559,7 +606,7 @@ struct lttng_channel *_channel_create(const char *name, &chan_priv_init, buf_addr, subbuf_size, num_subbuf, switch_timer_interval, read_timer_interval, - shm_path); + stream_fds, nr_stream_fds); if (!handle) return NULL; lttng_chan = priv;