trace_export.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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_STRUCT
  17. #define TRACE_STRUCT(args...) args
  18. #undef TRACE_FIELD
  19. #define TRACE_FIELD(type, item, assign) \
  20. ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
  21. "offset:%u;\tsize:%u;\n", \
  22. (unsigned int)offsetof(typeof(field), item), \
  23. (unsigned int)sizeof(field.item)); \
  24. if (!ret) \
  25. return 0;
  26. #undef TRACE_FIELD_SPECIAL
  27. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  28. ret = trace_seq_printf(s, "\tfield special:" #type_item ";\t" \
  29. "offset:%u;\tsize:%u;\n", \
  30. (unsigned int)offsetof(typeof(field), item), \
  31. (unsigned int)sizeof(field.item)); \
  32. if (!ret) \
  33. return 0;
  34. #undef TRACE_FIELD_ZERO_CHAR
  35. #define TRACE_FIELD_ZERO_CHAR(item) \
  36. ret = trace_seq_printf(s, "\tfield:char " #item ";\t" \
  37. "offset:%u;\tsize:0;\n", \
  38. (unsigned int)offsetof(typeof(field), item)); \
  39. if (!ret) \
  40. return 0;
  41. #undef TP_RAW_FMT
  42. #define TP_RAW_FMT(args...) args
  43. #undef TRACE_EVENT_FORMAT
  44. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  45. static int \
  46. ftrace_format_##call(struct trace_seq *s) \
  47. { \
  48. struct args field; \
  49. int ret; \
  50. \
  51. tstruct; \
  52. \
  53. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  54. \
  55. return ret; \
  56. }
  57. #undef TRACE_EVENT_FORMAT_NOFILTER
  58. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  59. tpfmt) \
  60. static int \
  61. ftrace_format_##call(struct trace_seq *s) \
  62. { \
  63. struct args field; \
  64. int ret; \
  65. \
  66. tstruct; \
  67. \
  68. trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
  69. \
  70. return ret; \
  71. }
  72. #include "trace_event_types.h"
  73. #undef TRACE_ZERO_CHAR
  74. #define TRACE_ZERO_CHAR(arg)
  75. #undef TRACE_FIELD
  76. #define TRACE_FIELD(type, item, assign)\
  77. entry->item = assign;
  78. #undef TRACE_FIELD
  79. #define TRACE_FIELD(type, item, assign)\
  80. entry->item = assign;
  81. #undef TP_CMD
  82. #define TP_CMD(cmd...) cmd
  83. #undef TRACE_ENTRY
  84. #define TRACE_ENTRY entry
  85. #undef TRACE_FIELD_SPECIAL
  86. #define TRACE_FIELD_SPECIAL(type_item, item, len, cmd) \
  87. cmd;
  88. #undef TRACE_EVENT_FORMAT
  89. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  90. int ftrace_define_fields_##call(void); \
  91. static int ftrace_raw_init_event_##call(void); \
  92. \
  93. struct ftrace_event_call __used \
  94. __attribute__((__aligned__(4))) \
  95. __attribute__((section("_ftrace_events"))) event_##call = { \
  96. .name = #call, \
  97. .id = proto, \
  98. .system = __stringify(TRACE_SYSTEM), \
  99. .raw_init = ftrace_raw_init_event_##call, \
  100. .show_format = ftrace_format_##call, \
  101. .define_fields = ftrace_define_fields_##call, \
  102. }; \
  103. static int ftrace_raw_init_event_##call(void) \
  104. { \
  105. INIT_LIST_HEAD(&event_##call.fields); \
  106. return 0; \
  107. } \
  108. #undef TRACE_EVENT_FORMAT_NOFILTER
  109. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  110. tpfmt) \
  111. \
  112. struct ftrace_event_call __used \
  113. __attribute__((__aligned__(4))) \
  114. __attribute__((section("_ftrace_events"))) event_##call = { \
  115. .name = #call, \
  116. .id = proto, \
  117. .system = __stringify(TRACE_SYSTEM), \
  118. .show_format = ftrace_format_##call, \
  119. };
  120. #include "trace_event_types.h"
  121. #undef TRACE_FIELD
  122. #define TRACE_FIELD(type, item, assign) \
  123. ret = trace_define_field(event_call, #type, #item, \
  124. offsetof(typeof(field), item), \
  125. sizeof(field.item)); \
  126. if (ret) \
  127. return ret;
  128. #undef TRACE_FIELD_SPECIAL
  129. #define TRACE_FIELD_SPECIAL(type, item, len, cmd) \
  130. ret = trace_define_field(event_call, #type "[" #len "]", #item, \
  131. offsetof(typeof(field), item), \
  132. sizeof(field.item)); \
  133. if (ret) \
  134. return ret;
  135. #undef TRACE_FIELD_ZERO_CHAR
  136. #define TRACE_FIELD_ZERO_CHAR(item)
  137. #undef TRACE_EVENT_FORMAT
  138. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  139. int \
  140. ftrace_define_fields_##call(void) \
  141. { \
  142. struct ftrace_event_call *event_call = &event_##call; \
  143. struct args field; \
  144. int ret; \
  145. \
  146. __common_field(unsigned char, type); \
  147. __common_field(unsigned char, flags); \
  148. __common_field(unsigned char, preempt_count); \
  149. __common_field(int, pid); \
  150. __common_field(int, tgid); \
  151. \
  152. tstruct; \
  153. \
  154. return ret; \
  155. }
  156. #undef TRACE_EVENT_FORMAT_NOFILTER
  157. #define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, \
  158. tpfmt)
  159. #include "trace_event_types.h"