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