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