tracing/events: add trace-events-sample
[linux-flexiantxendom0-3.2.10.git] / samples / trace_events / trace-events-sample.c
1 #include <linux/module.h>
2 #include <linux/kthread.h>
3
4 /*
5  * Any file that uses trace points, must include the header.
6  * But only one file, must include the header by defining
7  * CREATE_TRACE_POINTS first.  This will make the C code that
8  * creates the handles for the trace points.
9  */
10 #define CREATE_TRACE_POINTS
11 #include "trace-events-sample.h"
12
13
14 static void simple_thread_func(int cnt)
15 {
16         set_current_state(TASK_INTERRUPTIBLE);
17         schedule_timeout(HZ);
18         trace_foo_bar("hello", cnt);
19
20         if (!(cnt % 10))
21                 /* It is really important that I say "hi!" */
22                 printk(KERN_EMERG "hi!\n");
23 }
24
25 static int simple_thread(void *arg)
26 {
27         int cnt = 0;
28
29         while (!kthread_should_stop())
30                 simple_thread_func(cnt++);
31
32         return 0;
33 }
34
35 static struct task_struct *simple_tsk;
36
37 static int __init trace_event_init(void)
38 {
39         simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
40         if (IS_ERR(simple_tsk))
41                 return -1;
42
43         return 0;
44 }
45
46 static void __exit trace_event_exit(void)
47 {
48         kthread_stop(simple_tsk);
49 }
50
51 module_init(trace_event_init);
52 module_exit(trace_event_exit);
53
54 MODULE_AUTHOR("Steven Rostedt");
55 MODULE_DESCRIPTION("trace-events-sample");
56 MODULE_LICENSE("GPL");