lib ring buffer: add frontend init as module_init
[lttng-modules.git] / lttng-context-vppid.c
1 /*
2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * LTTng vPPID context.
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 <linux/syscalls.h>
14 #include "ltt-events.h"
15 #include "wrapper/ringbuffer/frontend_types.h"
16 #include "wrapper/vmalloc.h"
17 #include "ltt-tracer.h"
18
19 static
20 size_t vppid_get_size(size_t offset)
21 {
22 size_t size = 0;
23
24 size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
25 size += sizeof(pid_t);
26 return size;
27 }
28
29 static
30 void vppid_record(struct lttng_ctx_field *field,
31 struct lib_ring_buffer_ctx *ctx,
32 struct ltt_channel *chan)
33 {
34 struct task_struct *parent;
35 pid_t vppid;
36
37 /*
38 * nsproxy can be NULL when scheduled out of exit.
39 */
40 rcu_read_lock();
41 parent = rcu_dereference(current->real_parent);
42 if (!parent->nsproxy)
43 vppid = 0;
44 else
45 vppid = task_tgid_vnr(parent);
46 rcu_read_unlock();
47 lib_ring_buffer_align_ctx(ctx, ltt_alignof(vppid));
48 chan->ops->event_write(ctx, &vppid, sizeof(vppid));
49 }
50
51 int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx)
52 {
53 struct lttng_ctx_field *field;
54
55 field = lttng_append_context(ctx);
56 if (!field)
57 return -ENOMEM;
58 if (lttng_find_context(*ctx, "vppid")) {
59 lttng_remove_context_field(ctx, field);
60 return -EEXIST;
61 }
62 field->event_field.name = "vppid";
63 field->event_field.type.atype = atype_integer;
64 field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
65 field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
66 field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
67 field->event_field.type.u.basic.integer.reverse_byte_order = 0;
68 field->event_field.type.u.basic.integer.base = 10;
69 field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
70 field->get_size = vppid_get_size;
71 field->record = vppid_record;
72 wrapper_vmalloc_sync_all();
73 return 0;
74 }
75 EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
76
77 MODULE_LICENSE("GPL and additional rights");
78 MODULE_AUTHOR("Mathieu Desnoyers");
79 MODULE_DESCRIPTION("Linux Trace Toolkit vPPID Context");
This page took 0.04528 seconds and 4 git commands to generate.