Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 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 | */ |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 16 | static void probe_subsys_event(void *ignore, |
| 17 | struct inode *inode, struct file *file) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 18 | { |
| 19 | path_get(&file->f_path); |
| 20 | dget(file->f_path.dentry); |
| 21 | printk(KERN_INFO "Event is encountered with filename %s\n", |
| 22 | file->f_path.dentry->d_name.name); |
| 23 | dput(file->f_path.dentry); |
| 24 | path_put(&file->f_path); |
| 25 | } |
| 26 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 27 | static void probe_subsys_eventb(void *ignore) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 28 | { |
| 29 | printk(KERN_INFO "Event B is encountered\n"); |
| 30 | } |
| 31 | |
Qinghuang Feng | 7ec7fb3 | 2009-01-06 14:40:52 -0800 | [diff] [blame] | 32 | static int __init tp_sample_trace_init(void) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 33 | { |
| 34 | int ret; |
| 35 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 36 | ret = register_trace_subsys_event(probe_subsys_event, NULL); |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 37 | WARN_ON(ret); |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 38 | ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL); |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 39 | WARN_ON(ret); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | module_init(tp_sample_trace_init); |
| 45 | |
Qinghuang Feng | 7ec7fb3 | 2009-01-06 14:40:52 -0800 | [diff] [blame] | 46 | static void __exit tp_sample_trace_exit(void) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 47 | { |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 48 | unregister_trace_subsys_eventb(probe_subsys_eventb, NULL); |
| 49 | unregister_trace_subsys_event(probe_subsys_event, NULL); |
Mathieu Desnoyers | 2504ea5 | 2008-11-14 17:47:41 -0500 | [diff] [blame] | 50 | tracepoint_synchronize_unregister(); |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | module_exit(tp_sample_trace_exit); |
| 54 | |
| 55 | MODULE_LICENSE("GPL"); |
| 56 | MODULE_AUTHOR("Mathieu Desnoyers"); |
| 57 | MODULE_DESCRIPTION("Tracepoint Probes Samples"); |