blob: 744c0b9652a7815407b95ecbb8ca6553c5e900c0 [file] [log] [blame]
Mathieu Desnoyers4a089752008-07-18 12:16:16 -04001/*
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 Rostedt38516ab2010-04-20 17:04:50 -040016static void probe_subsys_event(void *ignore,
17 struct inode *inode, struct file *file)
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040018{
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 Rostedt38516ab2010-04-20 17:04:50 -040027static void probe_subsys_eventb(void *ignore)
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040028{
29 printk(KERN_INFO "Event B is encountered\n");
30}
31
Qinghuang Feng7ec7fb32009-01-06 14:40:52 -080032static int __init tp_sample_trace_init(void)
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040033{
34 int ret;
35
Steven Rostedt38516ab2010-04-20 17:04:50 -040036 ret = register_trace_subsys_event(probe_subsys_event, NULL);
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040037 WARN_ON(ret);
Steven Rostedt38516ab2010-04-20 17:04:50 -040038 ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL);
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040039 WARN_ON(ret);
40
41 return 0;
42}
43
44module_init(tp_sample_trace_init);
45
Qinghuang Feng7ec7fb32009-01-06 14:40:52 -080046static void __exit tp_sample_trace_exit(void)
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040047{
Steven Rostedt38516ab2010-04-20 17:04:50 -040048 unregister_trace_subsys_eventb(probe_subsys_eventb, NULL);
49 unregister_trace_subsys_event(probe_subsys_event, NULL);
Mathieu Desnoyers2504ea52008-11-14 17:47:41 -050050 tracepoint_synchronize_unregister();
Mathieu Desnoyers4a089752008-07-18 12:16:16 -040051}
52
53module_exit(tp_sample_trace_exit);
54
55MODULE_LICENSE("GPL");
56MODULE_AUTHOR("Mathieu Desnoyers");
57MODULE_DESCRIPTION("Tracepoint Probes Samples");