ftrace_event.h 5.7 KB

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