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