trace_export.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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;\n", \
  55. offsetof(typeof(field), item), \
  56. sizeof(field.item)); \
  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;\n", \
  63. offsetof(typeof(field), container.item), \
  64. sizeof(field.container.item)); \
  65. if (!ret) \
  66. return 0;
  67. #undef __array
  68. #define __array(type, item, len) \
  69. ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
  70. "offset:%zu;\tsize:%zu;\n", \
  71. offsetof(typeof(field), item), \
  72. sizeof(field.item)); \
  73. if (!ret) \
  74. return 0;
  75. #undef __array_desc
  76. #define __array_desc(type, container, item, len) \
  77. ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
  78. "offset:%zu;\tsize:%zu;\n", \
  79. offsetof(typeof(field), container.item), \
  80. sizeof(field.container.item)); \
  81. if (!ret) \
  82. return 0;
  83. #undef __dynamic_array
  84. #define __dynamic_array(type, item) \
  85. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  86. "offset:%zu;\tsize:0;\n", \
  87. offsetof(typeof(field), item)); \
  88. if (!ret) \
  89. return 0;
  90. #undef F_printk
  91. #define F_printk(fmt, args...) "%s, %s\n", #fmt, __stringify(args)
  92. #undef __entry
  93. #define __entry REC
  94. #undef FTRACE_ENTRY
  95. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  96. static int \
  97. ftrace_format_##name(struct ftrace_event_call *unused, \
  98. struct trace_seq *s) \
  99. { \
  100. struct struct_name field __attribute__((unused)); \
  101. int ret = 0; \
  102. \
  103. tstruct; \
  104. \
  105. trace_seq_printf(s, "\nprint fmt: " print); \
  106. \
  107. return ret; \
  108. }
  109. #include "trace_entries.h"
  110. #undef __field
  111. #define __field(type, item) \
  112. ret = trace_define_field(event_call, #type, #item, \
  113. offsetof(typeof(field), item), \
  114. sizeof(field.item), \
  115. is_signed_type(type), FILTER_OTHER); \
  116. if (ret) \
  117. return ret;
  118. #undef __field_desc
  119. #define __field_desc(type, container, item) \
  120. ret = trace_define_field(event_call, #type, #item, \
  121. offsetof(typeof(field), \
  122. container.item), \
  123. sizeof(field.container.item), \
  124. is_signed_type(type), FILTER_OTHER); \
  125. if (ret) \
  126. return ret;
  127. #undef __array
  128. #define __array(type, item, len) \
  129. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  130. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  131. offsetof(typeof(field), item), \
  132. sizeof(field.item), 0, FILTER_OTHER); \
  133. if (ret) \
  134. return ret;
  135. #undef __array_desc
  136. #define __array_desc(type, container, item, len) \
  137. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  138. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  139. offsetof(typeof(field), \
  140. container.item), \
  141. sizeof(field.container.item), 0, \
  142. FILTER_OTHER); \
  143. if (ret) \
  144. return ret;
  145. #undef __dynamic_array
  146. #define __dynamic_array(type, item)
  147. #undef FTRACE_ENTRY
  148. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  149. int \
  150. ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
  151. { \
  152. struct struct_name field; \
  153. int ret; \
  154. \
  155. ret = trace_define_common_fields(event_call); \
  156. if (ret) \
  157. return ret; \
  158. \
  159. tstruct; \
  160. \
  161. return ret; \
  162. }
  163. #include "trace_entries.h"
  164. #undef __field
  165. #define __field(type, item)
  166. #undef __field_desc
  167. #define __field_desc(type, container, item)
  168. #undef __array
  169. #define __array(type, item, len)
  170. #undef __array_desc
  171. #define __array_desc(type, container, item, len)
  172. #undef __dynamic_array
  173. #define __dynamic_array(type, item)
  174. #undef FTRACE_ENTRY
  175. #define FTRACE_ENTRY(call, struct_name, type, tstruct, print) \
  176. static int ftrace_raw_init_event_##call(void); \
  177. \
  178. struct ftrace_event_call __used \
  179. __attribute__((__aligned__(4))) \
  180. __attribute__((section("_ftrace_events"))) event_##call = { \
  181. .name = #call, \
  182. .id = type, \
  183. .system = __stringify(TRACE_SYSTEM), \
  184. .raw_init = ftrace_raw_init_event_##call, \
  185. .show_format = ftrace_format_##call, \
  186. .define_fields = ftrace_define_fields_##call, \
  187. }; \
  188. static int ftrace_raw_init_event_##call(void) \
  189. { \
  190. INIT_LIST_HEAD(&event_##call.fields); \
  191. return 0; \
  192. } \
  193. #include "trace_entries.h"