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