trace_export.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, 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. #include "trace_event_types.h"
  58. #undef TRACE_ZERO_CHAR
  59. #define TRACE_ZERO_CHAR(arg)
  60. #undef TRACE_FIELD
  61. #define TRACE_FIELD(type, item, assign)\
  62. entry->item = assign;
  63. #undef TRACE_FIELD
  64. #define TRACE_FIELD(type, item, assign)\
  65. entry->item = assign;
  66. #undef TP_CMD
  67. #define TP_CMD(cmd...) cmd
  68. #undef TRACE_ENTRY
  69. #define TRACE_ENTRY entry
  70. #undef TRACE_FIELD_SPECIAL
  71. #define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
  72. cmd;
  73. #undef TRACE_EVENT_FORMAT
  74. #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
  75. \
  76. static struct ftrace_event_call __used \
  77. __attribute__((__aligned__(4))) \
  78. __attribute__((section("_ftrace_events"))) event_##call = { \
  79. .name = #call, \
  80. .id = proto, \
  81. .system = __stringify(TRACE_SYSTEM), \
  82. .show_format = ftrace_format_##call, \
  83. }
  84. #include "trace_event_types.h"