trace_export.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_SYSTEM
  17. #define TRACE_SYSTEM ftrace
  18. /* not needed for this file */
  19. #undef __field_struct
  20. #define __field_struct(type, item)
  21. #undef __field
  22. #define __field(type, item) \
  23. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  24. "offset:%zu;\tsize:%zu;\n", \
  25. offsetof(typeof(field), item), \
  26. sizeof(field.item)); \
  27. if (!ret) \
  28. return 0;
  29. #undef __field_desc
  30. #define __field_desc(type, container, item) \
  31. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  32. "offset:%zu;\tsize:%zu;\n", \
  33. offsetof(typeof(field), container.item), \
  34. sizeof(field.container.item)); \
  35. if (!ret) \
  36. return 0;
  37. #undef __array
  38. #define __array(type, item, len) \
  39. ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
  40. "offset:%zu;\tsize:%zu;\n", \
  41. offsetof(typeof(field), item), \
  42. sizeof(field.item)); \
  43. if (!ret) \
  44. return 0;
  45. #undef __array_desc
  46. #define __array_desc(type, container, item, len) \
  47. ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
  48. "offset:%zu;\tsize:%zu;\n", \
  49. offsetof(typeof(field), container.item), \
  50. sizeof(field.container.item)); \
  51. if (!ret) \
  52. return 0;
  53. #undef __dynamic_array
  54. #define __dynamic_array(type, item) \
  55. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  56. "offset:%zu;\tsize:0;\n", \
  57. offsetof(typeof(field), item)); \
  58. if (!ret) \
  59. return 0;
  60. #undef F_printk
  61. #define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
  62. #undef __entry
  63. #define __entry REC
  64. #undef FTRACE_ENTRY
  65. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  66. static int \
  67. ftrace_format_##name(struct ftrace_event_call *unused, \
  68. struct trace_seq *s) \
  69. { \
  70. struct struct_name field __attribute__((unused)); \
  71. int ret = 0; \
  72. \
  73. tstruct; \
  74. \
  75. trace_seq_printf(s, "\nprint fmt: " print); \
  76. \
  77. return ret; \
  78. }
  79. #undef FTRACE_ENTRY_DUP
  80. #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print) \
  81. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print))
  82. #include "trace_entries.h"
  83. #undef __field
  84. #define __field(type, item) \
  85. ret = trace_define_field(event_call, #type, #item, \
  86. offsetof(typeof(field), item), \
  87. sizeof(field.item), \
  88. is_signed_type(type), FILTER_OTHER); \
  89. if (ret) \
  90. return ret;
  91. #undef __field_desc
  92. #define __field_desc(type, container, item) \
  93. ret = trace_define_field(event_call, #type, #item, \
  94. offsetof(typeof(field), \
  95. container.item), \
  96. sizeof(field.container.item), \
  97. is_signed_type(type), FILTER_OTHER); \
  98. if (ret) \
  99. return ret;
  100. #undef __array
  101. #define __array(type, item, len) \
  102. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  103. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  104. offsetof(typeof(field), item), \
  105. sizeof(field.item), 0, FILTER_OTHER); \
  106. if (ret) \
  107. return ret;
  108. #undef __array_desc
  109. #define __array_desc(type, container, item, len) \
  110. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  111. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  112. offsetof(typeof(field), \
  113. container.item), \
  114. sizeof(field.container.item), 0, \
  115. FILTER_OTHER); \
  116. if (ret) \
  117. return ret;
  118. #undef __dynamic_array
  119. #define __dynamic_array(type, item)
  120. #undef FTRACE_ENTRY
  121. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  122. int \
  123. ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
  124. { \
  125. struct struct_name field; \
  126. int ret; \
  127. \
  128. ret = trace_define_common_fields(event_call); \
  129. if (ret) \
  130. return ret; \
  131. \
  132. tstruct; \
  133. \
  134. return ret; \
  135. }
  136. #include "trace_entries.h"
  137. #undef __field
  138. #define __field(type, item)
  139. #undef __field_desc
  140. #define __field_desc(type, container, item)
  141. #undef __array
  142. #define __array(type, item, len)
  143. #undef __array_desc
  144. #define __array_desc(type, container, item, len)
  145. #undef __dynamic_array
  146. #define __dynamic_array(type, item)
  147. #undef TRACE_ZERO_CHAR
  148. #define TRACE_ZERO_CHAR(arg)
  149. #undef TRACE_FIELD
  150. #define TRACE_FIELD(type, item, assign)\
  151. entry->item = assign;
  152. #undef TRACE_FIELD
  153. #define TRACE_FIELD(type, item, assign)\
  154. entry->item = assign;
  155. #undef TRACE_FIELD_SIGN
  156. #define TRACE_FIELD_SIGN(type, item, assign, is_signed) \
  157. TRACE_FIELD(type, item, assign)
  158. #undef TP_CMD
  159. #define TP_CMD(cmd...) cmd
  160. #undef TRACE_ENTRY
  161. #define TRACE_ENTRY entry
  162. #undef TRACE_FIELD_SPECIAL
  163. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  164. cmd;
  165. #undef FTRACE_ENTRY
  166. #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
  167. static int ftrace_raw_init_event_##call(void); \
  168. \
  169. struct ftrace_event_call __used \
  170. __attribute__((__aligned__(4))) \
  171. __attribute__((section("_ftrace_events"))) event_##call = { \
  172. .name = #call, \
  173. .id = type, \
  174. .system = __stringify(TRACE_SYSTEM), \
  175. .raw_init = ftrace_raw_init_event_##call, \
  176. .show_format = ftrace_format_##call, \
  177. .define_fields = ftrace_define_fields_##call, \
  178. }; \
  179. static int ftrace_raw_init_event_##call(void) \
  180. { \
  181. INIT_LIST_HEAD(&event_##call.fields); \
  182. return 0; \
  183. } \
  184. #include "trace_entries.h"