callsite: add "ip" context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Oct 2012 17:00:57 +0000 (13:00 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 16 Oct 2012 17:00:57 +0000 (13:00 -0400)
Add caller's instruction pointer context.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ringbuffer-config.h
include/lttng/tracepoint.h
include/lttng/ust-abi.h
include/lttng/ust-events.h
include/lttng/ust-tracepoint-event.h
liblttng-ust/Makefile.am
liblttng-ust/lttng-context-ip.c [new file with mode: 0644]
liblttng-ust/lttng-ust-abi.c

index 174906cbafcdea9469601ba39a996bde3f2ecc26..ab5e9f9913aaf2c8ef7e578e6433d8a8fea41fcc 100644 (file)
@@ -193,7 +193,8 @@ struct lttng_ust_lib_ring_buffer_config {
  * UST. Fields need to be only added at the end, never reordered, never
  * removed.
  */
-#define LTTNG_UST_RING_BUFFER_CTX_PADDING      24
+#define LTTNG_UST_RING_BUFFER_CTX_PADDING      \
+               (24 - sizeof(int) - sizeof(void *))
 struct lttng_ust_lib_ring_buffer_ctx {
        /* input received by lib_ring_buffer_reserve(), saved here. */
        struct channel *chan;           /* channel */
@@ -221,7 +222,9 @@ struct lttng_ust_lib_ring_buffer_ctx {
                                         */
        uint64_t tsc;                   /* time-stamp counter value */
        unsigned int rflags;            /* reservation flags */
-       char padding[LTTNG_UST_RING_BUFFER_CTX_PADDING];
+       unsigned int padding1;          /* padding to realign on pointer */
+       void *ip;                       /* caller ip address */
+       char padding2[LTTNG_UST_RING_BUFFER_CTX_PADDING];
 };
 
 /**
@@ -251,7 +254,9 @@ void lib_ring_buffer_ctx_init(struct lttng_ust_lib_ring_buffer_ctx *ctx,
        ctx->cpu = cpu;
        ctx->rflags = 0;
        ctx->handle = handle;
-       memset(ctx->padding, 0, LTTNG_UST_RING_BUFFER_CTX_PADDING);
+       ctx->padding1 = 0;
+       ctx->ip = 0;
+       memset(ctx->padding2, 0, LTTNG_UST_RING_BUFFER_CTX_PADDING);
 }
 
 /*
index 8e4704c47f3e264e653b1539f45e30234f4080cf..7d98e22e9ac1d60678822e0a74dc11d509fb7c67 100644 (file)
@@ -138,11 +138,16 @@ extern "C" {
 #define _TP_ARGS_DATA_VAR(...)         _TP_DATA_VAR_N(_TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__)
 #define _TP_PARAMS(...)                        __VA_ARGS__
 
+/*
+ * The tracepoint cb is marked always inline so we can distinguish
+ * between caller's ip addresses within the probe using the return
+ * address.
+ */
 #define _DECLARE_TRACEPOINT(_provider, _name, ...)                                     \
 extern struct tracepoint __tracepoint_##_provider##___##_name;                         \
-static inline lttng_ust_notrace                                                                \
+static inline __attribute__((always_inline)) lttng_ust_notrace                         \
 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__));             \
-static inline                                                                          \
+static                                                                                 \
 void __tracepoint_cb_##_provider##___##_name(_TP_ARGS_PROTO(__VA_ARGS__))              \
 {                                                                                      \
        struct tracepoint_probe *__tp_probe;                                            \
index c9be4bd9d29fda9d8268a8d3531774d253f6e791..2b3d402dcbed4d9b16bbf5214a76dcfe3acfb891 100644 (file)
@@ -114,6 +114,7 @@ enum lttng_ust_context_type {
        LTTNG_UST_CONTEXT_VPID                  = 1,
        LTTNG_UST_CONTEXT_PTHREAD_ID            = 2,
        LTTNG_UST_CONTEXT_PROCNAME              = 3,
+       LTTNG_UST_CONTEXT_IP                    = 4,
 };
 
 #define LTTNG_UST_CONTEXT_PADDING1     16
index b076835794126345eb4f7f1d3b2e0444818a5bca..ad4ee39124ac22557f2b0e084ba701411b393e8b 100644 (file)
@@ -484,6 +484,7 @@ int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_ip_to_ctx(struct lttng_ctx **ctx);
 void lttng_context_vtid_reset(void);
 void lttng_context_vpid_reset(void);
 
index 8f0db41fc3c7c5490a38d5186661b7f68005c1af..da077b7c40f5d6657cff639581321d280b40ff95 100644 (file)
@@ -493,6 +493,7 @@ void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args))           \
        __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
        lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len,  \
                                 __event_align, -1, __chan->handle);          \
