Version 2.0.8
[lttng-modules.git] / lttng-events.h
CommitLineData
a90917c3
MD
1#ifndef _LTTNG_EVENTS_H
2#define _LTTNG_EVENTS_H
11b5a3c2 3
4e3c1b9b 4/*
a90917c3 5 * lttng-events.h
4e3c1b9b 6 *
4e3c1b9b 7 * Holds LTTng per-session event registry.
17baffe2 8 *
886d51a3
MD
9 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; only
14 * version 2.1 of the License.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4e3c1b9b
MD
24 */
25
26#include <linux/list.h>
d6d808f3 27#include <linux/kprobes.h>
a864fb02 28#include "wrapper/uuid.h"
e8951e63 29#include "lttng-abi.h"
4e3c1b9b 30
9e7e4892
MD
31#undef is_signed_type
32#define is_signed_type(type) (((type)(-1)) < 0)
33
a90917c3
MD
34struct lttng_channel;
35struct lttng_session;
1c25284c 36struct lib_ring_buffer_ctx;
ba1f5986 37struct perf_event;
833ad6a0 38struct perf_event_attr;
4e3c1b9b 39
c0edae1d
MD
40/* Type description */
41
42/* Update the astract_types name table in lttng-types.c along with this enum */
43enum abstract_types {
44 atype_integer,
45 atype_enum,
46 atype_array,
47 atype_sequence,
48 atype_string,
49 NR_ABSTRACT_TYPES,
50};
51
52/* Update the string_encodings name table in lttng-types.c along with this enum */
53enum lttng_string_encodings {
e0a7a7c4
MD
54 lttng_encode_none = 0,
55 lttng_encode_UTF8 = 1,
56 lttng_encode_ASCII = 2,
c0edae1d
MD
57 NR_STRING_ENCODINGS,
58};
59
60struct lttng_enum_entry {
61 unsigned long long start, end; /* start and end are inclusive */
62 const char *string;
63};
64
64c796d8 65#define __type_integer(_type, _byte_order, _base, _encoding) \
c099397a
MD
66 { \
67 .atype = atype_integer, \
68 .u.basic.integer = \
69 { \
30bdb6e4 70 .size = sizeof(_type) * CHAR_BIT, \
a90917c3 71 .alignment = lttng_alignof(_type) * CHAR_BIT, \
c099397a
MD
72 .signedness = is_signed_type(_type), \
73 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
e0a7a7c4 74 .base = _base, \
64c796d8 75 .encoding = lttng_encode_##_encoding, \
c099397a
MD
76 }, \
77 } \
78
79struct lttng_integer_type {
80 unsigned int size; /* in bits */
81 unsigned short alignment; /* in bits */
9cccf98a
MD
82 unsigned int signedness:1,
83 reverse_byte_order:1;
e0a7a7c4
MD
84 unsigned int base; /* 2, 8, 10, 16, for pretty print */
85 enum lttng_string_encodings encoding;
c099397a
MD
86};
87
88union _lttng_basic_type {
89 struct lttng_integer_type integer;
90 struct {
91 const char *name;
92 } enumeration;
93 struct {
94 enum lttng_string_encodings encoding;
95 } string;
96};
97
98struct lttng_basic_type {
99 enum abstract_types atype;
100 union {
101 union _lttng_basic_type basic;
102 } u;
c0edae1d
MD
103};
104
105struct lttng_type {
106 enum abstract_types atype;
c0edae1d 107 union {
c099397a 108 union _lttng_basic_type basic;
c0edae1d 109 struct {
c099397a 110 struct lttng_basic_type elem_type;
c0edae1d
MD
111 unsigned int length; /* num. elems. */
112 } array;
113 struct {
c099397a
MD
114 struct lttng_basic_type length_type;
115 struct lttng_basic_type elem_type;
c0edae1d 116 } sequence;
c0edae1d 117 } u;
c099397a
MD
118};
119
120struct lttng_enum {
121 const char *name;
122 struct lttng_type container_type;
123 const struct lttng_enum_entry *entries;
124 unsigned int len;
125};
c0edae1d
MD
126
127/* Event field description */
128
129struct lttng_event_field {
130 const char *name;
f17701fb 131 struct lttng_type type;
c0edae1d
MD
132};
133
2001023e
MD
134/*
135 * We need to keep this perf counter field separately from struct
136 * lttng_ctx_field because cpu hotplug needs fixed-location addresses.
137 */
138struct lttng_perf_counter_field {
139 struct notifier_block nb;
140 int hp_enable;
141 struct perf_event_attr *attr;
142 struct perf_event **e; /* per-cpu array */
143};
144
ba1f5986 145struct lttng_ctx_field {
8070f5c0 146 struct lttng_event_field event_field;
f1676205
MD
147 size_t (*get_size)(size_t offset);
148 void (*record)(struct lttng_ctx_field *field,
149 struct lib_ring_buffer_ctx *ctx,
a90917c3 150 struct lttng_channel *chan);
ba1f5986 151 union {
2001023e 152 struct lttng_perf_counter_field *perf_counter;
ba1f5986 153 } u;
2dccf128 154 void (*destroy)(struct lttng_ctx_field *field);
ba1f5986
MD
155};
156
157struct lttng_ctx {
833ad6a0 158 struct lttng_ctx_field *fields;
0d1a681e 159 unsigned int nr_fields;
ba1f5986 160 unsigned int allocated_fields;
0d1a681e
MD
161};
162
163struct lttng_event_desc {
c0edae1d
MD
164 const char *name;
165 void *probe_callback;
0d1a681e
MD
166 const struct lttng_event_ctx *ctx; /* context */
167 const struct lttng_event_field *fields; /* event payload */
c0edae1d 168 unsigned int nr_fields;
dc7f600a 169 struct module *owner;
c0edae1d
MD
170};
171
85a9ca7f 172struct lttng_probe_desc {
f7bdf4db 173 const struct lttng_event_desc **event_desc;
85a9ca7f
MD
174 unsigned int nr_events;
175 struct list_head head; /* chain registered probes */
176};
177
7371f44c
MD
178struct lttng_krp; /* Kretprobe handling */
179
85a9ca7f 180/*
a90917c3 181 * lttng_event structure is referred to by the tracing fast path. It must be
85a9ca7f
MD
182 * kept small.
183 */
a90917c3 184struct lttng_event {
85a9ca7f 185 unsigned int id;
a90917c3 186 struct lttng_channel *chan;
e64957da 187 int enabled;
d3dbe23c 188 const struct lttng_event_desc *desc;
85a9ca7f 189 void *filter;
f1676205 190 struct lttng_ctx *ctx;
38d024ae 191 enum lttng_kernel_instrumentation instrumentation;
d6d808f3
MD
192 union {
193 struct {
194 struct kprobe kp;
195 char *symbol_name;
196 } kprobe;
7371f44c
MD
197 struct {
198 struct lttng_krp *lttng_krp;
199 char *symbol_name;
200 } kretprobe;
e0a7a7c4
MD
201 struct {
202 char *symbol_name;
203 } ftrace;
d6d808f3 204 } u;
85a9ca7f 205 struct list_head list; /* Event list */
9cccf98a 206 unsigned int metadata_dumped:1;
85a9ca7f
MD
207};
208
a90917c3 209struct lttng_channel_ops {
85a9ca7f 210 struct channel *(*channel_create)(const char *name,
a90917c3 211 struct lttng_channel *lttng_chan,
85a9ca7f
MD
212 void *buf_addr,
213 size_t subbuf_size, size_t num_subbuf,
214 unsigned int switch_timer_interval,
215 unsigned int read_timer_interval);
216 void (*channel_destroy)(struct channel *chan);
217 struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
f71ecafa 218 int (*buffer_has_read_closed_stream)(struct channel *chan);
85a9ca7f 219 void (*buffer_read_close)(struct lib_ring_buffer *buf);
4e1f08f4 220 int (*event_reserve)(struct lib_ring_buffer_ctx *ctx,
64c796d8 221 uint32_t event_id);
85a9ca7f
MD
222 void (*event_commit)(struct lib_ring_buffer_ctx *ctx);
223 void (*event_write)(struct lib_ring_buffer_ctx *ctx, const void *src,
224 size_t len);
4ea00e4f
JD
225 void (*event_write_from_user)(struct lib_ring_buffer_ctx *ctx,
226 const void *src, size_t len);
58aa5d24
MD
227 void (*event_memset)(struct lib_ring_buffer_ctx *ctx,
228 int c, size_t len);
1ec3f75a
MD
229 /*
230 * packet_avail_size returns the available size in the current
231 * packet. Note that the size returned is only a hint, since it
232 * may change due to concurrent writes.
233 */
234 size_t (*packet_avail_size)(struct channel *chan);
71c1d843 235 wait_queue_head_t *(*get_writer_buf_wait_queue)(struct channel *chan, int cpu);
24cedcfe
MD
236 wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
237 int (*is_finalized)(struct channel *chan);
254ec7bc 238 int (*is_disabled)(struct channel *chan);
85a9ca7f
MD
239};
240
a90917c3 241struct lttng_transport {
a33c9927
MD
242 char *name;
243 struct module *owner;
244 struct list_head node;
a90917c3 245 struct lttng_channel_ops ops;
a33c9927
MD
246};
247
a90917c3 248struct lttng_channel {
c099397a 249 unsigned int id;
85a9ca7f 250 struct channel *chan; /* Channel buffers */
e64957da 251 int enabled;
f1676205 252 struct lttng_ctx *ctx;
85a9ca7f 253 /* Event ID management */
a90917c3 254 struct lttng_session *session;
85a9ca7f
MD
255 struct file *file; /* File associated to channel */
256 unsigned int free_event_id; /* Next event ID to allocate */
257 struct list_head list; /* Channel list */
a90917c3
MD
258 struct lttng_channel_ops *ops;
259 struct lttng_transport *transport;
260 struct lttng_event **sc_table; /* for syscall tracing */
261 struct lttng_event **compat_sc_table;
262 struct lttng_event *sc_unknown; /* for unknown syscalls */
263 struct lttng_event *sc_compat_unknown;
264 struct lttng_event *sc_exit; /* for syscall exit */
9115fbdc 265 int header_type; /* 0: unset, 1: compact, 2: large */
9cccf98a 266 unsigned int metadata_dumped:1;
85a9ca7f
MD
267};
268
a90917c3 269struct lttng_session {
85a9ca7f 270 int active; /* Is trace session active ? */
8070f5c0 271 int been_active; /* Has trace session been active ? */
85a9ca7f 272 struct file *file; /* File associated to session */
a90917c3 273 struct lttng_channel *metadata; /* Metadata channel */
85a9ca7f
MD
274 struct list_head chan; /* Channel list head */
275 struct list_head events; /* Event list head */
276 struct list_head list; /* Session list */
c099397a 277 unsigned int free_chan_id; /* Next chan ID to allocate */
d793d5e1 278 uuid_le uuid; /* Trace session unique ID */
9cccf98a 279 unsigned int metadata_dumped:1;
85a9ca7f
MD
280};
281
a90917c3
MD
282struct lttng_session *lttng_session_create(void);
283int lttng_session_enable(struct lttng_session *session);
284int lttng_session_disable(struct lttng_session *session);
285void lttng_session_destroy(struct lttng_session *session);
4e3c1b9b 286
a90917c3 287struct lttng_channel *lttng_channel_create(struct lttng_session *session,
5dbbdb43
MD
288 const char *transport_name,
289 void *buf_addr,
290 size_t subbuf_size, size_t num_subbuf,
291 unsigned int switch_timer_interval,
292 unsigned int read_timer_interval);
a90917c3 293struct lttng_channel *lttng_global_channel_create(struct lttng_session *session,
4e3c1b9b
MD
294 int overwrite, void *buf_addr,
295 size_t subbuf_size, size_t num_subbuf,
296 unsigned int switch_timer_interval,
297 unsigned int read_timer_interval);
4e3c1b9b 298
a90917c3 299struct lttng_event *lttng_event_create(struct lttng_channel *chan,
d6d808f3 300 struct lttng_kernel_event *event_param,
259b6cb3
MD
301 void *filter,
302 const struct lttng_event_desc *internal_desc);
c0e31d2e 303
a90917c3
MD
304int lttng_channel_enable(struct lttng_channel *channel);
305int lttng_channel_disable(struct lttng_channel *channel);
306int lttng_event_enable(struct lttng_event *event);
307int lttng_event_disable(struct lttng_event *event);
e64957da 308
a90917c3
MD
309void lttng_transport_register(struct lttng_transport *transport);
310void lttng_transport_unregister(struct lttng_transport *transport);
11b5a3c2 311
360f38ea 312void synchronize_trace(void);
80996790
MD
313int lttng_abi_init(void);
314void lttng_abi_exit(void);
1c25284c 315
a90917c3
MD
316int lttng_probe_register(struct lttng_probe_desc *desc);
317void lttng_probe_unregister(struct lttng_probe_desc *desc);
318const struct lttng_event_desc *lttng_event_get(const char *name);
319void lttng_event_put(const struct lttng_event_desc *desc);
320int lttng_probes_init(void);
321void lttng_probes_exit(void);
1ec65de1 322
63728b02 323#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
a90917c3
MD
324int lttng_syscalls_register(struct lttng_channel *chan, void *filter);
325int lttng_syscalls_unregister(struct lttng_channel *chan);
1ec65de1 326#else
a90917c3 327static inline int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
1ec65de1
MD
328{
329 return -ENOSYS;
330}
331
a90917c3 332static inline int lttng_syscalls_unregister(struct lttng_channel *chan)
1ec65de1
MD
333{
334 return 0;
335}
336#endif
337
2dccf128 338struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
44252f0f 339int lttng_find_context(struct lttng_ctx *ctx, const char *name);
8289661d
MD
340void lttng_remove_context_field(struct lttng_ctx **ctx,
341 struct lttng_ctx_field *field);
2dccf128 342void lttng_destroy_context(struct lttng_ctx *ctx);
8070f5c0 343int lttng_add_pid_to_ctx(struct lttng_ctx **ctx);
a2563e83 344int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
a8ad3613 345int lttng_add_prio_to_ctx(struct lttng_ctx **ctx);
53f1f0ca 346int lttng_add_nice_to_ctx(struct lttng_ctx **ctx);
b64bc438
MD
347int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
348int lttng_add_tid_to_ctx(struct lttng_ctx **ctx);
349int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
350int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx);
351int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx);
41c3c24e 352#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33))
c24a0d71
MD
353int lttng_add_perf_counter_to_ctx(uint32_t type,
354 uint64_t config,
355 const char *name,
356 struct lttng_ctx **ctx);
1d443b34
MD
357#else
358static inline
359int lttng_add_perf_counter_to_ctx(uint32_t type,
360 uint64_t config,
361 const char *name,
362 struct lttng_ctx **ctx)
363{
364 return -ENOSYS;
365}
366#endif
02119ee5 367
c337ddc2
MD
368extern int lttng_statedump_start(struct lttng_session *session);
369
acd614cc 370#ifdef CONFIG_KPROBES
f17701fb
MD
371int lttng_kprobes_register(const char *name,
372 const char *symbol_name,
373 uint64_t offset,
374 uint64_t addr,
a90917c3
MD
375 struct lttng_event *event);
376void lttng_kprobes_unregister(struct lttng_event *event);
377void lttng_kprobes_destroy_private(struct lttng_event *event);
acd614cc
MD
378#else
379static inline
380int lttng_kprobes_register(const char *name,
381 const char *symbol_name,
382 uint64_t offset,
383 uint64_t addr,
a90917c3 384 struct lttng_event *event)
acd614cc
MD
385{
386 return -ENOSYS;
387}
388
25f53c39 389static inline
a90917c3 390void lttng_kprobes_unregister(struct lttng_event *event)
acd614cc
MD
391{
392}
edeb3137
MD
393
394static inline
a90917c3 395void lttng_kprobes_destroy_private(struct lttng_event *event)
edeb3137
MD
396{
397}
acd614cc 398#endif
d6d808f3 399
7371f44c
MD
400#ifdef CONFIG_KRETPROBES
401int lttng_kretprobes_register(const char *name,
402 const char *symbol_name,
403 uint64_t offset,
404 uint64_t addr,
a90917c3
MD
405 struct lttng_event *event_entry,
406 struct lttng_event *event_exit);
407void lttng_kretprobes_unregister(struct lttng_event *event);
408void lttng_kretprobes_destroy_private(struct lttng_event *event);
7371f44c
MD
409#else
410static inline
411int lttng_kretprobes_register(const char *name,
412 const char *symbol_name,
413 uint64_t offset,
414 uint64_t addr,
a90917c3
MD
415 struct lttng_event *event_entry,
416 struct lttng_event *event_exit)
7371f44c
MD
417{
418 return -ENOSYS;
419}
420
421static inline
a90917c3 422void lttng_kretprobes_unregister(struct lttng_event *event)
7371f44c
MD
423{
424}
425
426static inline
a90917c3 427void lttng_kretprobes_destroy_private(struct lttng_event *event)
7371f44c
MD
428{
429}
430#endif
431
e0a7a7c4
MD
432#ifdef CONFIG_DYNAMIC_FTRACE
433int lttng_ftrace_register(const char *name,
434 const char *symbol_name,
a90917c3
MD
435 struct lttng_event *event);
436void lttng_ftrace_unregister(struct lttng_event *event);
437void lttng_ftrace_destroy_private(struct lttng_event *event);
e0a7a7c4
MD
438#else
439static inline
440int lttng_ftrace_register(const char *name,
441 const char *symbol_name,
a90917c3 442 struct lttng_event *event)
e0a7a7c4 443{
acd614cc 444 return -ENOSYS;
e0a7a7c4
MD
445}
446
447static inline
a90917c3 448void lttng_ftrace_unregister(struct lttng_event *event)
e0a7a7c4
MD
449{
450}
edeb3137
MD
451
452static inline
a90917c3 453void lttng_ftrace_destroy_private(struct lttng_event *event)
edeb3137
MD
454{
455}
e0a7a7c4 456#endif
271b6681 457
3db41b2c 458int lttng_calibrate(struct lttng_kernel_calibrate *calibrate);
57105fc2 459
271b6681
MD
460extern const struct file_operations lttng_tracepoint_list_fops;
461
ef200626
MD
462#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35))
463#define TRACEPOINT_HAS_DATA_ARG
464#endif
465
a90917c3 466#endif /* _LTTNG_EVENTS_H */
This page took 0.050602 seconds and 4 git commands to generate.