trace_export.c 6.1 KB

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