+       __ctx.ip = __builtin_return_address(0);                               \
        __ret = __chan->ops->event_reserve(&__ctx, __event->id);              \
        if (__ret < 0)                                                        \
                return;                                                       \
index dff8b6e9f425a00195784fff185b47f0aa9995b1..74963318047697630868e5b0c7df4362e81f3192 100644 (file)
@@ -26,6 +26,7 @@ liblttng_ust_runtime_la_SOURCES = \
        lttng-context-vpid.c \
        lttng-context-pthread-id.c \
        lttng-context-procname.c \
+       lttng-context-ip.c \
        ltt-context.c \
        ltt-events.c \
        lttng-filter.c \
diff --git a/liblttng-ust/lttng-context-ip.c b/liblttng-ust/lttng-context-ip.c
new file mode 100644 (file)
index 0000000..168e5cd
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * lttng-context-ip.c
+ *
+ * LTTng UST Instruction Pointer Context.
+ *
+ * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <lttng/ust-events.h>
+#include <lttng/ust-tracer.h>
+#include <lttng/ringbuffer-config.h>
+
+static
+size_t ip_get_size(size_t offset)
+{
+       size_t size = 0;
+
+       size += lib_ring_buffer_align(offset, lttng_alignof(void *));
+       size += sizeof(void *);
+       return size;
+}
+
+static
+void ip_record(struct lttng_ctx_field *field,
+                struct lttng_ust_lib_ring_buffer_ctx *ctx,
+                struct ltt_channel *chan)
+{
+       void *ip;
+
+       ip = ctx->ip;
+       lib_ring_buffer_align_ctx(ctx, lttng_alignof(ip));
+       chan->ops->event_write(ctx, &ip, sizeof(ip));
+}
+
+int lttng_add_ip_to_ctx(struct lttng_ctx **ctx)
+{
+       struct lttng_ctx_field *field;
+
+       field = lttng_append_context(ctx);
+       if (!field)
+               return -ENOMEM;
+       if (lttng_find_context(*ctx, "ip")) {
+               lttng_remove_context_field(ctx, field);
+               return -EEXIST;
+       }
+       field->event_field.name = "ip";
+       field->event_field.type.atype = atype_integer;
+       field->event_field.type.u.basic.integer.size = sizeof(void *) * CHAR_BIT;
+       field->event_field.type.u.basic.integer.alignment = lttng_alignof(void *) * CHAR_BIT;
+       field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(void *);
+       field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+       field->event_field.type.u.basic.integer.base = 16;
+       field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+       field->get_size = ip_get_size;
+       field->record = ip_record;
+       return 0;
+}
index 61d37ac8b172fc0f99c3eaef958640b8e1ee0a1a..4eb40959f4181c71a88d7c08d6afad2b17a94428 100644 (file)
@@ -286,6 +286,8 @@ long lttng_abi_add_context(int objd,
                return lttng_add_vpid_to_ctx(ctx);
        case LTTNG_UST_CONTEXT_PROCNAME:
                return lttng_add_procname_to_ctx(ctx);
+       case LTTNG_UST_CONTEXT_IP:
+               return lttng_add_ip_to_ctx(ctx);
        default:
                return -EINVAL;
        }
This page took 0.032155 seconds and 4 git commands to generate.