blob: c396a49b5d7831cbf42a4e619ef95cde55ae2f93 [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
Steven Rostedt (Red Hat)c4c7eb22015-02-09 16:05:55 -050034 /* Silly tracepoints */
Steven Rostedt (Red Hat)4e20e3a2015-02-09 15:27:04 -050035 trace_foo_bar("hello", cnt, array, random_strings[len],
36 tsk_cpus_allowed(current));
Steven Rostedt (Red Hat)c4c7eb22015-02-09 16:05:55 -050037
38 trace_foo_bar_with_cond("Some times print", cnt);
Steven Rostedt9cfe06f2009-04-14 21:37:03 -040039}
40
41static int simple_thread(void *arg)
42{
43 int cnt = 0;
44
45 while (!kthread_should_stop())
46 simple_thread_func(cnt++);
47
48 return 0;
49}
50
51static struct task_struct *simple_tsk;
52
53static int __init trace_event_init(void)
54{
55 simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
56 if (IS_ERR(simple_tsk))
57 return -1;
58
59 return 0;
60}
61
62static void __exit trace_event_exit(void)
63{
64 kthread_stop(simple_tsk);
65}
66
67module_init(trace_event_init);
68module_exit(trace_event_exit);
69
70MODULE_AUTHOR("Steven Rostedt");
71MODULE_DESCRIPTION("trace-events-sample");
72MODULE_LICENSE("GPL");