trace_custom_sched.c 1.4 KB

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