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