Add procname context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Sep 2011 01:16:19 +0000 (21:16 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Sep 2011 01:16:19 +0000 (21:16 -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-procname.c [new file with mode: 0644]
libust/lttng-ust-abi.c
tests/ust-basic-tracing/ust-basic-tracing.c

index 0439ea7a18c4bab8d372e38ec63ff9a6d5292a14..e09443f10485bcec527263fd31e582ca64b0c81a 100644 (file)
@@ -323,6 +323,7 @@ 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);
+int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
 void lttng_context_vtid_reset(void);
 void lttng_context_vpid_reset(void);
 
index c967fb11188e432967bf186cd12450c27a7ccb28..303493eeb4e1404ea4241b7054c9f138813ab475 100644 (file)
@@ -69,6 +69,7 @@ enum lttng_ust_context_type {
        LTTNG_UST_CONTEXT_VTID                  = 0,
        LTTNG_UST_CONTEXT_VPID                  = 1,
        LTTNG_UST_CONTEXT_PTHREAD_ID            = 2,
+       LTTNG_UST_CONTEXT_PROCNAME              = 3,
 };
 
 struct lttng_ust_context {
index cb00e179dc7d8320b6f19e2d9a16a23839621459..9295d6b726a0e5b0f4cda60aba8e5aa65b7ff47a 100644 (file)
@@ -22,6 +22,7 @@ libust_la_SOURCES = \
        lttng-context-vtid.c \
        lttng-context-vpid.c \
        lttng-context-pthread-id.c \
+       lttng-context-procname.c \
        ltt-context.c
 
 libust_la_LDFLAGS = -no-undefined -version-info 0:0:0
diff --git a/libust/lttng-context-procname.c b/libust/lttng-context-procname.c
new file mode 100644 (file)
index 0000000..2056d19
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * (C) Copyright       2009-2011 -
+ *             Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng UST procname context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <sys/prctl.h>
+#include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
+#include <ust/ringbuffer-config.h>
+#include <assert.h>
+
+#define PROCNAME_LEN   17      /* includes \0 */
+
+/*
+ * We cache the result to ensure we don't trigger a system call for
+ * each event.
+ * Upon exec, procname changes, but exec takes care of throwing away
+ * this cached version.
+ */
+static char cached_procname[17];
+
+static inline
+char *wrapper_getprocname(void)
+{
+       int ret;
+
+       if (unlikely(!cached_procname[0])) {
+               ret = prctl(PR_GET_NAME, (unsigned long) cached_procname,
+                       0, 0, 0);
+               assert(!ret);
+       }
+       return cached_procname;
+}
+
+void lttng_context_procname_reset(void)
+{
+       cached_procname[0] = '\0';
+}
+
+static
+size_t procname_get_size(size_t offset)
+{
+       size_t size = 0;
+
+       size += PROCNAME_LEN;
+       return size;
+}
+
+static
+void procname_record(struct lttng_ctx_field *field,
+                struct lib_ring_buffer_ctx *ctx,
+                struct ltt_channel *chan)
+{
+       char *procname;
+
+       procname = wrapper_getprocname();
+       chan->ops->event_write(ctx, procname, PROCNAME_LEN);
+}
+
+int lttng_add_procname_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, "procname")) {
+               lttng_remove_context_field(ctx, field);
+               return -EEXIST;
+       }
+       field->event_field.name = "procname";
+       field->event_field.type.atype = atype_array;
+       field->event_field.type.u.array.elem_type.atype = atype_integer;
+       field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
+       field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
+       field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
+       field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
+       field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
+       field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
+       field->event_field.type.u.array.length = PROCNAME_LEN;
+       field->get_size = procname_get_size;
+       field->record = procname_record;
+       return 0;
+}
index e125ac6d0eec37dc4151e3d178faef04a26d8fec..1d32e777be7c62126f44c7281c0d4539c5835660 100644 (file)
@@ -278,6 +278,8 @@ long lttng_abi_add_context(int objd,
                return lttng_add_vtid_to_ctx(ctx);
        case LTTNG_UST_CONTEXT_VPID:
                return lttng_add_vpid_to_ctx(ctx);
+       case LTTNG_UST_CONTEXT_PROCNAME:
+               return lttng_add_procname_to_ctx(ctx);
        default:
                return -EINVAL;
        }
index d200b4f98f50566eb4bc031d0d749f73e3705cad..e97552a13ba1d4f00643e12fa1d4c79c5d81d8fa 100644 (file)
@@ -571,6 +571,8 @@ int send_app_msgs(int sock, const char *outputpath,
        lum.cmd = LTTNG_UST_CONTEXT;
        lum.u.context.ctx = LTTNG_UST_CONTEXT_VTID;
        //lum.u.context.ctx = LTTNG_UST_CONTEXT_PTHREAD_ID;
+       //lum.u.context.ctx = LTTNG_UST_CONTEXT_VPID;
+       //lum.u.context.ctx = LTTNG_UST_CONTEXT_PROCNAME;
        ret = send_app_cmd(sock, &lum, &lur);
        if (ret)
                return ret;
This page took 0.041367 seconds and 4 git commands to generate.