Add vpid context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Sep 2011 00:46:04 +0000 (20:46 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Sep 2011 00:46:04 +0000 (20:46 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/ust/lttng-events.h
include/ust/lttng-ust-abi.h
libust/Makefile.am
libust/lttng-context-vpid.c [new file with mode: 0644]
libust/lttng-ust-abi.c

index 6bb4e8cce10ef1b89b791a262b89a0f1cbc42387..0439ea7a18c4bab8d372e38ec63ff9a6d5292a14 100644 (file)
@@ -321,7 +321,9 @@ void lttng_remove_context_field(struct lttng_ctx **ctx_p,
                                struct lttng_ctx_field *field);
 void lttng_destroy_context(struct lttng_ctx *ctx);
 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);
 void lttng_context_vtid_reset(void);
+void lttng_context_vpid_reset(void);
 
 #endif /* _UST_LTTNG_EVENTS_H */
index 7146579129006b45995c1a27283881a1be159698..c967fb11188e432967bf186cd12450c27a7ccb28 100644 (file)
@@ -67,7 +67,8 @@ struct lttng_ust_event {
 
 enum lttng_ust_context_type {
        LTTNG_UST_CONTEXT_VTID                  = 0,
-       LTTNG_UST_CONTEXT_PTHREAD_ID            = 1,
+       LTTNG_UST_CONTEXT_VPID                  = 1,
+       LTTNG_UST_CONTEXT_PTHREAD_ID            = 2,
 };
 
 struct lttng_ust_context {
index 9857dd2d6f4d9ef3b8cd752353552aff2436ad1f..cb00e179dc7d8320b6f19e2d9a16a23839621459 100644 (file)
@@ -20,6 +20,7 @@ libust_la_SOURCES = \
        probes/lttng-probe-ust.c \
        probes/lttng-probe-ust.h \
        lttng-context-vtid.c \
+       lttng-context-vpid.c \
        lttng-context-pthread-id.c \
        ltt-context.c
 
diff --git a/libust/lttng-context-vpid.c b/libust/lttng-context-vpid.c
new file mode 100644 (file)
index 0000000..71395c9
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * (C) Copyright       2009-2011 -
+ *             Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng UST vpid context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
+#include <ust/ringbuffer-config.h>
+
+#ifdef __linux__
+static inline
+pid_t wrapper_getpid(void)
+{
+       return getpid();
+}
+
+void lttng_context_vpid_reset(void)
+{
+}
+#else
+/*
+ * We cache the result to ensure we don't trigger a system call for
+ * each event.
+ */
+static pid_t cached_vpid;
+
+static inline
+pid_t wrapper_getpid(void)
+{
+       if (unlikely(!cached_vpid))
+               cached_vpid = getpid();
+       return cached_vpid;
+}
+
+/*
+ * Upon fork or clone, the PID assigned to our thread is not the same as
+ * we kept in cache.
+ */
+void lttng_context_vpid_reset(void)
+{
+       cached_vpid = 0;
+}
+#endif
+
+static
+size_t vpid_get_size(size_t offset)
+{
+       size_t size = 0;
+
+       size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
+       size += sizeof(pid_t);
+       return size;
+}
+
+static
+void vpid_record(struct lttng_ctx_field *field,
+                struct lib_ring_buffer_ctx *ctx,
+                struct ltt_channel *chan)
+{
+       pid_t pid;
+
+       pid = wrapper_getpid();
+       lib_ring_buffer_align_ctx(ctx, lttng_alignof(pid));
+       chan->ops->event_write(ctx, &pid, sizeof(pid));
+}
+
+int lttng_add_vpid_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, "vpid")) {
+               lttng_remove_context_field(ctx, field);
+               return -EEXIST;
+       }
+       field->event_field.name = "vpid";
+       field->event_field.type.atype = atype_integer;
+       field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+       field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
+       field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t);
+       field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+       field->event_field.type.u.basic.integer.base = 10;
+       field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+       field->get_size = vpid_get_size;
+       field->record = vpid_record;
+       return 0;
+}
index 35c93c91b5e1b64bb088e3f601853b3353896170..e125ac6d0eec37dc4151e3d178faef04a26d8fec 100644 (file)
@@ -276,6 +276,8 @@ long lttng_abi_add_context(int objd,
                return lttng_add_pthread_id_to_ctx(ctx);
        case LTTNG_UST_CONTEXT_VTID:
                return lttng_add_vtid_to_ctx(ctx);
+       case LTTNG_UST_CONTEXT_VPID:
+               return lttng_add_vpid_to_ctx(ctx);
        default:
                return -EINVAL;
        }
This page took 0.026554 seconds and 4 git commands to generate.