Commit | Line | Data |
---|---|---|
25b2f99a MD |
1 | /* |
2 | * (C) Copyright 2009-2011 - | |
3 | * Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | * | |
c26fddc2 | 5 | * LTTng procname context. |
25b2f99a MD |
6 | * |
7 | * Dual LGPL v2.1/GPL v2 license. | |
8 | */ | |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
13 | #include "ltt-events.h" | |
14 | #include "wrapper/ringbuffer/frontend_types.h" | |
15 | #include "wrapper/vmalloc.h" | |
16 | #include "ltt-tracer.h" | |
17 | ||
18 | static | |
c26fddc2 | 19 | size_t procname_get_size(size_t offset) |
25b2f99a MD |
20 | { |
21 | size_t size = 0; | |
22 | ||
23 | size += sizeof(current->comm); | |
24 | return size; | |
25 | } | |
26 | ||
27 | /* | |
c26fddc2 MD |
28 | * Racy read of procname. We simply copy its whole array size. |
29 | * Races with /proc/<task>/procname write only. | |
25b2f99a MD |
30 | * Otherwise having to take a mutex for each event is cumbersome and |
31 | * could lead to crash in IRQ context and deadlock of the lockdep tracer. | |
32 | */ | |
33 | static | |
c26fddc2 | 34 | void procname_record(struct lttng_ctx_field *field, |
25b2f99a MD |
35 | struct lib_ring_buffer_ctx *ctx, |
36 | struct ltt_channel *chan) | |
37 | { | |
38 | chan->ops->event_write(ctx, current->comm, sizeof(current->comm)); | |
39 | } | |
40 | ||
c26fddc2 | 41 | int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) |
25b2f99a MD |
42 | { |
43 | struct lttng_ctx_field *field; | |
25b2f99a MD |
44 | |
45 | field = lttng_append_context(ctx); | |
46 | if (!field) | |
09fec6b4 | 47 | return -ENOMEM; |
c26fddc2 | 48 | if (lttng_find_context(*ctx, "procname")) { |
44252f0f MD |
49 | lttng_remove_context_field(ctx, field); |
50 | return -EEXIST; | |
51 | } | |
c26fddc2 | 52 | field->event_field.name = "procname"; |
25b2f99a MD |
53 | field->event_field.type.atype = atype_array; |
54 | field->event_field.type.u.array.elem_type.atype = atype_integer; | |
55 | field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT; | |
56 | field->event_field.type.u.array.elem_type.u.basic.integer.alignment = ltt_alignof(char) * CHAR_BIT; | |
57 | field->event_field.type.u.array.elem_type.u.basic.integer.signedness = is_signed_type(char); | |
58 | field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0; | |
59 | field->event_field.type.u.array.elem_type.u.basic.integer.base = 10; | |
60 | field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8; | |
61 | field->event_field.type.u.array.length = sizeof(current->comm); | |
62 | ||
c26fddc2 MD |
63 | field->get_size = procname_get_size; |
64 | field->record = procname_record; | |
25b2f99a MD |
65 | wrapper_vmalloc_sync_all(); |
66 | return 0; | |
67 | } | |
c26fddc2 | 68 | EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx); |
25b2f99a MD |
69 | |
70 | MODULE_LICENSE("GPL and additional rights"); | |
71 | MODULE_AUTHOR("Mathieu Desnoyers"); | |
72 | MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support"); |