trace_export.c 5.1 KB

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