Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 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 | |
Steven Rostedt (Red Hat) | 4e20e3a | 2015-02-09 15:27:04 -0500 | [diff] [blame^] | 13 | static const char *random_strings[] = { |
| 14 | "Mother Goose", |
| 15 | "Snoopy", |
| 16 | "Gandalf", |
| 17 | "Frodo", |
| 18 | "One ring to rule them all" |
| 19 | }; |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 20 | |
| 21 | static void simple_thread_func(int cnt) |
| 22 | { |
Steven Rostedt (Red Hat) | 4e20e3a | 2015-02-09 15:27:04 -0500 | [diff] [blame^] | 23 | int array[6]; |
| 24 | int len = cnt % 5; |
| 25 | int i; |
| 26 | |
Steven Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 27 | set_current_state(TASK_INTERRUPTIBLE); |
| 28 | schedule_timeout(HZ); |
Steven Rostedt (Red Hat) | 4e20e3a | 2015-02-09 15:27:04 -0500 | [diff] [blame^] | 29 | |
| 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 Rostedt | 9cfe06f | 2009-04-14 21:37:03 -0400 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static 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 | |
| 48 | static struct task_struct *simple_tsk; |
| 49 | |
| 50 | static 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 | |
| 59 | static void __exit trace_event_exit(void) |
| 60 | { |
| 61 | kthread_stop(simple_tsk); |
| 62 | } |
| 63 | |
| 64 | module_init(trace_event_init); |
| 65 | module_exit(trace_event_exit); |
| 66 | |
| 67 | MODULE_AUTHOR("Steven Rostedt"); |
| 68 | MODULE_DESCRIPTION("trace-events-sample"); |
| 69 | MODULE_LICENSE("GPL"); |