diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-04-15 01:37:03 (GMT) |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-04-15 02:09:18 (GMT) |
commit | 9cfe06f8cd5c8c3ad6ab323973e87dde670642b8 (patch) | |
tree | 94348ca2c013264e45d352d208c4a6dc9c221eef /samples/trace_events/trace-events-sample.c | |
parent | ad8d75fff811a6a230f7f43b05a6483099349533 (diff) | |
download | linux-fsl-qoriq-9cfe06f8cd5c8c3ad6ab323973e87dde670642b8.tar.xz |
tracing/events: add trace-events-sample
This patch adds a sample to the samples directory on how to create
and use TRACE_EVENT trace points.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'samples/trace_events/trace-events-sample.c')
-rw-r--r-- | samples/trace_events/trace-events-sample.c | 56 |
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 0000000..f33b3ba --- /dev/null +++ b/samples/trace_events/trace-events-sample.c @@ -0,0 +1,56 @@ +#include <linux/module.h> +#include <linux/kthread.h> + +/* + * Any file that uses trace points, must include the header. + * But only one file, must include the header by defining + * CREATE_TRACE_POINTS first. This will make the C code that + * creates the handles for the trace points. + */ +#define CREATE_TRACE_POINTS +#include "trace-events-sample.h" + + +static void simple_thread_func(int cnt) +{ + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(HZ); + trace_foo_bar("hello", cnt); + + if (!(cnt % 10)) + /* It is really important that I say "hi!" */ + printk(KERN_EMERG "hi!\n"); +} + +static int simple_thread(void *arg) +{ + int cnt = 0; + + while (!kthread_should_stop()) + simple_thread_func(cnt++); + + return 0; +} + +static struct task_struct *simple_tsk; + +static int __init trace_event_init(void) +{ + simple_tsk = kthread_run(simple_thread, NULL, "event-sample"); + if (IS_ERR(simple_tsk)) + return -1; + + return 0; +} + +static void __exit trace_event_exit(void) +{ + kthread_stop(simple_tsk); +} + +module_init(trace_event_init); +module_exit(trace_event_exit); + +MODULE_AUTHOR("Steven Rostedt"); +MODULE_DESCRIPTION("trace-events-sample"); +MODULE_LICENSE("GPL"); |