blob: 07e0a6d64a24973045025b62003ac5a1b5e58ed4 [file] [log] [blame]
Steven Rostedt97f20252009-04-13 11:20:49 -04001#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;
Steven Rostedt6d723732009-04-10 14:53:50 -040010struct dentry;
Steven Rostedt97f20252009-04-13 11:20:49 -040011
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 */
18struct trace_entry {
Steven Rostedt89ec0de2009-03-26 11:03:29 -040019 unsigned short type;
Steven Rostedt97f20252009-04-13 11:20:49 -040020 unsigned char flags;
21 unsigned char preempt_count;
22 int pid;
23 int tgid;
24};
25
Steven Rostedt89ec0de2009-03-26 11:03:29 -040026#define FTRACE_MAX_EVENT \
27 ((1 << (sizeof(((struct trace_entry *)0)->type) * 8)) - 1)
28
Steven Rostedt97f20252009-04-13 11:20:49 -040029/*
30 * Trace iterator - used by printout routines who present trace
31 * results to users and which routines might sleep, etc:
32 */
33struct 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
55typedef enum print_line_t (*trace_print_func)(struct trace_iterator *iter,
56 int flags);
57struct trace_event {
58 struct hlist_node node;
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
66extern int register_ftrace_event(struct trace_event *event);
67extern int unregister_ftrace_event(struct trace_event *event);
68
69/* Return values for print_line callback */
70enum 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
77
78struct ring_buffer_event *
Li Zefan7a4f4532009-04-22 16:53:34 +080079trace_current_buffer_lock_reserve(int type, unsigned long len,
Steven Rostedt97f20252009-04-13 11:20:49 -040080 unsigned long flags, int pc);
81void trace_current_buffer_unlock_commit(struct ring_buffer_event *event,
82 unsigned long flags, int pc);
83void trace_nowake_buffer_unlock_commit(struct ring_buffer_event *event,
84 unsigned long flags, int pc);
85void trace_current_buffer_discard_commit(struct ring_buffer_event *event);
86
87void tracing_record_cmdline(struct task_struct *tsk);
88
89struct ftrace_event_call {
Steven Rostedta59fd602009-04-10 13:52:20 -040090 struct list_head list;
Steven Rostedt97f20252009-04-13 11:20:49 -040091 char *name;
92 char *system;
93 struct dentry *dir;
Steven Rostedt6d723732009-04-10 14:53:50 -040094 struct trace_event *event;
Steven Rostedt97f20252009-04-13 11:20:49 -040095 int enabled;
96 int (*regfunc)(void);
97 void (*unregfunc)(void);
98 int id;
99 int (*raw_init)(void);
100 int (*show_format)(struct trace_seq *s);
101 int (*define_fields)(void);
102 struct list_head fields;
103 int n_preds;
104 struct filter_pred **preds;
Steven Rostedt6d723732009-04-10 14:53:50 -0400105 void *mod;
Steven Rostedt97f20252009-04-13 11:20:49 -0400106
107#ifdef CONFIG_EVENT_PROFILE
108 atomic_t profile_count;
109 int (*profile_enable)(struct ftrace_event_call *);
110 void (*profile_disable)(struct ftrace_event_call *);
111#endif
112};
113
114#define MAX_FILTER_PRED 8
115#define MAX_FILTER_STR_VAL 128
116
117extern int init_preds(struct ftrace_event_call *call);
118extern int filter_match_preds(struct ftrace_event_call *call, void *rec);
119extern int filter_current_check_discard(struct ftrace_event_call *call,
120 void *rec,
121 struct ring_buffer_event *event);
122
123extern int trace_define_field(struct ftrace_event_call *call, char *type,
124 char *name, int offset, int size);
125
126
127/*
128 * The double __builtin_constant_p is because gcc will give us an error
129 * if we try to allocate the static variable to fmt if it is not a
130 * constant. Even with the outer if statement optimizing out.
131 */
132#define event_trace_printk(ip, fmt, args...) \
133do { \
134 __trace_printk_check_format(fmt, ##args); \
135 tracing_record_cmdline(current); \
136 if (__builtin_constant_p(fmt)) { \
137 static const char *trace_printk_fmt \
138 __attribute__((section("__trace_printk_fmt"))) = \
139 __builtin_constant_p(fmt) ? fmt : NULL; \
140 \
141 __trace_bprintk(ip, trace_printk_fmt, ##args); \
142 } else \
143 __trace_printk(ip, fmt, ##args); \
144} while (0)
145
146#define __common_field(type, item) \
147 ret = trace_define_field(event_call, #type, "common_" #item, \
148 offsetof(typeof(field.ent), item), \
149 sizeof(field.ent.item)); \
150 if (ret) \
151 return ret;
152
153#endif /* _LINUX_FTRACE_EVENT_H */