1 From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
2 Subject: Tracepoints Samples
4 Tracepoint example code under samples/.
6 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
7 Acked-by: 'Peter Zijlstra' <peterz@infradead.org>
8 CC: Masami Hiramatsu <mhiramat@redhat.com>
9 CC: "Frank Ch. Eigler" <fche@redhat.com>
10 CC: 'Ingo Molnar' <mingo@elte.hu>
11 CC: 'Hideo AOKI' <haoki@redhat.com>
12 CC: Takashi Nishiie <t-nishiie@np.css.fujitsu.com>
13 CC: 'Steven Rostedt' <rostedt@goodmis.org>
14 CC: Eduard - Gabriel Munteanu <eduard.munteanu@linux360.ro>
15 Acked-by: Jan Blunck <jblunck@suse.de>
17 samples/Kconfig | 6 ++
19 samples/tracepoints/Makefile | 6 ++
20 samples/tracepoints/tp-samples-trace.h | 13 +++++
21 samples/tracepoints/tracepoint-probe-sample.c | 55 +++++++++++++++++++++++++
22 samples/tracepoints/tracepoint-probe-sample2.c | 42 +++++++++++++++++++
23 samples/tracepoints/tracepoint-sample.c | 53 ++++++++++++++++++++++++
24 7 files changed, 176 insertions(+), 1 deletion(-)
26 Index: linux-2.6-lttng/samples/Kconfig
27 ===================================================================
28 --- linux-2.6-lttng.orig/samples/Kconfig 2008-07-07 09:59:25.000000000 -0400
29 +++ linux-2.6-lttng/samples/Kconfig 2008-07-07 10:00:07.000000000 -0400
30 @@ -13,6 +13,12 @@ config SAMPLE_MARKERS
32 This build markers example modules.
34 +config SAMPLE_TRACEPOINTS
35 + tristate "Build tracepoints examples -- loadable modules only"
36 + depends on TRACEPOINTS && m
38 + This build tracepoints example modules.
41 tristate "Build kobject examples"
43 Index: linux-2.6-lttng/samples/tracepoints/Makefile
44 ===================================================================
45 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
46 +++ linux-2.6-lttng/samples/tracepoints/Makefile 2008-07-07 10:53:09.000000000 -0400
48 +# builds the tracepoint example kernel modules;
49 +# then to use one (as root): insmod <module_name.ko>
51 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-sample.o
52 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample.o
53 +obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample2.o
54 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample.c
55 ===================================================================
56 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
57 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample.c 2008-07-07 10:50:26.000000000 -0400
60 + * tracepoint-probe-sample.c
62 + * sample tracepoint probes.
65 +#include <linux/module.h>
66 +#include <linux/file.h>
67 +#include <linux/dcache.h>
68 +#include "tp-samples-trace.h"
71 + * Here the caller only guarantees locking for struct file and struct inode.
72 + * Locking must therefore be done in the probe to use the dentry.
74 +static void probe_subsys_event(struct inode *inode, struct file *file)
76 + path_get(&file->f_path);
77 + dget(file->f_path.dentry);
78 + printk(KERN_INFO "Event is encountered with filename %s\n",
79 + file->f_path.dentry->d_name.name);
80 + dput(file->f_path.dentry);
81 + path_put(&file->f_path);
84 +static void probe_subsys_eventb(void)
86 + printk(KERN_INFO "Event B is encountered\n");
89 +int __init tp_sample_trace_init(void)
93 + ret = register_trace_subsys_event(probe_subsys_event);
95 + ret = register_trace_subsys_eventb(probe_subsys_eventb);
101 +module_init(tp_sample_trace_init);
103 +void __exit tp_sample_trace_exit(void)
105 + unregister_trace_subsys_eventb(probe_subsys_eventb);
106 + unregister_trace_subsys_event(probe_subsys_event);
109 +module_exit(tp_sample_trace_exit);
111 +MODULE_LICENSE("GPL");
112 +MODULE_AUTHOR("Mathieu Desnoyers");
113 +MODULE_DESCRIPTION("Tracepoint Probes Samples");
114 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-sample.c
115 ===================================================================
116 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
117 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-sample.c 2008-07-07 10:04:16.000000000 -0400
119 +/* tracepoint-sample.c
121 + * Executes a tracepoint when /proc/tracepoint-example is opened.
123 + * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
125 + * This file is released under the GPLv2.
126 + * See the file COPYING for more details.
129 +#include <linux/module.h>
130 +#include <linux/sched.h>
131 +#include <linux/proc_fs.h>
132 +#include "tp-samples-trace.h"
134 +struct proc_dir_entry *pentry_example;
136 +static int my_open(struct inode *inode, struct file *file)
140 + trace_subsys_event(inode, file);
141 + for (i = 0; i < 10; i++)
142 + trace_subsys_eventb();
146 +static struct file_operations mark_ops = {
150 +static int example_init(void)
152 + printk(KERN_ALERT "example init\n");
153 + pentry_example = proc_create("tracepoint-example", 0444, NULL,
155 + if (!pentry_example)
160 +static void example_exit(void)
162 + printk(KERN_ALERT "example exit\n");
163 + remove_proc_entry("tracepoint-example", NULL);
166 +module_init(example_init)
167 +module_exit(example_exit)
169 +MODULE_LICENSE("GPL");
170 +MODULE_AUTHOR("Mathieu Desnoyers");
171 +MODULE_DESCRIPTION("Tracepoint example");
172 Index: linux-2.6-lttng/samples/tracepoints/tp-samples-trace.h
173 ===================================================================
174 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
175 +++ linux-2.6-lttng/samples/tracepoints/tp-samples-trace.h 2008-07-07 10:06:26.000000000 -0400
177 +#ifndef _TP_SAMPLES_TRACE_H
178 +#define _TP_SAMPLES_TRACE_H
180 +#include <linux/proc_fs.h> /* for struct inode and struct file */
181 +#include <linux/tracepoint.h>
183 +DEFINE_TRACE(subsys_event,
184 + TPPROTO(struct inode *inode, struct file *file),
185 + TPARGS(inode, file));
186 +DEFINE_TRACE(subsys_eventb,
190 Index: linux-2.6-lttng/samples/Makefile
191 ===================================================================
192 --- linux-2.6-lttng.orig/samples/Makefile 2008-07-07 10:44:50.000000000 -0400
193 +++ linux-2.6-lttng/samples/Makefile 2008-07-07 10:44:59.000000000 -0400
195 # Makefile for Linux samples code
197 -obj-$(CONFIG_SAMPLES) += markers/ kobject/ kprobes/
198 +obj-$(CONFIG_SAMPLES) += markers/ kobject/ kprobes/ tracepoints/
199 Index: linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample2.c
200 ===================================================================
201 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
202 +++ linux-2.6-lttng/samples/tracepoints/tracepoint-probe-sample2.c 2008-07-07 10:56:09.000000000 -0400
205 + * tracepoint-probe-sample2.c
207 + * 2nd sample tracepoint probes.
210 +#include <linux/module.h>
211 +#include <linux/fs.h>
212 +#include "tp-samples-trace.h"
215 + * Here the caller only guarantees locking for struct file and struct inode.
216 + * Locking must therefore be done in the probe to use the dentry.
218 +static void probe_subsys_event(struct inode *inode, struct file *file)
220 + printk(KERN_INFO "Event is encountered with inode number %lu\n",
224 +int __init tp_sample_trace_init(void)
228 + ret = register_trace_subsys_event(probe_subsys_event);
234 +module_init(tp_sample_trace_init);
236 +void __exit tp_sample_trace_exit(void)
238 + unregister_trace_subsys_event(probe_subsys_event);
241 +module_exit(tp_sample_trace_exit);
243 +MODULE_LICENSE("GPL");
244 +MODULE_AUTHOR("Mathieu Desnoyers");
245 +MODULE_DESCRIPTION("Tracepoint Probes Samples");