trace_export.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 trace_seq *s) \
  53. { \
  54. struct args field; \
  55. int ret; \
  56. \
  57. tstruct; \
  58. \
  59. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  60. \
  61. return ret; \
  62. }
  63. #undef TRACE_EVENT_FORMAT_NOFILTER
  64. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  65. tpfmt) \
  66. static int \
  67. ftrace_format_##call(struct trace_seq *s) \
  68. { \
  69. struct args field; \
  70. int ret; \
  71. \
  72. tstruct; \
  73. \
  74. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  75. \
  76. return ret; \
  77. }
  78. #include "trace_event_types.h"
  79. #undef TRACE_ZERO_CHAR
  80. #define TRACE_ZERO_CHAR(arg)
  81. #undef TRACE_FIELD
  82. #define TRACE_FIELD(type, item, assign)\
  83. entry->item = assign;
  84. #undef TRACE_FIELD
  85. #define TRACE_FIELD(type, item, assign)\
  86. entry->item = assign;
  87. #undef TRACE_FIELD_SIGN
  88. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  89. TRACE_FIELD(type, item, assign)
  90. #undef TP_CMD
  91. #define TP_CMD(cmd...) cmd
  92. #undef TRACE_ENTRY
  93. #define TRACE_ENTRY entry
  94. #undef TRACE_FIELD_SPECIAL
  95. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  96. cmd;
  97. #undef TRACE_EVENT_FORMAT
  98. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  99. int ftrace_define_fields_##call(void); \
  100. static int ftrace_raw_init_event_##call(void); \
  101. \
  102. struct ftrace_event_call __used \
  103. __attribute__((__aligned__(4))) \
  104. __attribute__((section("_ftrace_events"))) event_##call = { \
  105. .name = #call, \
  106. .id = proto, \
  107. .system = __stringify(TRACE_SYSTEM), \
  108. .raw_init = ftrace_raw_init_event_##call, \
  109. .show_format = ftrace_format_##call, \
  110. .define_fields = ftrace_define_fields_##call, \
  111. }; \
  112. static int ftrace_raw_init_event_##call(void) \
  113. { \
  114. INIT_LIST_HEAD(&event_##call.fields); \
  115. init_preds(&event_##call); \
  116. return 0; \
  117. } \
  118. #undef TRACE_EVENT_FORMAT_NOFILTER
  119. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  120. tpfmt) \
  121. \
  122. struct ftrace_event_call __used \
  123. __attribute__((__aligned__(4))) \
  124. __attribute__((section("_ftrace_events"))) event_##call = { \
  125. .name = #call, \
  126. .id = proto, \
  127. .system = __stringify(TRACE_SYSTEM), \
  128. .show_format = ftrace_format_##call, \
  129. };
  130. #include "trace_event_types.h"
  131. #undef TRACE_FIELD
  132. #define TRACE_FIELD(type, item, assign) \
  133. ret = trace_define_field(event_call, #type, #item, \
  134. offsetof(typeof(field), item), \
  135. sizeof(field.item), is_signed_type(type)); \
  136. if (ret) \
  137. return ret;
  138. #undef TRACE_FIELD_SPECIAL
  139. #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
  140. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  141. offsetof(typeof(field), item), \
  142. sizeof(field.item), 0); \
  143. if (ret) \
  144. return ret;
  145. #undef TRACE_FIELD_SIGN
  146. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  147. ret = trace_define_field(event_call, #type, #item, \
  148. offsetof(typeof(field), item), \
  149. sizeof(field.item), is_signed); \
  150. if (ret) \
  151. return ret;
  152. #undef TRACE_FIELD_ZERO_CHAR
  153. #define TRACE_FIELD_ZERO_CHAR(item)
  154. #undef TRACE_EVENT_FORMAT
  155. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  156. int \
  157. ftrace_define_fields_##call(void) \
  158. { \
  159. struct ftrace_event_call *event_call = &event_##call; \
  160. struct args field; \
  161. int ret; \
  162. \
  163. __common_field(unsigned char, type, 0); \
  164. __common_field(unsigned char, flags, 0); \
  165. __common_field(unsigned char, preempt_count, 0); \
  166. __common_field(int, pid, 1); \
  167. __common_field(int, tgid, 1); \
  168. \
  169. tstruct; \
  170. \
  171. return ret; \
  172. }
  173. #undef TRACE_EVENT_FORMAT_NOFILTER
  174. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  175. tpfmt)
  176. #include "trace_event_types.h"