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

index ea7b87e655c244fbcc900c93fa31e80e0bf22336..a7726f090fd465b17defa44afb8fe305d4a30372 100644 (file)
@@ -317,11 +317,12 @@ const struct lttng_event_desc *ltt_event_get(const char *name);
 void ltt_event_put(const struct lttng_event_desc *desc);
 int ltt_probes_init(void);
 void ltt_probes_exit(void);
-struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
-void lttng_remove_context_field(struct lttng_ctx **ctx,
+int lttng_find_context(struct lttng_ctx *ctx, const char *name);
+struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
+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_pthread_id_to_ctx(struct lttng_ctx **ctx);
 
 //extern const struct file_operations lttng_tracepoint_list_fops;
 
index 0aba5c53549776d09e002340f7c15d531246dc9d..66837f5a8835a02361b512dcbef24e42a8ac96ee 100644 (file)
@@ -13,13 +13,14 @@ libust_la_SOURCES = \
        ltt-ring-buffer-metadata-client.h \
        ltt-ring-buffer-metadata-client.c \
        ltt-events.c \
-       ltt-context.c \
        ltt-probes.c \
        lttng-ust-abi.c \
        lttng-ust-comm.c \
        ust-core.c \
        probes/lttng-probe-ust.c \
-       probes/lttng-probe-ust.h
+       probes/lttng-probe-ust.h \
+       lttng-context-pthread-id.c \
+       ltt-context.c
 
 libust_la_LDFLAGS = -no-undefined -version-info 0:0:0
 
index 83aa297592929d9d900cb52940fd25974e62ae03..7f8351ecd478326e2ea1c462ca1dcd14b290c025 100644 (file)
@@ -3,15 +3,30 @@
  *
  * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * LTTng trace/channel/event context management.
+ * LTTng UST trace/channel/event context management.
  *
  * Dual LGPL v2.1/GPL v2 license.
  */
 
 #include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
 #include <ust/core.h>
 #include <string.h>
-#include <ust/usterr-signal-safe.h>
+#include <assert.h>
+
+int lttng_find_context(struct lttng_ctx *ctx, const char *name)
+{
+       unsigned int i;
+
+       for (i = 0; i < ctx->nr_fields; i++) {
+               /* Skip allocated (but non-initialized) contexts */
+               if (!ctx->fields[i].event_field.name)
+                       continue;
+               if (!strcmp(ctx->fields[i].event_field.name, name))
+                       return 1;
+       }
+       return 0;
+}
 
 /*
  * Note: as we append context information, the pointer location may change.
@@ -54,7 +69,7 @@ void lttng_remove_context_field(struct lttng_ctx **ctx_p,
 
        ctx = *ctx_p;
        ctx->nr_fields--;
-       WARN_ON_ONCE(&ctx->fields[ctx->nr_fields] != field);
+       assert(&ctx->fields[ctx->nr_fields] == field);
        memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field));
 }
 
diff --git a/libust/lttng-context-pthread-id.c b/libust/lttng-context-pthread-id.c
new file mode 100644 (file)
index 0000000..f65968b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright       2009-2011 -
+ *             Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng UST pthread_id context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <pthread.h>
+#include <ust/lttng-events.h>
+#include <ust/lttng-tracer.h>
+#include <ust/ringbuffer-config.h>
+
+static
+size_t pthread_id_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 pthread_id_record(struct lttng_ctx_field *field,
+                struct lib_ring_buffer_ctx *ctx,
+                struct ltt_channel *chan)
+{
+       unsigned long pthread_id;
+
+       pthread_id = (unsigned long) pthread_self();
+       lib_ring_buffer_align_ctx(ctx, lttng_alignof(pthread_id));
+       chan->ops->event_write(ctx, &pthread_id, sizeof(pthread_id));
+}
+
+int lttng_add_pthread_id_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, "pthread_id")) {
+               lttng_remove_context_field(ctx, field);
+               return -EEXIST;
+       }
+       field->event_field.name = "pthread_id";
+       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 = pthread_id_get_size;
+       field->record = pthread_id_record;
+       return 0;
+}
This page took 0.027875 seconds and 4 git commands to generate.