aboutsummaryrefslogtreecommitdiffstats
path: root/samples/trace_events/trace-events-sample.c
diff options
context:
space:
mode:
Diffstat (limited to 'samples/trace_events/trace-events-sample.c')
-rw-r--r--samples/trace_events/trace-events-sample.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/samples/trace_events/trace-events-sample.c b/samples/trace_events/trace-events-sample.c
new file mode 100644
index 000000000000..f33b3ba744ac
--- /dev/null
+++ b/samples/trace_events/trace-events-sample.c
@@ -0,0 +1,56 @@
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
14static 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
25static 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
35static struct task_struct *simple_tsk;
36
37static 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
46static void __exit trace_event_exit(void)
47{
48 kthread_stop(simple_tsk);
49}
50
51module_init(trace_event_init);
52module_exit(trace_event_exit);
53
54MODULE_AUTHOR("Steven Rostedt");
55MODULE_DESCRIPTION("trace-events-sample");
56MODULE_LICENSE("GPL");