trace_custom_sched.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Like the headers that use TRACE_EVENT(), the TRACE_CUSTOM_EVENT()
  4. * needs a header that allows for multiple inclusions.
  5. *
  6. * Test for a unique name (here we have _TRACE_CUSTOM_SCHED_H),
  7. * also allowing to continue if TRACE_CUSTOM_MULTI_READ is defined.
  8. */
  9. #if !defined(_TRACE_CUSTOM_SCHED_H) || defined(TRACE_CUSTOM_MULTI_READ)
  10. #define _TRACE_CUSTOM_SCHED_H
  11. /* Include linux/trace_events.h for initial defines of TRACE_CUSTOM_EVENT() */
  12. #include <linux/trace_events.h>
  13. /*
  14. * TRACE_CUSTOM_EVENT() is just like TRACE_EVENT(). The first parameter
  15. * is the event name of an existing event where the TRACE_EVENT has been included
  16. * in the C file before including this file.
  17. */
  18. TRACE_CUSTOM_EVENT(sched_switch,
  19. /*
  20. * The TP_PROTO() and TP_ARGS must match the trace event
  21. * that the custom event is using.
  22. */
  23. TP_PROTO(bool preempt,
  24. struct task_struct *prev,
  25. struct task_struct *next,
  26. unsigned int prev_state),
  27. TP_ARGS(preempt, prev, next, prev_state),
  28. /*
  29. * The next fields are where the customization happens.
  30. * The TP_STRUCT__entry() defines what will be recorded
  31. * in the ring buffer when the custom event triggers.
  32. *
  33. * The rest is just like the TRACE_EVENT() macro except that
  34. * it uses the custom entry.
  35. */
  36. TP_STRUCT__entry(
  37. __field( unsigned short, prev_prio )
  38. __field( unsigned short, next_prio )
  39. __field( pid_t, next_pid )
  40. ),
  41. TP_fast_assign(
  42. __entry->prev_prio = prev->prio;
  43. __entry->next_pid = next->pid;
  44. __entry->next_prio = next->prio;
  45. ),
  46. TP_printk("prev_prio=%d next_pid=%d next_prio=%d",
  47. __entry->prev_prio, __entry->next_pid, __entry->next_prio)
  48. )
  49. TRACE_CUSTOM_EVENT(sched_waking,
  50. TP_PROTO(struct task_struct *p),
  51. TP_ARGS(p),
  52. TP_STRUCT__entry(
  53. __field( pid_t, pid )
  54. __field( unsigned short, prio )
  55. ),
  56. TP_fast_assign(
  57. __entry->pid = p->pid;
  58. __entry->prio = p->prio;
  59. ),
  60. TP_printk("pid=%d prio=%d", __entry->pid, __entry->prio)
  61. )
  62. #endif
  63. /*
  64. * Just like the headers that create TRACE_EVENTs, the below must
  65. * be outside the protection of the above #if block.
  66. */
  67. /*
  68. * It is required that the Makefile includes:
  69. * CFLAGS_<c_file>.o := -I$(src)
  70. */
  71. #undef TRACE_INCLUDE_PATH
  72. #undef TRACE_INCLUDE_FILE
  73. #define TRACE_INCLUDE_PATH .
  74. /*
  75. * It is requred that the TRACE_INCLUDE_FILE be the same
  76. * as this file without the ".h".
  77. */
  78. #define TRACE_INCLUDE_FILE trace_custom_sched
  79. #include <trace/define_custom_trace.h>