Cleanup: remove logically dead code
[lttng-modules.git] / lttng-context-procname.c
CommitLineData
25b2f99a 1/*
886d51a3 2 * lttng-context-procname.c
25b2f99a 3 *
c26fddc2 4 * LTTng procname context.
25b2f99a 5 *
886d51a3
MD
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
25b2f99a
MD
21 */
22
23#include <linux/module.h>
24#include <linux/slab.h>
25#include <linux/sched.h>
a90917c3 26#include "lttng-events.h"
25b2f99a
MD
27#include "wrapper/ringbuffer/frontend_types.h"
28#include "wrapper/vmalloc.h"
a90917c3 29#include "lttng-tracer.h"
25b2f99a
MD
30
31static
c26fddc2 32size_t procname_get_size(size_t offset)
25b2f99a
MD
33{
34 size_t size = 0;
35
36 size += sizeof(current->comm);
37 return size;
38}
39
40/*
c26fddc2
MD
41 * Racy read of procname. We simply copy its whole array size.
42 * Races with /proc/<task>/procname write only.
25b2f99a
MD
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 */
46static
c26fddc2 47void procname_record(struct lttng_ctx_field *field,
25b2f99a 48 struct lib_ring_buffer_ctx *ctx,
a90917c3 49 struct lttng_channel *chan)
25b2f99a
MD
50{
51 chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
52}
53
f127e61e
MD
54static
55void procname_get_value(struct lttng_ctx_field *field,
56 union lttng_ctx_value *value)
57{
58 value->str = current->comm;
59}
60
c26fddc2 61int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
25b2f99a
MD
62{
63 struct lttng_ctx_field *field;
25b2f99a
MD
64
65 field = lttng_append_context(ctx);
66 if (!field)
09fec6b4 67 return -ENOMEM;
c26fddc2 68 if (lttng_find_context(*ctx, "procname")) {
44252f0f
MD
69 lttng_remove_context_field(ctx, field);
70 return -EEXIST;
71 }
c26fddc2 72 field->event_field.name = "procname";
25b2f99a
MD
73 field->event_field.type.atype = atype_array;
74 field->event_field.type.u.array.elem_type.atype = atype_integer;
75 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
a90917c3 76 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = lttng_alignof(char) * CHAR_BIT;
06254b0f 77 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = lttng_is_signed_type(char);
25b2f99a
MD
78 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
79 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
80 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
81 field->event_field.type.u.array.length = sizeof(current->comm);
82
c26fddc2
MD
83 field->get_size = procname_get_size;
84 field->record = procname_record;
f127e61e 85 field->get_value = procname_get_value;
a9dd15da 86 lttng_context_update(*ctx);
25b2f99a
MD
87 wrapper_vmalloc_sync_all();
88 return 0;
89}
c26fddc2 90EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
25b2f99a
MD
91
92MODULE_LICENSE("GPL and additional rights");
93MODULE_AUTHOR("Mathieu Desnoyers");
94MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
13ab8b0a
MD
95MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
96 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
97 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
98 LTTNG_MODULES_EXTRAVERSION);
This page took 0.031829 seconds and 4 git commands to generate.