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