Write context fields into trace
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 22:15:38 +0000 (18:15 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 22:15:38 +0000 (18:15 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ltt-events.h
ltt-ring-buffer-client.h
probes/lttng-context-pid.c
probes/lttng-events.h
probes/lttng-ftrace.c
probes/lttng-kprobes.c
probes/lttng-perf-counters.c

index 1a5b5d5cf6c196252458ae18ec65d8fb57637baf..bea5af1c988eeeb4e0539b6f2a34c46ec1205b22 100644 (file)
@@ -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 */
index 1c3d014d43cd8248a2aca5d65faff48f8935193a..8095eb6e73abf53a242abafc424559f7ddb3f54a 100644 (file)
@@ -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;
index 669e593fa1d50152362d191955118266f585b458..adb14c3604a72ead0ca08e414cc1b374ff604bb4 100644 (file)
 #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;
 }
index beedb22b6bb4bce475dfb0ee03bd9f9ec389534f..b32921ca67121fb2c3c89654fecebb60ac3ebd0e 100644 (file)
@@ -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)                                                        \
index c18a4702c90be4d8df6ef06490b2445385ed7e4d..476d6bce8e50600e0a6691317e3fd39d044c1c1b 100644 (file)
@@ -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)
index 481807de92a2796a36a1033fec6189ca7e2a97ff..89cfe07364779f6a2094979b16c6f039252fac89 100644 (file)
@@ -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)
index 740c1d9424ca3d98795c825065ec0c5a5b4f6bb5..06a4a7cebfff85cae03e29d67c73e82cb6686256 100644 (file)
 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;
 
This page took 0.030377 seconds and 4 git commands to generate.