From f167620537b558f8fabd6912d4ea5c46a92cd877 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 25 May 2011 18:15:38 -0400 Subject: [PATCH] Write context fields into trace Signed-off-by: Mathieu Desnoyers --- ltt-events.h | 8 +++++++- ltt-ring-buffer-client.h | 40 ++++++++++++++++++++++++++++++++++++ probes/lttng-context-pid.c | 13 +++++++++++- probes/lttng-events.h | 2 +- probes/lttng-ftrace.c | 2 +- probes/lttng-kprobes.c | 2 +- probes/lttng-perf-counters.c | 13 +++++++++++- 7 files changed, 74 insertions(+), 6 deletions(-) diff --git a/ltt-events.h b/ltt-events.h index 1a5b5d5c..bea5af1c 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -120,7 +120,10 @@ struct lttng_event_field { struct lttng_ctx_field { const char *name; struct lttng_type type; - void *callback; + size_t (*get_size)(size_t offset); + void (*record)(struct lttng_ctx_field *field, + struct lib_ring_buffer_ctx *ctx, + struct ltt_channel *chan); union { struct { struct perf_event **e; /* per-cpu array */ @@ -161,6 +164,7 @@ struct ltt_event { struct ltt_channel *chan; const struct lttng_event_desc *desc; void *filter; + struct lttng_ctx *ctx; enum lttng_kernel_instrumentation instrumentation; union { struct { @@ -202,6 +206,7 @@ struct ltt_channel_ops { struct ltt_channel { unsigned int id; struct channel *chan; /* Channel buffers */ + struct lttng_ctx *ctx; /* Event ID management */ struct ltt_session *session; struct file *file; /* File associated to channel */ @@ -215,6 +220,7 @@ struct ltt_channel { struct ltt_session { int active; /* Is trace session active ? */ + struct lttng_ctx *ctx; struct file *file; /* File associated to session */ struct ltt_channel *metadata; /* Metadata channel */ struct list_head chan; /* Channel list head */ diff --git a/ltt-ring-buffer-client.h b/ltt-ring-buffer-client.h index 1c3d014d..8095eb6e 100644 --- a/ltt-ring-buffer-client.h +++ b/ltt-ring-buffer-client.h @@ -55,6 +55,32 @@ static inline notrace u64 lib_ring_buffer_clock_read(struct channel *chan) return trace_clock_read64(); } +static inline +size_t ctx_get_size(size_t offset, struct lttng_ctx *ctx) +{ + int i; + size_t orig_offset = offset; + + if (likely(!ctx)) + return 0; + for (i = 0; i < ctx->nr_fields; i++) + offset += ctx->fields[i].get_size(offset); + return offset - orig_offset; +} + +static inline +void ctx_record(struct lib_ring_buffer_ctx *bufctx, + struct ltt_channel *chan, + struct lttng_ctx *ctx) +{ + int i; + + if (likely(!ctx)) + return; + for (i = 0; i < ctx->nr_fields; i++) + ctx->fields[i].record(&ctx->fields[i], bufctx, chan); +} + /* * record_header_size - Calculate the header size and padding necessary. * @config: ring buffer instance configuration @@ -75,6 +101,7 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, struct lib_ring_buffer_ctx *ctx) { struct ltt_channel *ltt_chan = channel_get_private(chan); + struct ltt_event *event = ctx->priv; size_t orig_offset = offset; size_t padding; @@ -113,6 +140,9 @@ unsigned char record_header_size(const struct lib_ring_buffer_config *config, default: WARN_ON_ONCE(1); } + offset += ctx_get_size(offset, event->ctx); + offset += ctx_get_size(offset, ltt_chan->ctx); + offset += ctx_get_size(offset, ltt_chan->session->ctx); *pre_header_padding = padding; return offset - orig_offset; @@ -140,6 +170,7 @@ void ltt_write_event_header(const struct lib_ring_buffer_config *config, uint32_t event_id) { struct ltt_channel *ltt_chan = channel_get_private(ctx->chan); + struct ltt_event *event = ctx->priv; if (unlikely(ctx->rflags)) goto slow_path; @@ -166,6 +197,11 @@ void ltt_write_event_header(const struct lib_ring_buffer_config *config, default: WARN_ON_ONCE(1); } + + ctx_record(ctx, ltt_chan, event->ctx); + ctx_record(ctx, ltt_chan, ltt_chan->ctx); + ctx_record(ctx, ltt_chan, ltt_chan->session->ctx); + return; slow_path: @@ -177,6 +213,7 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, uint32_t event_id) { struct ltt_channel *ltt_chan = channel_get_private(ctx->chan); + struct ltt_event *event = ctx->priv; switch (ltt_chan->header_type) { case 1: /* compact */ @@ -223,6 +260,9 @@ void ltt_write_event_header_slow(const struct lib_ring_buffer_config *config, default: WARN_ON_ONCE(1); } + ctx_record(ctx, ltt_chan, event->ctx); + ctx_record(ctx, ltt_chan, ltt_chan->ctx); + ctx_record(ctx, ltt_chan, ltt_chan->session->ctx); } static const struct lib_ring_buffer_config client_config; diff --git a/probes/lttng-context-pid.c b/probes/lttng-context-pid.c index 669e593f..adb14c36 100644 --- a/probes/lttng-context-pid.c +++ b/probes/lttng-context-pid.c @@ -15,6 +15,16 @@ #include "../wrapper/vmalloc.h" #include "../ltt-tracer.h" +static +size_t pid_get_size(size_t offset) +{ + size_t size = 0; + + size += lib_ring_buffer_align(offset, ltt_alignof(pid_t)); + size += sizeof(pid_t); + return size; +} + static void pid_record(struct lttng_ctx_field *field, struct lib_ring_buffer_ctx *ctx, @@ -43,7 +53,8 @@ int lttng_add_pid_to_ctx(struct lttng_ctx **ctx) field->type.u.basic.integer.reverse_byte_order = 0; field->type.u.basic.integer.base = 10; field->type.u.basic.integer.encoding = lttng_encode_none; - field->callback = pid_record; + field->get_size = pid_get_size; + field->record = pid_record; wrapper_vmalloc_sync_all(); return 0; } diff --git a/probes/lttng-events.h b/probes/lttng-events.h index beedb22b..b32921ca 100644 --- a/probes/lttng-events.h +++ b/probes/lttng-events.h @@ -521,7 +521,7 @@ static void __event_probe__##_name(void *__data, _proto) \ return; \ __event_len = __event_get_size__##_name(__dynamic_len, _args); \ __event_align = __event_get_align__##_name(_args); \ - lib_ring_buffer_ctx_init(&ctx, __chan->chan, NULL, __event_len, \ + lib_ring_buffer_ctx_init(&ctx, __chan->chan, __event, __event_len, \ __event_align, -1); \ __ret = __chan->ops->event_reserve(&ctx, __event->id); \ if (__ret < 0) \ diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index c18a4702..476d6bce 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -36,7 +36,7 @@ void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip, void **data if (!ACCESS_ONCE(chan->session->active)) return; - lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, + lib_ring_buffer_ctx_init(&ctx, chan->chan, event, sizeof(payload), ltt_alignof(payload), -1); ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 481807de..89cfe073 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -27,7 +27,7 @@ int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) if (!ACCESS_ONCE(chan->session->active)) return 0; - lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, sizeof(data), + lib_ring_buffer_ctx_init(&ctx, chan->chan, event, sizeof(data), ltt_alignof(data), -1); ret = chan->ops->event_reserve(&ctx, event->id); if (ret < 0) diff --git a/probes/lttng-perf-counters.c b/probes/lttng-perf-counters.c index 740c1d94..06a4a7ce 100644 --- a/probes/lttng-perf-counters.c +++ b/probes/lttng-perf-counters.c @@ -23,6 +23,16 @@ static DEFINE_MUTEX(perf_counter_mutex); static LIST_HEAD(perf_counter_contexts); +static +size_t perf_counter_get_size(size_t offset) +{ + size_t size = 0; + + size += lib_ring_buffer_align(offset, ltt_alignof(uint64_t)); + size += sizeof(uint64_t); + return size; +} + static void perf_counter_record(struct lttng_ctx_field *field, struct lib_ring_buffer_ctx *ctx, @@ -112,7 +122,8 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->type.u.basic.integer.reverse_byte_order = 0; field->type.u.basic.integer.base = 10; field->type.u.basic.integer.encoding = lttng_encode_none; - field->callback = perf_counter_record; + field->get_size = perf_counter_get_size; + field->record = perf_counter_record; field->u.perf_counter.e = events; field->u.perf_counter.attr = attr; -- 2.34.1