ftrace_event.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. #include <linux/percpu.h>
  6. struct trace_array;
  7. struct tracer;
  8. struct dentry;
  9. DECLARE_PER_CPU(struct trace_seq, ftrace_event_seq);
  10. struct trace_print_flags {
  11. unsigned long mask;
  12. const char *name;
  13. };
  14. const char *ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
  15. unsigned long flags,
  16. const struct trace_print_flags *flag_array);
  17. const char *ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  18. const struct trace_print_flags *symbol_array);
  19. /*
  20. * The trace entry - the most basic unit of tracing. This is what
  21. * is printed in the end as a single line in the trace output, such as:
  22. *
  23. * bash-15816 [01] 235.197585: idle_cpu <- irq_enter
  24. */
  25. struct trace_entry {
  26. unsigned short type;
  27. unsigned char flags;
  28. unsigned char preempt_count;
  29. int pid;
  30. };
  31. #define FTRACE_MAX_EVENT \
  32. ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
  33. /*
  34. * Trace iterator - used by printout routines who present trace
  35. * results to users and which routines might sleep, etc:
  36. */
  37. struct trace_iterator {
  38. struct trace_array *tr;
  39. struct tracer *trace;
  40. void *private;
  41. int cpu_file;
  42. struct mutex mutex;
  43. struct ring_buffer_iter *buffer_iter[NR_CPUS];
  44. unsigned long iter_flags;
  45. /* The below is zeroed out in pipe_read */
  46. struct trace_seq seq;
  47. struct trace_entry *ent;
  48. int cpu;
  49. u64 ts;
  50. loff_t pos;
  51. long idx;
  52. cpumask_var_t started;
  53. };
  54. typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
  55. int flags);
  56. struct trace_event {
  57. struct hlist_node node;
  58. struct list_head list;
  59. int type;
  60. trace_print_func trace;
  61. trace_print_func raw;
  62. trace_print_func hex;
  63. trace_print_func binary;
  64. };
  65. extern int register_ftrace_event(struct trace_event *event);
  66. extern int unregister_ftrace_event(struct trace_event *event);
  67. /* Return values for print_line callback */
  68. enum print_line_t {
  69. TRACE_TYPE_PARTIAL_LINE = 0, /* Retry after flushing the seq */
  70. TRACE_TYPE_HANDLED = 1,
  71. TRACE_TYPE_UNHANDLED = 2, /* Relay to other output functions */
  72. TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
  73. };
  74. void tracing_generic_entry_update(struct trace_entry *entry,
  75. unsigned long flags,
  76. int pc);
  77. struct ring_buffer_event *
  78. trace_current_buffer_lock_reserve(struct ring_buffer **current_buffer,
  79. int type, unsigned long len,
  80. unsigned long flags, int pc);
  81. void trace_current_buffer_unlock_commit(struct ring_buffer *buffer,
  82. struct ring_buffer_event *event,
  83. unsigned long flags, int pc);
  84. void trace_nowake_buffer_unlock_commit(struct ring_buffer *buffer,
  85. struct ring_buffer_event *event,
  86. unsigned long flags, int pc);
  87. void trace_current_buffer_discard_commit(struct ring_buffer *buffer,
  88. struct ring_buffer_event *event);
  89. void tracing_record_cmdline(struct task_struct *tsk);
  90. struct event_filter;
  91. struct ftrace_event_call {
  92. struct list_head list;
  93. char *name;
  94. char *system;
  95. struct dentry *dir;
  96. struct trace_event *event;
  97. int enabled;
  98. int (*regfunc)(void *);
  99. void (*unregfunc)(void *);
  100. int id;
  101. int (*raw_init)(void);
  102. int (*show_format)(struct ftrace_event_call *call,
  103. struct trace_seq *s);
  104. int (*define_fields)(struct ftrace_event_call *);
  105. struct list_head fields;
  106. int filter_active;
  107. struct event_filter *filter;
  108. void *mod;
  109. void *data;
  110. atomic_t profile_count;
  111. int (*profile_enable)(struct ftrace_event_call *);
  112. void (*profile_disable)(struct ftrace_event_call *);
  113. };
  114. #define MAX_FILTER_PRED 32
  115. #define MAX_FILTER_STR_VAL 128
  116. extern void destroy_preds(struct ftrace_event_call *call);
  117. extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
  118. extern int filter_current_check_discard(struct ring_buffer *buffer,
  119. struct ftrace_event_call *call,
  120. void *rec,
  121. struct ring_buffer_event *event);
  122. enum {
  123. FILTER_OTHER = 0,
  124. FILTER_STATIC_STRING,
  125. FILTER_DYN_STRING,
  126. FILTER_PTR_STRING,
  127. };
  128. extern int trace_define_field(struct ftrace_event_call *call,
  129. const char *type, const char *name,
  130. int offset, int size, int is_signed,
  131. int filter_type);
  132. extern int trace_define_common_fields(struct ftrace_event_call *call);
  133. #define is_signed_type(type) (((type)(-1)) < 0)
  134. int trace_set_clr_event(const char *system, const char *event, int set);
  135. /*
  136. * The double __builtin_constant_p is because gcc will give us an error
  137. * if we try to allocate the static variable to fmt if it is not a
  138. * constant. Even with the outer if statement optimizing out.
  139. */
  140. #define event_trace_printk(ip, fmt, args...) \
  141. do { \
  142. __trace_printk_check_format(fmt, ##args); \
  143. tracing_record_cmdline(current); \
  144. if (__builtin_constant_p(fmt)) { \
  145. static const char *trace_printk_fmt \
  146. __attribute__((section("__trace_printk_fmt"))) = \
  147. __builtin_constant_p(fmt) ? fmt : NULL; \
  148. \
  149. __trace_bprintk(ip, trace_printk_fmt, ##args); \
  150. } else \
  151. __trace_printk(ip, fmt, ##args); \
  152. } while (0)
  153. #endif /* _LINUX_FTRACE_EVENT_H */