trace-events-sample.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Notice that this file is not protected like a normal header.
  3. * We also must allow for rereading of this file. The
  4. *
  5. * || defined(TRACE_HEADER_MULTI_READ)
  6. *
  7. * serves this purpose.
  8. */
  9. #if !defined(_TRACE_EVENT_SAMPLE_H) || defined(TRACE_HEADER_MULTI_READ)
  10. #define _TRACE_EVENT_SAMPLE_H
  11. /*
  12. * All trace headers should include tracepoint.h, until we finally
  13. * make it into a standard header.
  14. */
  15. #include <linux/tracepoint.h>
  16. /*
  17. * If TRACE_SYSTEM is defined, that will be the directory created
  18. * in the ftrace directory under /debugfs/tracing/events/<system>
  19. *
  20. * The define_trace.h belowe will also look for a file name of
  21. * TRACE_SYSTEM.h where TRACE_SYSTEM is what is defined here.
  22. *
  23. * If you want a different system than file name, you can override
  24. * the header name by defining TRACE_INCLUDE_FILE
  25. *
  26. * If this file was called, goofy.h, then we would define:
  27. *
  28. * #define TRACE_INCLUDE_FILE goofy
  29. *
  30. */
  31. #undef TRACE_SYSTEM
  32. #define TRACE_SYSTEM sample
  33. /*
  34. * The TRACE_EVENT macro is broken up into 5 parts.
  35. *
  36. * name: name of the trace point. This is also how to enable the tracepoint.
  37. * A function called trace_foo_bar() will be created.
  38. *
  39. * proto: the prototype of the function trace_foo_bar()
  40. * Here it is trace_foo_bar(char *foo, int bar).
  41. *
  42. * args: must match the arguments in the prototype.
  43. * Here it is simply "foo, bar".
  44. *
  45. * struct: This defines the way the data will be stored in the ring buffer.
  46. * There are currently two types of elements. __field and __array.
  47. * a __field is broken up into (type, name). Where type can be any
  48. * type but an array.
  49. * For an array. there are three fields. (type, name, size). The
  50. * type of elements in the array, the name of the field and the size
  51. * of the array.
  52. *
  53. * __array( char, foo, 10) is the same as saying char foo[10].
  54. *
  55. * fast_assign: This is a C like function that is used to store the items
  56. * into the ring buffer.
  57. *
  58. * printk: This is a way to print out the data in pretty print. This is
  59. * useful if the system crashes and you are logging via a serial line,
  60. * the data can be printed to the console using this "printk" method.
  61. *
  62. * Note, that for both the assign and the printk, __entry is the handler
  63. * to the data structure in the ring buffer, and is defined by the
  64. * TP_STRUCT__entry.
  65. */
  66. TRACE_EVENT(foo_bar,
  67. TP_PROTO(char *foo, int bar),
  68. TP_ARGS(foo, bar),
  69. TP_STRUCT__entry(
  70. __array( char, foo, 10 )
  71. __field( int, bar )
  72. ),
  73. TP_fast_assign(
  74. strncpy(__entry->foo, foo, 10);
  75. __entry->bar = bar;
  76. ),
  77. TP_printk("foo %s %d", __entry->foo, __entry->bar)
  78. );
  79. #endif
  80. /***** NOTICE! The #if protection ends here. *****/
  81. /*
  82. * There are several ways I could have done this. If I left out the
  83. * TRACE_INCLUDE_PATH, then it would default to the kernel source
  84. * include/trace/events directory.
  85. *
  86. * I could specify a path from the define_trace.h file back to this
  87. * file.
  88. *
  89. * #define TRACE_INCLUDE_PATH ../../samples/trace_events
  90. *
  91. * But I chose to simply make it use the current directory and then in
  92. * the Makefile I added:
  93. *
  94. * CFLAGS_trace-events-sample.o := -I$(PWD)/samples/trace_events/
  95. *
  96. * This will make sure the current path is part of the include
  97. * structure for our file so that we can find it.
  98. *
  99. * I could have made only the top level directory the include:
  100. *
  101. * CFLAGS_trace-events-sample.o := -I$(PWD)
  102. *
  103. * And then let the path to this directory be the TRACE_INCLUDE_PATH:
  104. *
  105. * #define TRACE_INCLUDE_PATH samples/trace_events
  106. *
  107. * But then if something defines "samples" or "trace_events" then we
  108. * could risk that being converted too, and give us an unexpected
  109. * result.
  110. */
  111. #undef TRACE_INCLUDE_PATH
  112. #undef TRACE_INCLUDE_FILE
  113. #define TRACE_INCLUDE_PATH .
  114. /*
  115. * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
  116. */
  117. #define TRACE_INCLUDE_FILE trace-events-sample
  118. #include <trace/define_trace.h>