trace_export.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 __always_unused ____ftrace_check_##name(void) \
  41. { \
  42. struct ____ftrace_##name *__entry = NULL; \
  43. \
  44. /* force compile-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_define_field(event_call, #type, #item, \
  54. offsetof(typeof(field), item), \
  55. sizeof(field.item), \
  56. is_signed_type(type), FILTER_OTHER); \
  57. if (ret) \
  58. return ret;
  59. #undef __field_desc
  60. #define __field_desc(type, container, item) \
  61. ret = trace_define_field(event_call, #type, #item, \
  62. offsetof(typeof(field), \
  63. container.item), \
  64. sizeof(field.container.item), \
  65. is_signed_type(type), FILTER_OTHER); \
  66. if (ret) \
  67. return ret;
  68. #undef __array
  69. #define __array(type, item, len) \
  70. do { \
  71. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  72. mutex_lock(&event_storage_mutex); \
  73. snprintf(event_storage, sizeof(event_storage), \
  74. "%s[%d]", #type, len); \
  75. ret = trace_define_field(event_call, event_storage, #item, \
  76. offsetof(typeof(field), item), \
  77. sizeof(field.item), \
  78. is_signed_type(type), FILTER_OTHER); \
  79. mutex_unlock(&event_storage_mutex); \
  80. if (ret) \
  81. return ret; \
  82. } while (0);
  83. #undef __array_desc
  84. #define __array_desc(type, container, item, len) \
  85. BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
  86. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  87. offsetof(typeof(field), \
  88. container.item), \
  89. sizeof(field.container.item), \
  90. is_signed_type(type), FILTER_OTHER); \
  91. if (ret) \
  92. return ret;
  93. #undef __dynamic_array
  94. #define __dynamic_array(type, item) \
  95. ret = trace_define_field(event_call, #type, #item, \
  96. offsetof(typeof(field), item), \
  97. 0, is_signed_type(type), FILTER_OTHER);\
  98. if (ret) \
  99. return ret;
  100. #undef FTRACE_ENTRY
  101. #define FTRACE_ENTRY(name, struct_name, id, tstruct, print) \
  102. int \
  103. ftrace_define_fields_##name(struct ftrace_event_call *event_call) \
  104. { \
  105. struct struct_name field; \
  106. int ret; \
  107. \
  108. tstruct; \
  109. \
  110. return ret; \
  111. }
  112. #include "trace_entries.h"
  113. #undef __entry
  114. #define __entry REC
  115. #undef __field
  116. #define __field(type, item)
  117. #undef __field_desc
  118. #define __field_desc(type, container, item)
  119. #undef __array
  120. #define __array(type, item, len)
  121. #undef __array_desc
  122. #define __array_desc(type, container, item, len)
  123. #undef __dynamic_array
  124. #define __dynamic_array(type, item)
  125. #undef F_printk
  126. #define F_printk(fmt, args...) __stringify(fmt) ", " __stringify(args)
  127. #undef FTRACE_ENTRY
  128. #define FTRACE_ENTRY(call, struct_name, etype, tstruct, print) \
  129. \
  130. struct ftrace_event_class event_class_ftrace_##call = { \
  131. .system = __stringify(TRACE_SYSTEM), \
  132. .define_fields = ftrace_define_fields_##call, \
  133. .fields = LIST_HEAD_INIT(event_class_ftrace_##call.fields),\
  134. }; \
  135. \
  136. struct ftrace_event_call __used event_##call = { \
  137. .name = #call, \
  138. .event.type = etype, \
  139. .class = &event_class_ftrace_##call, \
  140. .print_fmt = print, \
  141. }; \
  142. struct ftrace_event_call __used \
  143. __attribute__((section("_ftrace_events"))) *__event_##call = &event_##call;
  144. #include "trace_entries.h"