blob: 16c15c08ed38936dc56c469a6fc623f3942f2c95 [file] [log] [blame]
Steven Rostedt9cfe06f2009-04-14 21:37:03 -04001#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
Steven Rostedt (Red Hat)4e20e3a2015-02-09 15:27:04 -050013static const char *random_strings[] = {
14 "Mother Goose",
15 "Snoopy",
16 "Gandalf",
17 "Frodo",
18 "One ring to rule them all"
19};
Steven Rostedt9cfe06f2009-04-14 21:37:03 -040020
21static void simple_thread_func(int cnt)
22{
Steven Rostedt (Red Hat)4e20e3a2015-02-09 15:27:04 -050023 int array[6];
24 int len = cnt % 5;
25 int i;
26
Steven Rostedt9cfe06f2009-04-14 21:37:03 -040027 set_current_state(TASK_INTERRUPTIBLE);
28 schedule_timeout(HZ);
Steven Rostedt (Red Hat)4e20e3a2015-02-09 15:27:04 -050029
30 for (i = 0; i < len; i++)
31 array[i] = i + 1;
32 array[i] = 0;
33
34 trace_foo_bar("hello", cnt, array, random_strings[len],
35 tsk_cpus_allowed(current));
Steven Rostedt9cfe06f2009-04-14 21:37:03 -040036}
37
38static int simple_thread(void *arg)
39{
40 int cnt = 0;
41
42 while (!kthread_should_stop())
43 simple_thread_func(cnt++);
44
45 return 0;
46}
47
48static struct task_struct *simple_tsk;
49
50static int __init trace_event_init(void)
51{
52 simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
53 if (IS_ERR(simple_tsk))
54 return -1;
55
56 return 0;
57}
58
59static void __exit trace_event_exit(void)
60{
61 kthread_stop(simple_tsk);
62}
63
64module_init(trace_event_init);
65module_exit(trace_event_exit);
66
67MODULE_AUTHOR("Steven Rostedt");
68MODULE_DESCRIPTION("trace-events-sample");
69MODULE_LICENSE("GPL");