define_trace.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Trace files that want to automate creation of all tracepoints defined
  4. * in their file should include this file. The following are macros that the
  5. * trace file may define:
  6. *
  7. * TRACE_SYSTEM defines the system the tracepoint is for
  8. *
  9. * TRACE_INCLUDE_FILE if the file name is something other than TRACE_SYSTEM.h
  10. * This macro may be defined to tell define_trace.h what file to include.
  11. * Note, leave off the ".h".
  12. *
  13. * TRACE_INCLUDE_PATH if the path is something other than core kernel include/trace
  14. * then this macro can define the path to use. Note, the path is relative to
  15. * define_trace.h, not the file including it. Full path names for out of tree
  16. * modules must be used.
  17. */
  18. #ifdef CREATE_TRACE_POINTS
  19. /* Prevent recursion */
  20. #undef CREATE_TRACE_POINTS
  21. #include <linux/stringify.h>
  22. #undef TRACE_EVENT
  23. #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
  24. DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
  25. #undef TRACE_EVENT_CONDITION
  26. #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
  27. TRACE_EVENT(name, \
  28. PARAMS(proto), \
  29. PARAMS(args), \
  30. PARAMS(tstruct), \
  31. PARAMS(assign), \
  32. PARAMS(print))
  33. #undef TRACE_EVENT_FN
  34. #define TRACE_EVENT_FN(name, proto, args, tstruct, \
  35. assign, print, reg, unreg) \
  36. DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args))
  37. #undef TRACE_EVENT_FN_COND
  38. #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
  39. assign, print, reg, unreg) \
  40. DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args))
  41. #undef TRACE_EVENT_SYSCALL
  42. #define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, print, reg, unreg) \
  43. DEFINE_TRACE_SYSCALL(name, reg, unreg, PARAMS(proto), PARAMS(args))
  44. #undef TRACE_EVENT_NOP
  45. #define TRACE_EVENT_NOP(name, proto, args, struct, assign, print)
  46. #undef DEFINE_EVENT_NOP
  47. #define DEFINE_EVENT_NOP(template, name, proto, args)
  48. #undef DEFINE_EVENT
  49. #define DEFINE_EVENT(template, name, proto, args) \
  50. DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
  51. #undef DEFINE_EVENT_FN
  52. #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
  53. DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args))
  54. #undef DEFINE_EVENT_PRINT
  55. #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
  56. DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
  57. #undef DEFINE_EVENT_CONDITION
  58. #define DEFINE_EVENT_CONDITION(template, name, proto, args, cond) \
  59. DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
  60. #undef DECLARE_TRACE
  61. #define DECLARE_TRACE(name, proto, args) \
  62. DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
  63. #undef DECLARE_TRACE_CONDITION
  64. #define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
  65. DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
  66. #undef DECLARE_TRACE_EVENT
  67. #define DECLARE_TRACE_EVENT(name, proto, args) \
  68. DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
  69. #undef DECLARE_TRACE_EVENT_CONDITION
  70. #define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \
  71. DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
  72. /* If requested, create helpers for calling these tracepoints from Rust. */
  73. #ifdef CREATE_RUST_TRACE_POINTS
  74. #undef DEFINE_RUST_DO_TRACE
  75. #define DEFINE_RUST_DO_TRACE(name, proto, args) \
  76. __DEFINE_RUST_DO_TRACE(name, PARAMS(proto), PARAMS(args))
  77. #endif
  78. #undef TRACE_INCLUDE
  79. #undef __TRACE_INCLUDE
  80. #ifndef TRACE_INCLUDE_FILE
  81. # define TRACE_INCLUDE_FILE TRACE_SYSTEM
  82. # define UNDEF_TRACE_INCLUDE_FILE
  83. #endif
  84. #ifndef TRACE_INCLUDE_PATH
  85. # define __TRACE_INCLUDE(system) <trace/events/system.h>
  86. # define UNDEF_TRACE_INCLUDE_PATH
  87. #else
  88. # define __TRACE_INCLUDE(system) __stringify(TRACE_INCLUDE_PATH/system.h)
  89. #endif
  90. # define TRACE_INCLUDE(system) __TRACE_INCLUDE(system)
  91. /* Let the trace headers be reread */
  92. #define TRACE_HEADER_MULTI_READ
  93. #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
  94. /* Make all open coded DECLARE_TRACE nops */
  95. #undef DECLARE_TRACE
  96. #define DECLARE_TRACE(name, proto, args)
  97. #undef DECLARE_TRACE_CONDITION
  98. #define DECLARE_TRACE_CONDITION(name, proto, args, cond)
  99. #undef DECLARE_TRACE_EVENT
  100. #define DECLARE_TRACE_EVENT(name, proto, args)
  101. #undef DECLARE_TRACE_EVENT_CONDITION
  102. #define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond)
  103. #ifdef TRACEPOINTS_ENABLED
  104. #include <trace/trace_events.h>
  105. #include <trace/perf.h>
  106. #include <trace/bpf_probe.h>
  107. #endif
  108. #undef TRACE_EVENT
  109. #undef TRACE_EVENT_FN
  110. #undef TRACE_EVENT_FN_COND
  111. #undef TRACE_EVENT_SYSCALL
  112. #undef TRACE_EVENT_CONDITION
  113. #undef TRACE_EVENT_NOP
  114. #undef DEFINE_EVENT_NOP
  115. #undef DECLARE_EVENT_CLASS
  116. #undef DEFINE_EVENT
  117. #undef DEFINE_EVENT_FN
  118. #undef DEFINE_EVENT_PRINT
  119. #undef DEFINE_EVENT_CONDITION
  120. #undef TRACE_HEADER_MULTI_READ
  121. #undef DECLARE_TRACE
  122. #undef DECLARE_TRACE_CONDITION
  123. #undef DECLARE_TRACE_EVENT
  124. #undef DECLARE_TRACE_EVENT_CONDITION
  125. /* Only undef what we defined in this file */
  126. #ifdef UNDEF_TRACE_INCLUDE_FILE
  127. # undef TRACE_INCLUDE_FILE
  128. # undef UNDEF_TRACE_INCLUDE_FILE
  129. #endif
  130. #ifdef UNDEF_TRACE_INCLUDE_PATH
  131. # undef TRACE_INCLUDE_PATH
  132. # undef UNDEF_TRACE_INCLUDE_PATH
  133. #endif
  134. #ifdef CREATE_RUST_TRACE_POINTS
  135. # undef DEFINE_RUST_DO_TRACE
  136. # define DEFINE_RUST_DO_TRACE(name, proto, args)
  137. #endif
  138. /* We may be processing more files */
  139. #define CREATE_TRACE_POINTS
  140. #endif /* CREATE_TRACE_POINTS */