trace_export.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  82. mutex_lock(&event_storage_mutex); \
  83. snprintf(event_storage, sizeof(event_storage), \
  84. "%s[%d]", #type, len); \
  85. ret = trace_define_field(event_call, event_storage, #item, \
  86. offsetof(typeof(field), item), \
  87. sizeof(field.item), \
  88. is_signed_type(type), filter_type); \
  89. mutex_unlock(&event_storage_mutex); \
  90. if (ret) \
  91. return ret; \
  92. } while (0);
  93. #undef __array_desc
  94. #define __array_desc(type, container, item, len) \
  95. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  96. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  97. offsetof(typeof(field), \
  98. container.item), \
  99. sizeof(field.container.item), \
  100. is_signed_type(type), filter_type); \
  101. if (ret) \
  102. return ret;
  103. #undef __dynamic_array
  104. #define __dynamic_array(type, item) \
  105. ret = trace_define_field(event_call, #type, #item, \
  106. offsetof(typeof(field), item), \
  107. 0, is_signed_type(type), filter_type);\
  108. if (ret) \
  109. return ret;
  110. #undef FTRACE_ENTRY
  111. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print, filter) \
  112. int \
  113. ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
  114. { \
  115. struct struct_name field; \
  116. int ret; \
  117. int filter_type = filter; \
  118. \
  119. tstruct; \
  120. \
  121. return ret; \
  122. }
  123. #include "trace_entries.h"
  124. #undef __entry
  125. #define __entry REC
  126. #undef __field
  127. #define __field(type, item)
  128. #undef __field_desc
  129. #define __field_desc(type, container, item)
  130. #undef __array
  131. #define __array(type, item, len)
  132. #undef __array_desc
  133. #define __array_desc(type, container, item, len)
  134. #undef __dynamic_array
  135. #define __dynamic_array(type, item)
  136. #undef F_printk
  137. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  138. #undef FTRACE_ENTRY_REG
  139. #define FTRACE_ENTRY_REG(call, struct_name, etype, tstruct, print, filter,\
  140. regfn) \
  141. \
  142. struct ftrace_event_class event_class_ftrace_##call = { \
  143. .system = __stringify(TRACE_SYSTEM), \
  144. .define_fields = ftrace_define_fields_##call, \
  145. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  146. .reg = regfn, \
  147. }; \
  148. \
  149. struct ftrace_event_call __used event_##call = { \
  150. .name = #call, \
  151. .event.type = etype, \
  152. .class = &event_class_ftrace_##call, \
  153. .print_fmt = print, \
  154. .flags = TRACE_EVENT_FL_IGNORE_ENABLE, \
  155. }; \
  156. struct ftrace_event_call __used \
  157. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
  158. #undef FTRACE_ENTRY
  159. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print, filter) \
  160. FTRACE_ENTRY_REG(call, struct_name, etype, \
  161. PARAMS(tstruct), PARAMS(print), filter, NULL)
  162. int ftrace_event_is_function(struct ftrace_event_call *call)
  163. {
  164. return call == &event_function;
  165. }
  166. #include "trace_entries.h"