Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 1 | /* tracepoint-sample.c |
| 2 | * |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 3 | * Executes a tracepoint when /proc/tracepoint-sample is opened. |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 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 | |
Mathieu Desnoyers | 7e066fb | 2008-11-14 17:47:47 -0500 | [diff] [blame] | 16 | DEFINE_TRACE(subsys_event); |
| 17 | DEFINE_TRACE(subsys_eventb); |
| 18 | |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 19 | struct proc_dir_entry *pentry_sample; |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 20 | |
| 21 | static int my_open(struct inode *inode, struct file *file) |
| 22 | { |
| 23 | int i; |
| 24 | |
| 25 | trace_subsys_event(inode, file); |
| 26 | for (i = 0; i < 10; i++) |
| 27 | trace_subsys_eventb(); |
| 28 | return -EPERM; |
| 29 | } |
| 30 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 31 | static const struct file_operations mark_ops = { |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 32 | .open = my_open, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 33 | .llseek = noop_llseek, |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 34 | }; |
| 35 | |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 36 | static int __init sample_init(void) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 37 | { |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 38 | printk(KERN_ALERT "sample init\n"); |
| 39 | pentry_sample = proc_create("tracepoint-sample", 0444, NULL, |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 40 | &mark_ops); |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 41 | if (!pentry_sample) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 42 | return -EPERM; |
| 43 | return 0; |
| 44 | } |
| 45 | |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 46 | static void __exit sample_exit(void) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 47 | { |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 48 | printk(KERN_ALERT "sample exit\n"); |
| 49 | remove_proc_entry("tracepoint-sample", NULL); |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 50 | } |
| 51 | |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 52 | module_init(sample_init) |
| 53 | module_exit(sample_exit) |
Mathieu Desnoyers | 4a08975 | 2008-07-18 12:16:16 -0400 | [diff] [blame] | 54 | |
| 55 | MODULE_LICENSE("GPL"); |
| 56 | MODULE_AUTHOR("Mathieu Desnoyers"); |
Jody McIntyre | 0a5d649 | 2009-03-24 16:00:28 -0400 | [diff] [blame] | 57 | MODULE_DESCRIPTION("Tracepoint sample"); |