Fix: handle large number of pages or subbuffers per buffer
[lttng-modules.git] / lttng-context-procname.c
1 /*
2 * lttng-context-procname.c
3 *
4 * LTTng procname context.
5 *
6 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/sched.h>
26 #include <lttng-events.h>
27 #include <wrapper/ringbuffer/frontend_types.h>
28 #include <wrapper/vmalloc.h>
29 #include <lttng-tracer.h>
30
31 static
32 size_t procname_get_size(size_t offset)
33 {
34 size_t size = 0;
35
36 size += sizeof(current->comm);
37 return size;
38 }
39
40 /*
41 * Racy read of procname. We simply copy its whole array size.
42 * Races with /proc/<task>/procname write only.
43 * Otherwise having to take a mutex for each event is cumbersome and
44 * could lead to crash in IRQ context and deadlock of the lockdep tracer.
45 */
46 static
47 void procname_record(struct lttng_ctx_field *field,
48 struct lib_ring_buffer_ctx *ctx,
49 struct lttng_channel *chan)
50 {
51 chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
52 }
53
54 static
55 void procname_get_value(struct lttng_ctx_field *field,
56 struct lttng_probe_ctx *lttng_probe_ctx,
57 union lttng_ctx_value *value)
58 {
59 value->str = current->comm;
60 }
61
62 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
63 {
64 struct lttng_ctx_field *field;
65
66 field = lttng_append_context(ctx);
67 if (!field)
68 return -ENOMEM;
69 if (lttng_find_context(*ctx, "procname")) {
70 lttng_remove_context_field(ctx, field);
71 return -EEXIST;
72 }
73 field->event_field.name = "procname";
74 field->event_field.type.atype = atype_array;
75 field->event_field.type.u.array.elem_type.atype = atype_integer;
76 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
77 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
78 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
79 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
80 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
81 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
82 field->event_field.type.u.array.length = sizeof(current->comm);
83
84 field->get_size = procname_get_size;
85 field->record = procname_record;
86 field->get_value = procname_get_value;
87 lttng_context_update(*ctx);
88 wrapper_vmalloc_sync_all();
89 return 0;
90 }
91 EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
This page took 0.0323 seconds and 4 git commands to generate.