trace_custom_sched.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * event tracer
  4. *
  5. * Copyright (C) 2022 Google Inc, Steven Rostedt <rostedt@goodmis.org>
  6. */
  7. #define pr_fmt(fmt) fmt
  8. #include <linux/trace_events.h>
  9. #include <linux/module.h>
  10. #include <linux/sched.h>
  11. /*
  12. * Must include the event header that the custom event will attach to,
  13. * from the C file, and not in the custom header file.
  14. */
  15. #include <trace/events/sched.h>
  16. /* Declare CREATE_CUSTOM_TRACE_EVENTS before including custom header */
  17. #define CREATE_CUSTOM_TRACE_EVENTS
  18. #include "trace_custom_sched.h"
  19. /*
  20. * As the trace events are not exported to modules, the use of
  21. * for_each_kernel_tracepoint() is needed to find the trace event
  22. * to attach to. The fct() function below, is a callback that
  23. * will be called for every event.
  24. *
  25. * Helper functions are created by the TRACE_CUSTOM_EVENT() macro
  26. * update the event. Those are of the form:
  27. *
  28. * trace_custom_event_<event>_update()
  29. *
  30. * Where <event> is the event to attach.
  31. */
  32. static void fct(struct tracepoint *tp, void *priv)
  33. {
  34. trace_custom_event_sched_switch_update(tp);
  35. trace_custom_event_sched_waking_update(tp);
  36. }
  37. static int __init trace_sched_init(void)
  38. {
  39. for_each_kernel_tracepoint(fct, NULL);
  40. return 0;
  41. }
  42. static void __exit trace_sched_exit(void)
  43. {
  44. }
  45. module_init(trace_sched_init);
  46. module_exit(trace_sched_exit);
  47. MODULE_AUTHOR("Steven Rostedt");
  48. MODULE_DESCRIPTION("Custom scheduling events");
  49. MODULE_LICENSE("GPL");