Write context fields into trace
[lttng-modules.git] / ltt-events.h
1 #ifndef _LTT_EVENTS_H
2 #define _LTT_EVENTS_H
3
4 /*
5 * ltt-events.h
6 *
7 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 */
11
12 #include <linux/list.h>
13 #include <linux/uuid.h>
14 #include <linux/kprobes.h>
15 #include "ltt-debugfs-abi.h"
16
17 #undef is_signed_type
18 #define is_signed_type(type) (((type)(-1)) < 0)
19
20 struct ltt_channel;
21 struct ltt_session;
22 struct lib_ring_buffer_ctx;
23 struct perf_event;
24 struct perf_event_attr;
25
26 /* Type description */
27
28 /* Update the astract_types name table in lttng-types.c along with this enum */
29 enum abstract_types {
30 atype_integer,
31 atype_enum,
32 atype_array,
33 atype_sequence,
34 atype_string,
35 NR_ABSTRACT_TYPES,
36 };
37
38 /* Update the string_encodings name table in lttng-types.c along with this enum */
39 enum lttng_string_encodings {
40 lttng_encode_none = 0,
41 lttng_encode_UTF8 = 1,
42 lttng_encode_ASCII = 2,
43 NR_STRING_ENCODINGS,
44 };
45
46 struct lttng_enum_entry {
47 unsigned long long start, end; /* start and end are inclusive */
48 const char *string;
49 };
50
51 #define __type_integer(_type, _byte_order, _base, _encoding) \
52 { \
53 .atype = atype_integer, \
54 .u.basic.integer = \
55 { \
56 .size = sizeof(_type) * CHAR_BIT, \
57 .alignment = ltt_alignof(_type) * CHAR_BIT, \
58 .signedness = is_signed_type(_type), \
59 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
60 .base = _base, \
61 .encoding = lttng_encode_##_encoding, \
62 }, \
63 } \
64
65 struct lttng_integer_type {
66 unsigned int size; /* in bits */
67 unsigned short alignment; /* in bits */
68 unsigned int signedness:1;
69 unsigned int reverse_byte_order:1;
70 unsigned int base; /* 2, 8, 10, 16, for pretty print */
71 enum lttng_string_encodings encoding;
72 };
73
74 union _lttng_basic_type {
75 struct lttng_integer_type integer;
76 struct {
77 const char *name;
78 } enumeration;
79 struct {
80 enum lttng_string_encodings encoding;
81 } string;
82 };
83
84 struct lttng_basic_type {
85 enum abstract_types atype;
86 union {
87 union _lttng_basic_type basic;
88 } u;
89 };
90
91 struct lttng_type {
92 enum abstract_types atype;
93 union {
94 union _lttng_basic_type basic;
95 struct {
96 struct lttng_basic_type elem_type;
97 unsigned int length; /* num. elems. */
98 } array;
99 struct {
100 struct lttng_basic_type length_type;
101 struct lttng_basic_type elem_type;
102 } sequence;
103 } u;
104 };
105
106 struct lttng_enum {
107 const char *name;
108 struct lttng_type container_type;
109 const struct lttng_enum_entry *entries;
110 unsigned int len;
111 };
112
113 /* Event field description */
114
115 struct lttng_event_field {
116 const char *name;
117 struct lttng_type type;
118 };
119
120 struct lttng_ctx_field {
121 const char *name;
122 struct lttng_type type;
123 size_t (*get_size)(size_t offset);
124 void (*record)(struct lttng_ctx_field *field,
125 struct lib_ring_buffer_ctx *ctx,
126 struct ltt_channel *chan);
127 union {
128 struct {
129 struct perf_event **e; /* per-cpu array */
130 struct list_head head;
131 struct perf_event_attr *attr;
132 } perf_counter;
133 } u;
134 void (*destroy)(struct lttng_ctx_field *field);
135 };
136
137 struct lttng_ctx {
138 struct lttng_ctx_field *fields;
139 unsigned int nr_fields;
140 unsigned int allocated_fields;
141 };
142
143 struct lttng_event_desc {
144 const char *name;
145 void *probe_callback;
146 const struct lttng_event_ctx *ctx; /* context */
147 const struct lttng_event_field *fields; /* event payload */
148 unsigned int nr_fields;
149 struct module *owner;
150 };
151
152 struct lttng_probe_desc {
153 const struct lttng_event_desc *event_desc;
154 unsigned int nr_events;
155 struct list_head head; /* chain registered probes */
156 };
157
158 /*
159 * ltt_event structure is referred to by the tracing fast path. It must be
160 * kept small.
161 */
162 struct ltt_event {
163 unsigned int id;
164 struct ltt_channel *chan;
165 const struct lttng_event_desc *desc;
166 void *filter;
167 struct lttng_ctx *ctx;
168 enum lttng_kernel_instrumentation instrumentation;
169 union {
170 struct {
171 struct kprobe kp;
172 char *symbol_name;
173 } kprobe;
174 struct {
175 char *symbol_name;
176 } ftrace;
177 } u;
178 struct list_head list; /* Event list */
179 int metadata_dumped:1;
180 };
181
182 struct ltt_channel_ops {
183 struct channel *(*channel_create)(const char *name,
184 struct ltt_channel *ltt_chan,
185 void *buf_addr,
186 size_t subbuf_size, size_t num_subbuf,
187 unsigned int switch_timer_interval,
188 unsigned int read_timer_interval);
189 void (*channel_destroy)(struct channel *chan);
190 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
191 void (*buffer_read_close)(struct lib_ring_buffer *buf);
192 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
193 uint32_t event_id);
194 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
195 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
196 size_t len);
197 /*
198 * packet_avail_size returns the available size in the current
199 * packet. Note that the size returned is only a hint, since it
200 * may change due to concurrent writes.
201 */
202 size_t (*packet_avail_size)(struct channel *chan);
203 wait_queue_head_t *(*get_reader_wait_queue)(struct ltt_channel *chan);
204 };
205
206 struct ltt_channel {
207 unsigned int id;
208 struct channel *chan; /* Channel buffers */
209 struct lttng_ctx *ctx;
210 /* Event ID management */
211 struct ltt_session *session;
212 struct file *file; /* File associated to channel */
213 unsigned int free_event_id; /* Next event ID to allocate */
214 struct list_head list; /* Channel list */
215 wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
216 struct ltt_channel_ops *ops;
217 int header_type; /* 0: unset, 1: compact, 2: large */
218 int metadata_dumped:1;
219 };
220
221 struct ltt_session {
222 int active; /* Is trace session active ? */
223 struct lttng_ctx *ctx;
224 struct file *file; /* File associated to session */
225 struct ltt_channel *metadata; /* Metadata channel */
226 struct list_head chan; /* Channel list head */
227 struct list_head events; /* Event list head */
228 struct list_head list; /* Session list */
229 unsigned int free_chan_id; /* Next chan ID to allocate */
230 uuid_le uuid; /* Trace session unique ID */
231 int metadata_dumped:1;
232 };
233
234 struct ltt_transport {
235 char *name;
236 struct module *owner;
237 struct list_head node;
238 struct ltt_channel_ops ops;
239 };
240
241 struct ltt_session *ltt_session_create(void);
242 int ltt_session_start(struct ltt_session *session);
243 int ltt_session_stop(struct ltt_session *session);
244 void ltt_session_destroy(struct ltt_session *session);
245
246 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
247 const char *transport_name,
248 void *buf_addr,
249 size_t subbuf_size, size_t num_subbuf,
250 unsigned int switch_timer_interval,
251 unsigned int read_timer_interval);
252 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
253 int overwrite, void *buf_addr,
254 size_t subbuf_size, size_t num_subbuf,
255 unsigned int switch_timer_interval,
256 unsigned int read_timer_interval);
257
258 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
259 struct lttng_kernel_event *event_param,
260 void *filter);
261
262 void ltt_transport_register(struct ltt_transport *transport);
263 void ltt_transport_unregister(struct ltt_transport *transport);
264
265 int ltt_debugfs_abi_init(void);
266 void ltt_debugfs_abi_exit(void);
267
268 int ltt_probe_register(struct lttng_probe_desc *desc);
269 void ltt_probe_unregister(struct lttng_probe_desc *desc);
270 const struct lttng_event_desc *ltt_event_get(const char *name);
271 void ltt_event_put(const struct lttng_event_desc *desc);
272 int ltt_probes_init(void);
273 void ltt_probes_exit(void);
274 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
275 void lttng_destroy_context(struct lttng_ctx *ctx);
276
277 #ifdef CONFIG_KPROBES
278 int lttng_kprobes_register(const char *name,
279 const char *symbol_name,
280 uint64_t offset,
281 uint64_t addr,
282 struct ltt_event *event);
283 void lttng_kprobes_unregister(struct ltt_event *event);
284 void lttng_kprobes_destroy_private(struct ltt_event *event);
285 #else
286 static inline
287 int lttng_kprobes_register(const char *name,
288 const char *symbol_name,
289 uint64_t offset,
290 uint64_t addr,
291 struct ltt_event *event)
292 {
293 return -ENOSYS;
294 }
295
296 static inline
297 void lttng_kprobes_unregister(struct ltt_event *event)
298 {
299 }
300
301 static inline
302 void lttng_kprobes_destroy_private(struct ltt_event *event)
303 {
304 }
305 #endif
306
307 #ifdef CONFIG_DYNAMIC_FTRACE
308 int lttng_ftrace_register(const char *name,
309 const char *symbol_name,
310 struct ltt_event *event);
311 void lttng_ftrace_unregister(struct ltt_event *event);
312 void lttng_ftrace_destroy_private(struct ltt_event *event);
313 #else
314 static inline
315 int lttng_ftrace_register(const char *name,
316 const char *symbol_name,
317 struct ltt_event *event)
318 {
319 return -ENOSYS;
320 }
321
322 static inline
323 void lttng_ftrace_unregister(struct ltt_event *event)
324 {
325 }
326
327 static inline
328 void lttng_ftrace_destroy_private(struct ltt_event *event)
329 {
330 }
331 #endif
332
333 extern const struct file_operations lttng_tracepoint_list_fops;
334
335 #endif /* _LTT_EVENTS_H */
This page took 0.045878 seconds and 5 git commands to generate.