ftrace_event.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #ifndef _LINUX_FTRACE_EVENT_H
  2. #define _LINUX_FTRACE_EVENT_H
  3. #include <linux/trace_seq.h>
  4. #include <linux/ring_buffer.h>
  5. struct trace_array;
  6. struct tracer;
  7. /*
  8. * The trace entry - the most basic unit of tracing. This is what
  9. * is printed in the end as a single line in the trace output, such as:
  10. *
  11. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  12. */
  13. struct trace_entry {
  14. unsigned char type;
  15. unsigned char flags;
  16. unsigned char preempt_count;
  17. int pid;
  18. int tgid;
  19. };
  20. /*
  21. * Trace iterator - used by printout routines who present trace
  22. * results to users and which routines might sleep, etc:
  23. */
  24. struct trace_iterator {
  25. struct trace_array *tr;
  26. struct tracer *trace;
  27. void *private;
  28. int cpu_file;
  29. struct mutex mutex;
  30. struct ring_buffer_iter *buffer_iter[NR_CPUS];
  31. /* The below is zeroed out in pipe_read */
  32. struct trace_seq seq;
  33. struct trace_entry *ent;
  34. int cpu;
  35. u64 ts;
  36. unsigned long iter_flags;
  37. loff_t pos;
  38. long idx;
  39. cpumask_var_t started;
  40. };
  41. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  42. int flags);
  43. struct trace_event {
  44. struct hlist_node node;
  45. int type;
  46. trace_print_func trace;
  47. trace_print_func raw;
  48. trace_print_func hex;
  49. trace_print_func binary;
  50. };
  51. extern int register_ftrace_event(struct trace_event *event);
  52. extern int unregister_ftrace_event(struct trace_event *event);
  53. /* Return values for print_line callback */
  54. enum print_line_t {
  55. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  56. TRACE_TYPE_HANDLED = 1,
  57. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  58. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  59. };
  60. struct ring_buffer_event *
  61. trace_current_buffer_lock_reserve(unsigned char type, unsigned long len,
  62. unsigned long flags, int pc);
  63. void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
  64. unsigned long flags, int pc);
  65. void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
  66. unsigned long flags, int pc);
  67. void trace_current_buffer_discard_commit(struct ring_buffer_event *event);
  68. void tracing_record_cmdline(struct task_struct *tsk);
  69. struct ftrace_event_call {
  70. struct list_head list;
  71. char *name;
  72. char *system;
  73. struct dentry *dir;
  74. int enabled;
  75. int (*regfunc)(void);
  76. void (*unregfunc)(void);
  77. int id;
  78. int (*raw_init)(void);
  79. int (*show_format)(struct trace_seq *s);
  80. int (*define_fields)(void);
  81. struct list_head fields;
  82. int n_preds;
  83. struct filter_pred **preds;
  84. #ifdef CONFIG_EVENT_PROFILE
  85. atomic_t profile_count;
  86. int (*profile_enable)(struct ftrace_event_call *);
  87. void (*profile_disable)(struct ftrace_event_call *);
  88. #endif
  89. };
  90. #define MAX_FILTER_PRED 8
  91. #define MAX_FILTER_STR_VAL 128
  92. extern int init_preds(struct ftrace_event_call *call);
  93. extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
  94. extern int filter_current_check_discard(struct ftrace_event_call *call,
  95. void *rec,
  96. struct ring_buffer_event *event);
  97. extern int trace_define_field(struct ftrace_event_call *call, char *type,
  98. char *name, int offset, int size);
  99. /*
  100. * The double __builtin_constant_p is because gcc will give us an error
  101. * if we try to allocate the static variable to fmt if it is not a
  102. * constant. Even with the outer if statement optimizing out.
  103. */
  104. #define event_trace_printk(ip, fmt, args...) \
  105. do { \
  106. __trace_printk_check_format(fmt, ##args); \
  107. tracing_record_cmdline(current); \
  108. if (__builtin_constant_p(fmt)) { \
  109. static const char *trace_printk_fmt \
  110. __attribute__((section("__trace_printk_fmt"))) = \
  111. __builtin_constant_p(fmt) ? fmt : NULL; \
  112. \
  113. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  114. } else \
  115. __trace_printk(ip, fmt, ##args); \
  116. } while (0)
  117. #define __common_field(type, item) \
  118. ret = trace_define_field(event_call, #type, "common_" #item, \
  119. offsetof(typeof(field.ent), item), \
  120. sizeof(field.ent.item)); \
  121. if (ret) \
  122. return ret;
  123. #endif /* _LINUX_FTRACE_EVENT_H */