trace_export.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * trace_export.c - export basic ftrace utilities to user space
  3. *
  4. * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
  5. */
  6. #include <linux/stringify.h>
  7. #include <linux/kallsyms.h>
  8. #include <linux/seq_file.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/uaccess.h>
  11. #include <linux/ftrace.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/fs.h>
  15. #include "trace_output.h"
  16. #undef TRACE_STRUCT
  17. #define TRACE_STRUCT(args...) args
  18. extern void __bad_type_size(void);
  19. #undef TRACE_FIELD
  20. #define TRACE_FIELD(type, item, assign) \
  21. if (sizeof(type) != sizeof(field.item)) \
  22. __bad_type_size(); \
  23. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  24. "offset:%u;\tsize:%u;\n", \
  25. (unsigned int)offsetof(typeof(field), item), \
  26. (unsigned int)sizeof(field.item)); \
  27. if (!ret) \
  28. return 0;
  29. #undef TRACE_FIELD_SPECIAL
  30. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  31. ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t" \
  32. "offset:%u;\tsize:%u;\n", \
  33. (unsigned int)offsetof(typeof(field), item), \
  34. (unsigned int)sizeof(field.item)); \
  35. if (!ret) \
  36. return 0;
  37. #undef TRACE_FIELD_ZERO_CHAR
  38. #define TRACE_FIELD_ZERO_CHAR(item) \
  39. ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \
  40. "offset:%u;\tsize:0;\n", \
  41. (unsigned int)offsetof(typeof(field), item)); \
  42. if (!ret) \
  43. return 0;
  44. #undef TRACE_FIELD_SIGN
  45. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  46. TRACE_FIELD(type, item, assign)
  47. #undef TP_RAW_FMT
  48. #define TP_RAW_FMT(args...) args
  49. #undef TRACE_EVENT_FORMAT
  50. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  51. static int \
  52. ftrace_format_##call(struct ftrace_event_call *unused, \
  53. struct trace_seq *s) \
  54. { \
  55. struct args field; \
  56. int ret; \
  57. \
  58. tstruct; \
  59. \
  60. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  61. \
  62. return ret; \
  63. }
  64. #undef TRACE_EVENT_FORMAT_NOFILTER
  65. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  66. tpfmt) \
  67. static int \
  68. ftrace_format_##call(struct ftrace_event_call *unused, \
  69. struct trace_seq *s) \
  70. { \
  71. struct args field; \
  72. int ret; \
  73. \
  74. tstruct; \
  75. \
  76. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  77. \
  78. return ret; \
  79. }
  80. #include "trace_event_types.h"
  81. #undef TRACE_ZERO_CHAR
  82. #define TRACE_ZERO_CHAR(arg)
  83. #undef TRACE_FIELD
  84. #define TRACE_FIELD(type, item, assign)\
  85. entry->item = assign;
  86. #undef TRACE_FIELD
  87. #define TRACE_FIELD(type, item, assign)\
  88. entry->item = assign;
  89. #undef TRACE_FIELD_SIGN
  90. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  91. TRACE_FIELD(type, item, assign)
  92. #undef TP_CMD
  93. #define TP_CMD(cmd...) cmd
  94. #undef TRACE_ENTRY
  95. #define TRACE_ENTRY entry
  96. #undef TRACE_FIELD_SPECIAL
  97. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  98. cmd;
  99. #undef TRACE_EVENT_FORMAT
  100. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  101. int ftrace_define_fields_##call(struct ftrace_event_call *event_call); \
  102. static int ftrace_raw_init_event_##call(void); \
  103. \
  104. struct ftrace_event_call __used \
  105. __attribute__((__aligned__(4))) \
  106. __attribute__((section("_ftrace_events"))) event_##call = { \
  107. .name = #call, \
  108. .id = proto, \
  109. .system = __stringify(TRACE_SYSTEM), \
  110. .raw_init = ftrace_raw_init_event_##call, \
  111. .show_format = ftrace_format_##call, \
  112. .define_fields = ftrace_define_fields_##call, \
  113. }; \
  114. static int ftrace_raw_init_event_##call(void) \
  115. { \
  116. INIT_LIST_HEAD(&event_##call.fields); \
  117. init_preds(&event_##call); \
  118. return 0; \
  119. } \
  120. #undef TRACE_EVENT_FORMAT_NOFILTER
  121. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  122. tpfmt) \
  123. \
  124. struct ftrace_event_call __used \
  125. __attribute__((__aligned__(4))) \
  126. __attribute__((section("_ftrace_events"))) event_##call = { \
  127. .name = #call, \
  128. .id = proto, \
  129. .system = __stringify(TRACE_SYSTEM), \
  130. .show_format = ftrace_format_##call, \
  131. };
  132. #include "trace_event_types.h"
  133. #undef TRACE_FIELD
  134. #define TRACE_FIELD(type, item, assign) \
  135. ret = trace_define_field(event_call, #type, #item, \
  136. offsetof(typeof(field), item), \
  137. sizeof(field.item), \
  138. is_signed_type(type), FILTER_OTHER); \
  139. if (ret) \
  140. return ret;
  141. #undef TRACE_FIELD_SPECIAL
  142. #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
  143. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  144. offsetof(typeof(field), item), \
  145. sizeof(field.item), 0, FILTER_OTHER); \
  146. if (ret) \
  147. return ret;
  148. #undef TRACE_FIELD_SIGN
  149. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  150. ret = trace_define_field(event_call, #type, #item, \
  151. offsetof(typeof(field), item), \
  152. sizeof(field.item), is_signed, \
  153. FILTER_OTHER); \
  154. if (ret) \
  155. return ret;
  156. #undef TRACE_FIELD_ZERO_CHAR
  157. #define TRACE_FIELD_ZERO_CHAR(item)
  158. #undef TRACE_EVENT_FORMAT
  159. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  160. int \
  161. ftrace_define_fields_##call(struct ftrace_event_call *event_call) \
  162. { \
  163. struct args field; \
  164. int ret; \
  165. \
  166. ret = trace_define_common_fields(event_call); \
  167. if (ret) \
  168. return ret; \
  169. \
  170. tstruct; \
  171. \
  172. return ret; \
  173. }
  174. #undef TRACE_EVENT_FORMAT_NOFILTER
  175. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  176. tpfmt)
  177. #include "trace_event_types.h"