trace-events-sample.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <linux/module.h>
  2. #include <linux/kthread.h>
  3. /*
  4. * Any file that uses trace points, must include the header.
  5. * But only one file, must include the header by defining
  6. * CREATE_TRACE_POINTS first. This will make the C code that
  7. * creates the handles for the trace points.
  8. */
  9. #define CREATE_TRACE_POINTS
  10. #include "trace-events-sample.h"
  11. static void simple_thread_func(int cnt)
  12. {
  13. set_current_state(TASK_INTERRUPTIBLE);
  14. schedule_timeout(HZ);
  15. trace_foo_bar("hello", cnt);
  16. }
  17. static int simple_thread(void *arg)
  18. {
  19. int cnt = 0;
  20. while (!kthread_should_stop())
  21. simple_thread_func(cnt++);
  22. return 0;
  23. }
  24. static struct task_struct *simple_tsk;
  25. static int __init trace_event_init(void)
  26. {
  27. simple_tsk = kthread_run(simple_thread, NULL, "event-sample");
  28. if (IS_ERR(simple_tsk))
  29. return -1;
  30. return 0;
  31. }
  32. static void __exit trace_event_exit(void)
  33. {
  34. kthread_stop(simple_tsk);
  35. }
  36. module_init(trace_event_init);
  37. module_exit(trace_event_exit);
  38. MODULE_AUTHOR("Steven Rostedt");
  39. MODULE_DESCRIPTION("trace-events-sample");
  40. MODULE_LICENSE("GPL");