trace_export.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. /*
  19. * The FTRACE_ENTRY_REG macro allows ftrace entry to define register
  20. * function and thus become accesible via perf.
  21. */
  22. #undef FTRACE_ENTRY_REG
  23. #define FTRACE_ENTRY_REG(name, struct_name, id, tstruct, print, \
  24. filter, regfn) \
  25. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  26. filter)
  27. /* not needed for this file */
  28. #undef __field_struct
  29. #define __field_struct(type, item)
  30. #undef __field
  31. #define __field(type, item) type item;
  32. #undef __field_desc
  33. #define __field_desc(type, container, item) type item;
  34. #undef __array
  35. #define __array(type, item, size) type item[size];
  36. #undef __array_desc
  37. #define __array_desc(type, container, item, size) type item[size];
  38. #undef __dynamic_array
  39. #define __dynamic_array(type, item) type item[];
  40. #undef F_STRUCT
  41. #define F_STRUCT(args...) args
  42. #undef F_printk
  43. #define F_printk(fmt, args...) fmt, args
  44. #undef FTRACE_ENTRY
  45. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  46. struct ____ftrace_##name { \
  47. tstruct \
  48. }; \
  49. static void __always_unused ____ftrace_check_##name(void) \
  50. { \
  51. struct ____ftrace_##name *__entry = NULL; \
  52. \
  53. /* force compile-time check on F_printk() */ \
  54. printk(print); \
  55. }
  56. #undef FTRACE_ENTRY_DUP
  57. #define FTRACE_ENTRY_DUP(name, struct_name, id, tstruct, print, filter) \
  58. FTRACE_ENTRY(name, struct_name, id, PARAMS(tstruct), PARAMS(print), \
  59. filter)
  60. #include "trace_entries.h"
  61. #undef __field
  62. #define __field(type, item) \
  63. ret = trace_define_field(event_call, #type, #item, \
  64. offsetof(typeof(field), item), \
  65. sizeof(field.item), \
  66. is_signed_type(type), filter_type); \
  67. if (ret) \
  68. return ret;
  69. #undef __field_desc
  70. #define __field_desc(type, container, item) \
  71. ret = trace_define_field(event_call, #type, #item, \
  72. offsetof(typeof(field), \
  73. container.item), \
  74. sizeof(field.container.item), \
  75. is_signed_type(type), filter_type); \
  76. if (ret) \
  77. return ret;
  78. #undef __array
  79. #define __array(type, item, len) \
  80. do { \
  81. char *type_str = #type"["__stringify(len)"]"; \
  82. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  83. ret = trace_define_field(event_call, type_str, #item, \
  84. offsetof(typeof(field), item), \
  85. sizeof(field.item), \
  86. is_signed_type(type), filter_type); \
  87. if (ret) \
  88. return ret; \
  89. } while (0);
  90. #undef __array_desc
  91. #define __array_desc(type, container, item, len) \
  92. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  93. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  94. offsetof(typeof(field), \
  95. container.item), \
  96. sizeof(field.container.item), \
  97. is_signed_type(type), filter_type); \
  98. if (ret) \
  99. return ret;
  100. #undef __dynamic_array
  101. #define __dynamic_array(type, item) \
  102. ret = trace_define_field(event_call, #type, #item, \
  103. offsetof(typeof(field), item), \
  104. 0, is_signed_type(type), filter_type);\
  105. if (ret) \
  106. return ret;
  107. #undef FTRACE_ENTRY
  108. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  109. static int __init \
  110. ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
  111. { \
  112. struct struct_name field; \
  113. int ret; \
  114. int filter_type = filter; \
  115. \
  116. tstruct; \
  117. \
  118. return ret; \
  119. }
  120. #include "trace_entries.h"
  121. #undef __entry
  122. #define __entry REC
  123. #undef __field
  124. #define __field(type, item)
  125. #undef __field_desc
  126. #define __field_desc(type, container, item)
  127. #undef __array
  128. #define __array(type, item, len)
  129. #undef __array_desc
  130. #define __array_desc(type, container, item, len)
  131. #undef __dynamic_array
  132. #define __dynamic_array(type, item)
  133. #undef F_printk
  134. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  135. #undef FTRACE_ENTRY_REG
  136. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
  137. regfn) \
  138. \
  139. struct ftrace_event_class __refdata event_class_ftrace_##call = { \
  140. .system = __stringify(TRACE_SYSTEM), \
  141. .define_fields = ftrace_define_fields_##call, \
  142. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  143. .reg = regfn, \
  144. }; \
  145. \
  146. struct ftrace_event_call __used event_##call = { \
  147. .class = &event_class_ftrace_##call, \
  148. { \
  149. .name = #call, \
  150. }, \
  151. .event.type = etype, \
  152. .print_fmt = print, \
  153. .flags = TRACE_EVENT_FL_IGNORE_ENABLE | TRACE_EVENT_FL_USE_CALL_FILTER, \
  154. }; \
  155. struct ftrace_event_call __used \
  156. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
  157. #undef FTRACE_ENTRY
  158. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \
  159. FTRACE_ENTRY_REG(call, struct_name, etype, \
  160. PARAMS(tstruct), PARAMS(print), filter, NULL)
  161. int ftrace_event_is_function(struct ftrace_event_call *call)
  162. {
  163. return call == &event_function;
  164. }
  165. #include "trace_entries.h"