Define ltt_transport_list as static
[lttng-ust.git] / include / lttng / ust-events.h
1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
3
4 /*
5 * lttng/ust-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 <urcu/list.h>
15 #include <uuid/uuid.h>
16 #include <stdint.h>
17 #include <lttng/ust-abi.h>
18 #include <lttng/ust-tracer.h>
19 #include <endian.h>
20 #include <float.h>
21 #include <lttng/tracepoint-internal.h>
22
23 struct ltt_channel;
24 struct ltt_session;
25 struct lttng_ust_lib_ring_buffer_ctx;
26
27 /*
28 * LTTng client type enumeration. Used by the consumer to map the
29 * callbacks from its own address space.
30 */
31 enum lttng_client_types {
32 LTTNG_CLIENT_METADATA = 0,
33 LTTNG_CLIENT_DISCARD = 1,
34 LTTNG_CLIENT_OVERWRITE = 2,
35 LTTNG_NR_CLIENT_TYPES,
36 };
37
38 /* Type description */
39
40 /* Update the astract_types name table in lttng-types.c along with this enum */
41 enum abstract_types {
42 atype_integer,
43 atype_enum,
44 atype_array,
45 atype_sequence,
46 atype_string,
47 atype_float,
48 NR_ABSTRACT_TYPES,
49 };
50
51 /* Update the string_encodings name table in lttng-types.c along with this enum */
52 enum lttng_string_encodings {
53 lttng_encode_none = 0,
54 lttng_encode_UTF8 = 1,
55 lttng_encode_ASCII = 2,
56 NR_STRING_ENCODINGS,
57 };
58
59 struct lttng_enum_entry {
60 unsigned long long start, end; /* start and end are inclusive */
61 const char *string;
62 };
63
64 #define __type_integer(_type, _byte_order, _base, _encoding) \
65 { \
66 .atype = atype_integer, \
67 .u.basic.integer = \
68 { \
69 .size = sizeof(_type) * CHAR_BIT, \
70 .alignment = lttng_alignof(_type) * CHAR_BIT, \
71 .signedness = lttng_is_signed_type(_type), \
72 .reverse_byte_order = _byte_order != __BYTE_ORDER, \
73 .base = _base, \
74 .encoding = lttng_encode_##_encoding, \
75 }, \
76 } \
77
78 struct lttng_integer_type {
79 unsigned int size; /* in bits */
80 unsigned short alignment; /* in bits */
81 unsigned int signedness:1;
82 unsigned int reverse_byte_order:1;
83 unsigned int base; /* 2, 8, 10, 16, for pretty print */
84 enum lttng_string_encodings encoding;
85 };
86
87 /*
88 * Only float and double are supported. long double is not supported at
89 * the moment.
90 */
91 #define _float_mant_dig(_type) \
92 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
93 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
94 : 0))
95
96 #define __type_float(_type) \
97 { \
98 .atype = atype_float, \
99 .u.basic._float = \
100 { \
101 .exp_dig = sizeof(_type) * CHAR_BIT \
102 - _float_mant_dig(_type), \
103 .mant_dig = _float_mant_dig(_type), \
104 .alignment = lttng_alignof(_type) * CHAR_BIT, \
105 .reverse_byte_order = __BYTE_ORDER != __FLOAT_WORD_ORDER, \
106 }, \
107 } \
108
109 struct lttng_float_type {
110 unsigned int exp_dig; /* exponent digits, in bits */
111 unsigned int mant_dig; /* mantissa digits, in bits */
112 unsigned short alignment; /* in bits */
113 unsigned int reverse_byte_order:1;
114 };
115
116 union _lttng_basic_type {
117 struct lttng_integer_type integer;
118 struct {
119 const char *name;
120 } enumeration;
121 struct {
122 enum lttng_string_encodings encoding;
123 } string;
124 struct lttng_float_type _float;
125 };
126
127 struct lttng_basic_type {
128 enum abstract_types atype;
129 union {
130 union _lttng_basic_type basic;
131 } u;
132 };
133
134 struct lttng_type {
135 enum abstract_types atype;
136 union {
137 union _lttng_basic_type basic;
138 struct {
139 struct lttng_basic_type elem_type;
140 unsigned int length; /* num. elems. */
141 } array;
142 struct {
143 struct lttng_basic_type length_type;
144 struct lttng_basic_type elem_type;
145 } sequence;
146 } u;
147 };
148
149 struct lttng_enum {
150 const char *name;
151 struct lttng_type container_type;
152 const struct lttng_enum_entry *entries;
153 unsigned int len;
154 };
155
156 /* Event field description */
157
158 struct lttng_event_field {
159 const char *name;
160 struct lttng_type type;
161 };
162
163 struct lttng_ctx_field {
164 struct lttng_event_field event_field;
165 size_t (*get_size)(size_t offset);
166 void (*record)(struct lttng_ctx_field *field,
167 struct lttng_ust_lib_ring_buffer_ctx *ctx,
168 struct ltt_channel *chan);
169 union {
170 } u;
171 void (*destroy)(struct lttng_ctx_field *field);
172 };
173
174 struct lttng_ctx {
175 struct lttng_ctx_field *fields;
176 unsigned int nr_fields;
177 unsigned int allocated_fields;
178 };
179
180 struct lttng_event_desc {
181 const char *name;
182 void *probe_callback;
183 const struct lttng_event_ctx *ctx; /* context */
184 const struct lttng_event_field *fields; /* event payload */
185 unsigned int nr_fields;
186 };
187
188 struct lttng_probe_desc {
189 const struct lttng_event_desc *event_desc;
190 unsigned int nr_events;
191 struct cds_list_head head; /* chain registered probes */
192 };
193
194 struct ust_pending_probe;
195
196 /*
197 * ltt_event structure is referred to by the tracing fast path. It must be
198 * kept small.
199 */
200 struct ltt_event {
201 unsigned int id;
202 struct ltt_channel *chan;
203 int enabled;
204 const struct lttng_event_desc *desc;
205 void *filter;
206 struct lttng_ctx *ctx;
207 enum lttng_ust_instrumentation instrumentation;
208 union {
209 } u;
210 struct cds_list_head list; /* Event list */
211 struct ust_pending_probe *pending_probe;
212 int metadata_dumped:1;
213 };
214
215 struct channel;
216 struct lttng_ust_shm_handle;
217
218 struct ltt_channel_ops {
219 struct ltt_channel *(*channel_create)(const char *name,
220 void *buf_addr,
221 size_t subbuf_size, size_t num_subbuf,
222 unsigned int switch_timer_interval,
223 unsigned int read_timer_interval,
224 int *shm_fd, int *wait_fd,
225 uint64_t *memory_map_size,
226 struct ltt_channel *chan_priv_init);
227 void (*channel_destroy)(struct ltt_channel *ltt_chan);
228 struct lttng_ust_lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
229 struct lttng_ust_shm_handle *handle,
230 int *shm_fd, int *wait_fd,
231 uint64_t *memory_map_size);
232 void (*buffer_read_close)(struct lttng_ust_lib_ring_buffer *buf,
233 struct lttng_ust_shm_handle *handle);
234 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
235 uint32_t event_id);
236 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
237 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx, const void *src,
238 size_t len);
239 /*
240 * packet_avail_size returns the available size in the current
241 * packet. Note that the size returned is only a hint, since it
242 * may change due to concurrent writes.
243 */
244 size_t (*packet_avail_size)(struct channel *chan,
245 struct lttng_ust_shm_handle *handle);
246 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
247 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
248 int (*is_finalized)(struct channel *chan);
249 int (*is_disabled)(struct channel *chan);
250 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
251 };
252
253 struct ltt_channel {
254 /*
255 * The pointers located in this private data are NOT safe to be
256 * dereferenced by the consumer. The only operations the
257 * consumer process is designed to be allowed to do is to read
258 * and perform subbuffer flush.
259 */
260 struct channel *chan; /* Channel buffers */
261 int enabled;
262 struct lttng_ctx *ctx;
263 /* Event ID management */
264 struct ltt_session *session;
265 int objd; /* Object associated to channel */
266 unsigned int free_event_id; /* Next event ID to allocate */
267 unsigned int used_event_id; /* Max allocated event IDs */
268 struct cds_list_head list; /* Channel list */
269 struct ltt_channel_ops *ops;
270 int header_type; /* 0: unset, 1: compact, 2: large */
271 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
272 int metadata_dumped:1;
273
274 /* Channel ID, available for consumer too */
275 unsigned int id;
276 /* Copy of session UUID for consumer (availability through shm) */
277 uuid_t uuid; /* Trace session unique ID */
278 };
279
280 struct ltt_session {
281 int active; /* Is trace session active ? */
282 int been_active; /* Has trace session been active ? */
283 int objd; /* Object associated to session */
284 struct ltt_channel *metadata; /* Metadata channel */
285 struct cds_list_head chan; /* Channel list head */
286 struct cds_list_head events; /* Event list head */
287 struct cds_list_head list; /* Session list */
288 unsigned int free_chan_id; /* Next chan ID to allocate */
289 uuid_t uuid; /* Trace session unique ID */
290 int metadata_dumped:1;
291 };
292
293 struct ltt_transport {
294 char *name;
295 struct cds_list_head node;
296 struct ltt_channel_ops ops;
297 };
298
299 struct ltt_tracepoint_list {
300 struct tracepoint_iter iter;
301 int got_first;
302 };
303
304 struct ltt_session *ltt_session_create(void);
305 int ltt_session_enable(struct ltt_session *session);
306 int ltt_session_disable(struct ltt_session *session);
307 void ltt_session_destroy(struct ltt_session *session);
308
309 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
310 const char *transport_name,
311 void *buf_addr,
312 size_t subbuf_size, size_t num_subbuf,
313 unsigned int switch_timer_interval,
314 unsigned int read_timer_interval,
315 int *shm_fd, int *wait_fd,
316 uint64_t *memory_map_size,
317 struct ltt_channel *chan_priv_init);
318 struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
319 int overwrite, void *buf_addr,
320 size_t subbuf_size, size_t num_subbuf,
321 unsigned int switch_timer_interval,
322 unsigned int read_timer_interval,
323 int *shm_fd, int *wait_fd,
324 uint64_t *memory_map_size);
325
326 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
327 struct lttng_ust_event *event_param,
328 void *filter);
329
330 int ltt_channel_enable(struct ltt_channel *channel);
331 int ltt_channel_disable(struct ltt_channel *channel);
332 int ltt_event_enable(struct ltt_event *event);
333 int ltt_event_disable(struct ltt_event *event);
334
335 void ltt_transport_register(struct ltt_transport *transport);
336 void ltt_transport_unregister(struct ltt_transport *transport);
337
338 void synchronize_trace(void);
339
340 int ltt_probe_register(struct lttng_probe_desc *desc);
341 void ltt_probe_unregister(struct lttng_probe_desc *desc);
342 int pending_probe_fix_events(const struct lttng_event_desc *desc);
343 const struct lttng_event_desc *ltt_event_get(const char *name);
344 void ltt_event_put(const struct lttng_event_desc *desc);
345 int ltt_probes_init(void);
346 void ltt_probes_exit(void);
347 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
348 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
349 void lttng_remove_context_field(struct lttng_ctx **ctx_p,
350 struct lttng_ctx_field *field);
351 void lttng_destroy_context(struct lttng_ctx *ctx);
352 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
353 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
354 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
355 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
356 void lttng_context_vtid_reset(void);
357 void lttng_context_vpid_reset(void);
358
359 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
360 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
361 const struct lttng_ust_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
362
363 struct ltt_transport *ltt_transport_find(const char *name);
364
365 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.037414 seconds and 5 git commands to generate.