Implement lttng test module
[lttng-modules.git] / probes / lttng-test.c
CommitLineData
89406ecd
MD
1/*
2 * lttng-test.c
3 *
4 * Linux Trace Toolkit Next Generation Test Module
5 *
6 * Copyright 2015 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/init.h>
24#include <linux/module.h>
25#include <linux/proc_fs.h>
26#include <linux/byteorder/generic.h>
27
28#include "../lttng-events.h"
29#include "../lttng-tracer.h"
30#include "../wrapper/tracepoint.h"
31
32#define TP_MODULE_NOAUTOLOAD
33#define LTTNG_PACKAGE_BUILD
34#define CREATE_TRACE_POINTS
35#define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module
36#define TRACE_INCLUDE_FILE lttng-test
37#define LTTNG_INSTRUMENTATION
38#include "../instrumentation/events/lttng-module/lttng-test.h"
39
40DEFINE_TRACE(lttng_test_filter_event);
41
42#define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
43
44#define LTTNG_WRITE_COUNT_MAX 64
45
46static struct proc_dir_entry *lttng_test_filter_event_dentry;
47
48static
49void trace_test_event(unsigned int nr_iter)
50{
51 int i, netint;
52 long values[] = { 1, 2, 3 };
53 char text[10] = "test";
54 char escape[10] = "\\*";
55
56 for (i = 0; i < nr_iter; i++) {
57 netint = htonl(i);
58 trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape);
59 }
60}
61
62/**
63 * lttng_filter_event_write - trigger a lttng_test_filter_event
64 * @file: file pointer
65 * @user_buf: user string
66 * @count: length to copy
67 *
68 * Return -1 on error, with EFAULT errno. Returns count on success.
69 */
70static
71ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf,
72 size_t count, loff_t *ppos)
73{
74 unsigned int nr_iter;
75 ssize_t written;
76 int ret;
77
78 /* Get the number of iterations */
79 ret = kstrtouint_from_user(user_buf, count, 10, &nr_iter);
80 if (ret) {
81 written = ret;
82 goto end;
83 }
84 /* Trace the event */
85 trace_test_event(nr_iter);
86 written = count;
87 *ppos += written;
88end:
89 return written;
90}
91
92static const struct file_operations lttng_test_filter_event_operations = {
93 .write = lttng_test_filter_event_write,
94};
95
96static
97int __init lttng_test_init(void)
98{
99 int ret = 0;
100
101 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
102 wrapper_vmalloc_sync_all();
103 lttng_test_filter_event_dentry =
104 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
105 S_IRUGO | S_IWUGO, NULL,
106 &lttng_test_filter_event_operations, NULL);
107 if (!lttng_test_filter_event_dentry) {
108 printk(KERN_ERR "Error creating LTTng test filter file\n");
109 ret = -ENOMEM;
110 goto error;
111 }
112 ret = __lttng_events_init__lttng_test();
113 if (ret)
114 goto error_events;
115 return ret;
116
117error_events:
118 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
119error:
120 return ret;
121}
122
123module_init(lttng_test_init);
124
125static
126void __exit lttng_test_exit(void)
127{
128 __lttng_events_exit__lttng_test();
129 if (lttng_test_filter_event_dentry)
130 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
131}
132
133module_exit(lttng_test_exit);
134
135MODULE_LICENSE("GPL and additional rights");
136MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
137MODULE_DESCRIPTION("LTTng Test");
138MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
139 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
140 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
141 LTTNG_MODULES_EXTRAVERSION);
This page took 0.027605 seconds and 4 git commands to generate.