From: Mathieu Desnoyers Date: Thu, 26 May 2011 02:54:11 +0000 (-0400) Subject: Add comm context X-Git-Tag: v2.0-pre1~79 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=25b2f99ab44a986f4850ece6eaadb2ead024c924;p=lttng-modules.git Add comm context Signed-off-by: Mathieu Desnoyers --- diff --git a/Makefile b/Makefile index 01b0e7ee..8f364dbf 100644 --- 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/ diff --git a/ltt-debugfs-abi.c b/ltt-debugfs-abi.c index 73082667..afdc09a6 100644 --- a/ltt-debugfs-abi.c +++ b/ltt-debugfs-abi.c @@ -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; } diff --git a/ltt-debugfs-abi.h b/ltt-debugfs-abi.h index ddc50ba5..2768055f 100644 --- a/ltt-debugfs-abi.h +++ b/ltt-debugfs-abi.h @@ -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; }; diff --git a/ltt-events.h b/ltt-events.h index a5a57fcd..2b6ef40a 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -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 index 00000000..6e51bf85 --- /dev/null +++ b/lttng-context-comm.c @@ -0,0 +1,69 @@ +/* + * (C) Copyright 2009-2011 - + * Mathieu Desnoyers + * + * LTTng comm name context. + * + * Dual LGPL v2.1/GPL v2 license. + */ + +#include +#include +#include +#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//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");