diff options
| author | Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | 2008-07-18 12:16:16 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2008-10-14 04:29:05 -0400 |
| commit | 4a0897526bbc5c6ac0df80b16b8c60339e717ae2 (patch) | |
| tree | aa8eb17c791cdff175f8cd6cb76f02d05f00029a /samples/tracepoints | |
| parent | 24b8d831d56aac7907752d22d2aba5d8127db6f6 (diff) | |
tracing: tracepoints, samples
Tracepoint example code under samples/.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Acked-by: 'Peter Zijlstra' <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'samples/tracepoints')
| -rw-r--r-- | samples/tracepoints/Makefile | 6 | ||||
| -rw-r--r-- | samples/tracepoints/tp-samples-trace.h | 13 | ||||
| -rw-r--r-- | samples/tracepoints/tracepoint-probe-sample.c | 55 | ||||
| -rw-r--r-- | samples/tracepoints/tracepoint-probe-sample2.c | 42 | ||||
| -rw-r--r-- | samples/tracepoints/tracepoint-sample.c | 53 |
5 files changed, 169 insertions, 0 deletions
diff --git a/samples/tracepoints/Makefile b/samples/tracepoints/Makefile new file mode 100644 index 00000000000..36479ad9ae1 --- /dev/null +++ b/samples/tracepoints/Makefile | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | # builds the tracepoint example kernel modules; | ||
| 2 | # then to use one (as root): insmod <module_name.ko> | ||
| 3 | |||
| 4 | obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-sample.o | ||
| 5 | obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample.o | ||
| 6 | obj-$(CONFIG_SAMPLE_TRACEPOINTS) += tracepoint-probe-sample2.o | ||
diff --git a/samples/tracepoints/tp-samples-trace.h b/samples/tracepoints/tp-samples-trace.h new file mode 100644 index 00000000000..0216b55bd64 --- /dev/null +++ b/samples/tracepoints/tp-samples-trace.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | #ifndef _TP_SAMPLES_TRACE_H | ||
| 2 | #define _TP_SAMPLES_TRACE_H | ||
| 3 | |||
| 4 | #include <linux/proc_fs.h> /* for struct inode and struct file */ | ||
| 5 | #include <linux/tracepoint.h> | ||
| 6 | |||
| 7 | DEFINE_TRACE(subsys_event, | ||
| 8 | TPPROTO(struct inode *inode, struct file *file), | ||
| 9 | TPARGS(inode, file)); | ||
| 10 | DEFINE_TRACE(subsys_eventb, | ||
| 11 | TPPROTO(void), | ||
| 12 | TPARGS()); | ||
| 13 | #endif | ||
diff --git a/samples/tracepoints/tracepoint-probe-sample.c b/samples/tracepoints/tracepoint-probe-sample.c new file mode 100644 index 00000000000..55abfdda4bd --- /dev/null +++ b/samples/tracepoints/tracepoint-probe-sample.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | /* | ||
| 2 | * tracepoint-probe-sample.c | ||
| 3 | * | ||
| 4 | * sample tracepoint probes. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <linux/module.h> | ||
| 8 | #include <linux/file.h> | ||
| 9 | #include <linux/dcache.h> | ||
| 10 | #include "tp-samples-trace.h" | ||
| 11 | |||
| 12 | /* | ||
| 13 | * Here the caller only guarantees locking for struct file and struct inode. | ||
| 14 | * Locking must therefore be done in the probe to use the dentry. | ||
| 15 | */ | ||
| 16 | static void probe_subsys_event(struct inode *inode, struct file *file) | ||
| 17 | { | ||
| 18 | path_get(&file->f_path); | ||
| 19 | dget(file->f_path.dentry); | ||
| 20 | printk(KERN_INFO "Event is encountered with filename %s\n", | ||
| 21 | file->f_path.dentry->d_name.name); | ||
| 22 | dput(file->f_path.dentry); | ||
| 23 | path_put(&file->f_path); | ||
| 24 | } | ||
| 25 | |||
| 26 | static void probe_subsys_eventb(void) | ||
| 27 | { | ||
| 28 | printk(KERN_INFO "Event B is encountered\n"); | ||
| 29 | } | ||
| 30 | |||
| 31 | int __init tp_sample_trace_init(void) | ||
| 32 | { | ||
| 33 | int ret; | ||
| 34 | |||
| 35 | ret = register_trace_subsys_event(probe_subsys_event); | ||
| 36 | WARN_ON(ret); | ||
| 37 | ret = register_trace_subsys_eventb(probe_subsys_eventb); | ||
| 38 | WARN_ON(ret); | ||
| 39 | |||
| 40 | return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | module_init(tp_sample_trace_init); | ||
| 44 | |||
| 45 | void __exit tp_sample_trace_exit(void) | ||
| 46 | { | ||
| 47 | unregister_trace_subsys_eventb(probe_subsys_eventb); | ||
| 48 | unregister_trace_subsys_event(probe_subsys_event); | ||
| 49 | } | ||
| 50 | |||
| 51 | module_exit(tp_sample_trace_exit); | ||
| 52 | |||
| 53 | MODULE_LICENSE("GPL"); | ||
| 54 | MODULE_AUTHOR("Mathieu Desnoyers"); | ||
| 55 | MODULE_DESCRIPTION("Tracepoint Probes Samples"); | ||
diff --git a/samples/tracepoints/tracepoint-probe-sample2.c b/samples/tracepoints/tracepoint-probe-sample2.c new file mode 100644 index 00000000000..5e9fcf4afff --- /dev/null +++ b/samples/tracepoints/tracepoint-probe-sample2.c | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* | ||
| 2 | * tracepoint-probe-sample2.c | ||
| 3 | * | ||
| 4 | * 2nd sample tracepoint probes. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <linux/module.h> | ||
| 8 | #include <linux/fs.h> | ||
| 9 | #include "tp-samples-trace.h" | ||
| 10 | |||
| 11 | /* | ||
| 12 | * Here the caller only guarantees locking for struct file and struct inode. | ||
| 13 | * Locking must therefore be done in the probe to use the dentry. | ||
| 14 | */ | ||
| 15 | static void probe_subsys_event(struct inode *inode, struct file *file) | ||
| 16 | { | ||
| 17 | printk(KERN_INFO "Event is encountered with inode number %lu\n", | ||
| 18 | inode->i_ino); | ||
| 19 | } | ||
| 20 | |||
| 21 | int __init tp_sample_trace_init(void) | ||
| 22 | { | ||
| 23 | int ret; | ||
| 24 | |||
| 25 | ret = register_trace_subsys_event(probe_subsys_event); | ||
| 26 | WARN_ON(ret); | ||
| 27 | |||
| 28 | return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | module_init(tp_sample_trace_init); | ||
| 32 | |||
| 33 | void __exit tp_sample_trace_exit(void) | ||
| 34 | { | ||
| 35 | unregister_trace_subsys_event(probe_subsys_event); | ||
| 36 | } | ||
| 37 | |||
| 38 | module_exit(tp_sample_trace_exit); | ||
| 39 | |||
| 40 | MODULE_LICENSE("GPL"); | ||
| 41 | MODULE_AUTHOR("Mathieu Desnoyers"); | ||
| 42 | MODULE_DESCRIPTION("Tracepoint Probes Samples"); | ||
diff --git a/samples/tracepoints/tracepoint-sample.c b/samples/tracepoints/tracepoint-sample.c new file mode 100644 index 00000000000..4ae4b7fcc04 --- /dev/null +++ b/samples/tracepoints/tracepoint-sample.c | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* tracepoint-sample.c | ||
| 2 | * | ||
| 3 | * Executes a tracepoint when /proc/tracepoint-example is opened. | ||
| 4 | * | ||
| 5 | * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> | ||
| 6 | * | ||
| 7 | * This file is released under the GPLv2. | ||
| 8 | * See the file COPYING for more details. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <linux/module.h> | ||
| 12 | #include <linux/sched.h> | ||
| 13 | #include <linux/proc_fs.h> | ||
| 14 | #include "tp-samples-trace.h" | ||
| 15 | |||
| 16 | struct proc_dir_entry *pentry_example; | ||
| 17 | |||
| 18 | static int my_open(struct inode *inode, struct file *file) | ||
| 19 | { | ||
| 20 | int i; | ||
| 21 | |||
| 22 | trace_subsys_event(inode, file); | ||
| 23 | for (i = 0; i < 10; i++) | ||
| 24 | trace_subsys_eventb(); | ||
| 25 | return -EPERM; | ||
| 26 | } | ||
| 27 | |||
| 28 | static struct file_operations mark_ops = { | ||
| 29 | .open = my_open, | ||
| 30 | }; | ||
| 31 | |||
| 32 | static int example_init(void) | ||
| 33 | { | ||
| 34 | printk(KERN_ALERT "example init\n"); | ||
| 35 | pentry_example = proc_create("tracepoint-example", 0444, NULL, | ||
| 36 | &mark_ops); | ||
| 37 | if (!pentry_example) | ||
| 38 | return -EPERM; | ||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | static void example_exit(void) | ||
| 43 | { | ||
| 44 | printk(KERN_ALERT "example exit\n"); | ||
| 45 | remove_proc_entry("tracepoint-example", NULL); | ||
| 46 | } | ||
| 47 | |||
| 48 | module_init(example_init) | ||
| 49 | module_exit(example_exit) | ||
| 50 | |||
| 51 | MODULE_LICENSE("GPL"); | ||
| 52 | MODULE_AUTHOR("Mathieu Desnoyers"); | ||
| 53 | MODULE_DESCRIPTION("Tracepoint example"); | ||
