Add comm context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 May 2011 02:54:11 +0000 (22:54 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 26 May 2011 02:54:11 +0000 (22:54 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Makefile
ltt-debugfs-abi.c
ltt-debugfs-abi.h
ltt-events.h
lttng-context-comm.c [new file with mode: 0644]

index 01b0e7ee1b02d0f45e08b305cf45b77b98a9f7b5..8f364dbff965994e3176f96af7974aeb6f3e4c09 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ obj-m += ltt-ring-buffer-metadata-client.o
 obj-m += ltt-relay.o
 ltt-relay-objs :=  ltt-events.o ltt-debugfs-abi.o \
                        ltt-probes.o ltt-core.o ltt-context.o \
-                       lttng-context-pid.o
+                       lttng-context-pid.o lttng-context-comm.o
 
 obj-m += probes/
 obj-m += lib/
index 730826674cda7a82ccce3da3d9a4779eb078f6d2..afdc09a61ad8eb0dcc1e39be75ec8be03d6a2169 100644 (file)
@@ -154,6 +154,8 @@ long lttng_abi_add_context(struct file *file,
                return lttng_add_pid_to_ctx(ctx);
        case LTTNG_KERNEL_CONTEXT_PERF_COUNTER:
                return -ENOSYS;
+       case LTTNG_KERNEL_CONTEXT_COMM:
+               return lttng_add_comm_to_ctx(ctx);
        default:
                return -EINVAL;
        }
index ddc50ba5b9643ee20026de3aaaf57770627bad87..2768055f29b483788545ca5b3c44949478920942 100644 (file)
@@ -31,9 +31,6 @@ struct lttng_kernel_channel {
        unsigned int read_timer_interval;       /* usecs */
 };
 
-struct lttng_kernel_tracepoint {
-};
-
 /*
  * Either addr is used, or symbol_name and offset.
  */
@@ -53,7 +50,6 @@ struct lttng_kernel_event {
        enum lttng_kernel_instrumentation instrumentation;
        /* Per instrumentation type configuration */
        union {
-               struct lttng_kernel_tracepoint tracepoint;
                struct lttng_kernel_kprobe kprobe;
                struct lttng_kernel_function_tracer ftrace;
        } u;
@@ -68,9 +64,7 @@ struct lttng_kernel_tracer_version {
 enum lttng_kernel_context_type {
        LTTNG_KERNEL_CONTEXT_PID,
        LTTNG_KERNEL_CONTEXT_PERF_COUNTER,
-};
-
-struct lttng_kernel_pid_ctx {
+       LTTNG_KERNEL_CONTEXT_COMM,
 };
 
 struct lttng_kernel_perf_counter_ctx {
@@ -81,7 +75,6 @@ struct lttng_kernel_perf_counter_ctx {
 struct lttng_kernel_context {
        enum lttng_kernel_context_type ctx;
        union {
-               struct lttng_kernel_pid_ctx pid;
                struct lttng_kernel_perf_counter_ctx perf_counter;
        } u;
 };
index a5a57fcdf016c868c5ee0fe50f31afb2e07efd6d..2b6ef40a42978de5274db70e900b497144a50431 100644 (file)
@@ -273,6 +273,7 @@ void ltt_probes_exit(void);
 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
 void lttng_destroy_context(struct lttng_ctx *ctx);
 int lttng_add_pid_to_ctx(struct lttng_ctx **ctx);
+int lttng_add_comm_to_ctx(struct lttng_ctx **ctx);
 
 #ifdef CONFIG_KPROBES
 int lttng_kprobes_register(const char *name,
diff --git a/lttng-context-comm.c b/lttng-context-comm.c
new file mode 100644 (file)
index 0000000..6e51bf8
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * (C) Copyright       2009-2011 -
+ *             Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng comm name context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t comm_get_size(size_t offset)
+{
+       size_t size = 0;
+
+       size += sizeof(current->comm);
+       return size;
+}
+
+/*
+ * Racy read of comm. We simply copy its whole array size.
+ * Races with /proc/<task>/comm write only.
+ * Otherwise having to take a mutex for each event is cumbersome and
+ * could lead to crash in IRQ context and deadlock of the lockdep tracer.
+ */
+static
+void comm_record(struct lttng_ctx_field *field,
+                struct lib_ring_buffer_ctx *ctx,
+                struct ltt_channel *chan)
+{
+       chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
+}
+
+int lttng_add_comm_to_ctx(struct lttng_ctx **ctx)
+{
+       struct lttng_ctx_field *field;
+       int ret;
+
+       field = lttng_append_context(ctx);
+       if (!field)
+               return ret;
+       field->event_field.name = "comm";
+       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 = ltt_alignof(char) * CHAR_BIT;
+       field->event_field.type.u.array.elem_type.u.basic.integer.signedness = 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 = sizeof(current->comm);
+
+       field->get_size = comm_get_size;
+       field->record = comm_record;
+       wrapper_vmalloc_sync_all();
+       return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_comm_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
This page took 0.029136 seconds and 4 git commands to generate.