Add PID context
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 21:33:56 +0000 (17:33 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 21:33:56 +0000 (17:33 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
ltt-context.c
ltt-events.h
probes/Makefile
probes/lttng-context-pid.c [new file with mode: 0644]
probes/lttng-ftrace.c
probes/lttng-kprobes.c
probes/lttng-perf-counters.c
probes/lttng.h

index cc9633ac08d63bdd46be0de4d62bf8a89e0fd76b..89e54bf80dd7980647018e63075b8692629ed601 100644 (file)
@@ -47,8 +47,10 @@ void lttng_destroy_context(struct lttng_ctx *ctx)
 {
        int i;
 
-       for (i = 0; i < ctx->nr_fields; i++)
-               ctx->fields[i].destroy(&ctx->fields[i]);
+       for (i = 0; i < ctx->nr_fields; i++) {
+               if (ctx->fields[i].destroy)
+                       ctx->fields[i].destroy(&ctx->fields[i]);
+       }
        kfree(ctx->fields);
        kfree(ctx);
 }
index bacef0a82e69c92f4dca34291a70db7426ccb86b..1a5b5d5cf6c196252458ae18ec65d8fb57637baf 100644 (file)
@@ -14,6 +14,9 @@
 #include <linux/kprobes.h>
 #include "ltt-debugfs-abi.h"
 
+#undef is_signed_type
+#define is_signed_type(type)           (((type)(-1)) < 0)
+
 struct ltt_channel;
 struct ltt_session;
 struct lib_ring_buffer_ctx;
index 554e6ffaf8e34c6a3a889786d3a126bbdc3fe46a..78c0c69903882a36d7d6c241a4c503eff7c8e885 100644 (file)
@@ -28,6 +28,8 @@ ifneq ($(CONFIG_PERF_EVENTS),)
 obj-m += lttng-perf-counters.o
 endif
 
+obj-m += lttng-context-pid.o
+
 endif
 
 else
diff --git a/probes/lttng-context-pid.c b/probes/lttng-context-pid.c
new file mode 100644 (file)
index 0000000..669e593
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * (C) Copyright       2009-2011 -
+ *             Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng PID 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
+void pid_record(struct lttng_ctx_field *field,
+               struct lib_ring_buffer_ctx *ctx,
+               struct ltt_channel *chan)
+{
+       pid_t pid;
+
+       pid = current->pid;
+       lib_ring_buffer_align_ctx(ctx, ltt_alignof(pid));
+       chan->ops->event_write(ctx, &pid, sizeof(pid));
+}
+
+int lttng_add_pid_to_ctx(struct lttng_ctx **ctx)
+{
+       struct lttng_ctx_field *field;
+       int ret;
+
+       field = lttng_append_context(ctx);
+       if (!field)
+               return ret;
+       field->name = "pid";
+       field->type.atype = atype_integer;
+       field->type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+       field->type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+       field->type.u.basic.integer.signedness = is_signed_type(pid_t);
+       field->type.u.basic.integer.reverse_byte_order = 0;
+       field->type.u.basic.integer.base = 10;
+       field->type.u.basic.integer.encoding = lttng_encode_none;
+       field->callback = pid_record;
+       wrapper_vmalloc_sync_all();
+       return 0;
+}
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
index ec086902892d644fcee8c57f70d78231cc4944f2..c18a4702c90be4d8df6ef06490b2445385ed7e4d 100644 (file)
@@ -78,7 +78,7 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event)
        fields[0].type.atype = atype_integer;
        fields[0].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT;
        fields[0].type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT;
-       fields[0].type.u.basic.integer.signedness = 0;
+       fields[0].type.u.basic.integer.signedness = is_signed_type(unsigned long);
        fields[0].type.u.basic.integer.reverse_byte_order = 0;
        fields[0].type.u.basic.integer.base = 16;
        fields[0].type.u.basic.integer.encoding = lttng_encode_none;
@@ -87,7 +87,7 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event)
        fields[1].type.atype = atype_integer;
        fields[1].type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT;
        fields[1].type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT;
-       fields[1].type.u.basic.integer.signedness = 0;
+       fields[1].type.u.basic.integer.signedness = is_signed_type(unsigned long);
        fields[1].type.u.basic.integer.reverse_byte_order = 0;
        fields[1].type.u.basic.integer.base = 16;
        fields[1].type.u.basic.integer.encoding = lttng_encode_none;
index 9dd3569b4a794d59f5a7cbec2a060fb1d3cd9a6f..481807de92a2796a36a1033fec6189ca7e2a97ff 100644 (file)
@@ -67,7 +67,7 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event)
        field->type.atype = atype_integer;
        field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT;
        field->type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT;
-       field->type.u.basic.integer.signedness = 0;
+       field->type.u.basic.integer.signedness = is_signed_type(unsigned long);
        field->type.u.basic.integer.reverse_byte_order = 0;
        field->type.u.basic.integer.base = 16;
        field->type.u.basic.integer.encoding = lttng_encode_none;
index c6620713c44d72f8f3ed8d082cb1e8ee65062ae3..740c1d9424ca3d98795c825065ec0c5a5b4f6bb5 100644 (file)
@@ -34,8 +34,7 @@ void perf_counter_record(struct lttng_ctx_field *field,
        event = field->u.perf_counter.e[ctx->cpu];
        event->pmu->read(event);
        value = local64_read(&event->count);
-       lib_ring_buffer_align_ctx(ctx,
-               ltt_alignof(field->type.u.basic.integer.alignment / CHAR_BIT));
+       lib_ring_buffer_align_ctx(ctx, ltt_alignof(value));
        chan->ops->event_write(ctx, &value, sizeof(value));
 }
 
@@ -109,7 +108,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
        field->type.atype = atype_integer;
        field->type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT;
        field->type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT;
-       field->type.u.basic.integer.signedness = 0;
+       field->type.u.basic.integer.signedness = is_signed_type(unsigned long);
        field->type.u.basic.integer.reverse_byte_order = 0;
        field->type.u.basic.integer.base = 10;
        field->type.u.basic.integer.encoding = lttng_encode_none;
index d09ecb115f172b09ca52dbacf3fba5451103e014..f87017bae00bd057a6179f5e4af491b3d0bb7174 100644 (file)
@@ -1,9 +1,6 @@
 #ifndef _LTTNG_PROBES_LTTNG_H
 #define _LTTNG_PROBES_LTTNG_H
 
-#undef is_signed_type
-#define is_signed_type(type)           (((type)(-1)) < 0)
-
 #undef PARAMS
 #define PARAMS(args...)                args
 
This page took 0.028816 seconds and 4 git commands to generate.