1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
7 * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * Holds LTTng per-session event registry.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
22 #include <urcu/list.h>
23 #include <urcu/hlist.h>
25 #include <lttng/ust-abi.h>
26 #include <lttng/ust-tracer.h>
27 #include <lttng/ust-endian.h>
30 #define LTTNG_UST_UUID_LEN 16
34 struct lttng_ust_lib_ring_buffer_ctx
;
37 * Data structures used by tracepoint event declarations, and by the
38 * tracer. Those structures have padding for future extension.
42 * LTTng client type enumeration. Used by the consumer to map the
43 * callbacks from its own address space.
45 enum lttng_client_types
{
46 LTTNG_CLIENT_METADATA
= 0,
47 LTTNG_CLIENT_DISCARD
= 1,
48 LTTNG_CLIENT_OVERWRITE
= 2,
49 LTTNG_NR_CLIENT_TYPES
,
52 /* Type description */
54 /* Update the astract_types name table in lttng-types.c along with this enum */
55 enum lttng_abstract_types
{
65 /* Update the string_encodings name table in lttng-types.c along with this enum */
66 enum lttng_string_encodings
{
67 lttng_encode_none
= 0,
68 lttng_encode_UTF8
= 1,
69 lttng_encode_ASCII
= 2,
73 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
74 struct lttng_enum_entry
{
75 unsigned long long start
, end
; /* start and end are inclusive */
77 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
80 #define __type_integer(_type, _byte_order, _base, _encoding) \
82 .atype = atype_integer, \
85 .size = sizeof(_type) * CHAR_BIT, \
86 .alignment = lttng_alignof(_type) * CHAR_BIT, \
87 .signedness = lttng_is_signed_type(_type), \
88 .reverse_byte_order = _byte_order != BYTE_ORDER, \
90 .encoding = lttng_encode_##_encoding, \
94 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
95 struct lttng_integer_type
{
96 unsigned int size
; /* in bits */
97 unsigned short alignment
; /* in bits */
98 unsigned int signedness
:1;
99 unsigned int reverse_byte_order
:1;
100 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
101 enum lttng_string_encodings encoding
;
102 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
106 * Only float and double are supported. long double is not supported at
109 #define _float_mant_dig(_type) \
110 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
111 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
114 #define __type_float(_type) \
116 .atype = atype_float, \
119 .exp_dig = sizeof(_type) * CHAR_BIT \
120 - _float_mant_dig(_type), \
121 .mant_dig = _float_mant_dig(_type), \
122 .alignment = lttng_alignof(_type) * CHAR_BIT, \
123 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
127 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
128 struct lttng_float_type
{
129 unsigned int exp_dig
; /* exponent digits, in bits */
130 unsigned int mant_dig
; /* mantissa digits, in bits */
131 unsigned short alignment
; /* in bits */
132 unsigned int reverse_byte_order
:1;
133 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
136 #define LTTNG_UST_BASIC_TYPE_PADDING 128
137 union _lttng_basic_type
{
138 struct lttng_integer_type integer
;
143 enum lttng_string_encodings encoding
;
145 struct lttng_float_type _float
;
146 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
149 struct lttng_basic_type
{
150 enum lttng_abstract_types atype
;
152 union _lttng_basic_type basic
;
156 #define LTTNG_UST_TYPE_PADDING 128
158 enum lttng_abstract_types atype
;
160 union _lttng_basic_type basic
;
162 struct lttng_basic_type elem_type
;
163 unsigned int length
; /* num. elems. */
166 struct lttng_basic_type length_type
;
167 struct lttng_basic_type elem_type
;
169 char padding
[LTTNG_UST_TYPE_PADDING
];
173 #define LTTNG_UST_ENUM_TYPE_PADDING 24
176 struct lttng_type container_type
;
177 const struct lttng_enum_entry
*entries
;
179 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
183 * Event field description
185 * IMPORTANT: this structure is part of the ABI between the probe and
186 * UST. Fields need to be only added at the end, never reordered, never
190 #define LTTNG_UST_EVENT_FIELD_PADDING 28
191 struct lttng_event_field
{
193 struct lttng_type type
;
194 unsigned int nowrite
; /* do not write into trace */
195 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
198 #define LTTNG_UST_CTX_FIELD_PADDING 40
199 struct lttng_ctx_field
{
200 struct lttng_event_field event_field
;
201 size_t (*get_size
)(size_t offset
);
202 void (*record
)(struct lttng_ctx_field
*field
,
203 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
204 struct lttng_channel
*chan
);
206 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
208 void (*destroy
)(struct lttng_ctx_field
*field
);
211 #define LTTNG_UST_CTX_PADDING 24
213 struct lttng_ctx_field
*fields
;
214 unsigned int nr_fields
;
215 unsigned int allocated_fields
;
216 char padding
[LTTNG_UST_CTX_PADDING
];
219 #define LTTNG_UST_EVENT_DESC_PADDING 40
220 struct lttng_event_desc
{
222 void (*probe_callback
)(void);
223 const struct lttng_event_ctx
*ctx
; /* context */
224 const struct lttng_event_field
*fields
; /* event payload */
225 unsigned int nr_fields
;
226 const int **loglevel
;
227 const char *signature
; /* Argument types/names received */
230 const char **model_emf_uri
;
232 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
236 #define LTTNG_UST_PROBE_DESC_PADDING 40
237 struct lttng_probe_desc
{
238 const char *provider
;
239 const struct lttng_event_desc
**event_desc
;
240 unsigned int nr_events
;
241 struct cds_list_head head
; /* chain registered probes */
242 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
245 /* Data structures used by the tracer. */
247 enum lttng_enabler_type
{
248 LTTNG_ENABLER_WILDCARD
,
253 * Enabler field, within whatever object is enabling an event. Target of
254 * backward reference.
256 struct lttng_enabler
{
257 enum lttng_enabler_type type
;
259 /* head list of struct lttng_ust_filter_bytecode_node */
260 struct cds_list_head filter_bytecode_head
;
261 struct cds_list_head node
; /* per-session list of enablers */
263 struct lttng_ust_event event_param
;
264 struct lttng_channel
*chan
;
265 struct lttng_ctx
*ctx
;
266 unsigned int enabled
:1;
269 struct tp_list_entry
{
270 struct lttng_ust_tracepoint_iter tp
;
271 struct cds_list_head head
;
274 struct lttng_ust_tracepoint_list
{
275 struct tp_list_entry
*iter
;
276 struct cds_list_head head
;
279 struct tp_field_list_entry
{
280 struct lttng_ust_field_iter field
;
281 struct cds_list_head head
;
284 struct lttng_ust_field_list
{
285 struct tp_field_list_entry
*iter
;
286 struct cds_list_head head
;
289 struct ust_pending_probe
;
292 struct lttng_ust_filter_bytecode_node
{
293 struct cds_list_head node
;
294 struct lttng_enabler
*enabler
;
296 * struct lttng_ust_filter_bytecode has var. sized array, must
299 struct lttng_ust_filter_bytecode bc
;
303 * Filter return value masks.
305 enum lttng_filter_ret
{
306 LTTNG_FILTER_DISCARD
= 0,
307 LTTNG_FILTER_RECORD_FLAG
= (1ULL << 0),
308 /* Other bits are kept for future use. */
311 struct lttng_bytecode_runtime
{
312 /* Associated bytecode */
313 struct lttng_ust_filter_bytecode_node
*bc
;
314 uint64_t (*filter
)(void *filter_data
, const char *filter_stack_data
);
316 struct cds_list_head node
; /* list of bytecode runtime in event */
320 * Objects in a linked-list of enablers, owned by an event.
322 struct lttng_enabler_ref
{
323 struct cds_list_head node
; /* enabler ref list */
324 struct lttng_enabler
*ref
; /* backward ref */
328 * lttng_event structure is referred to by the tracing fast path. It
329 * must be kept small.
331 * IMPORTANT: this structure is part of the ABI between the probe and
332 * UST. Fields need to be only added at the end, never reordered, never
336 /* LTTng-UST 2.0 starts here */
338 struct lttng_channel
*chan
;
340 const struct lttng_event_desc
*desc
;
342 struct lttng_ctx
*ctx
;
343 enum lttng_ust_instrumentation instrumentation
;
346 struct cds_list_head node
; /* Event list in session */
347 struct cds_list_head _deprecated2
;
349 unsigned int metadata_dumped
:1;
351 /* LTTng-UST 2.1 starts here */
352 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
353 struct cds_list_head bytecode_runtime_head
;
354 int has_enablers_without_bytecode
;
355 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
356 struct cds_list_head enablers_ref_head
;
360 struct lttng_ust_shm_handle
;
363 * IMPORTANT: this structure is part of the ABI between the probe and
364 * UST. Fields need to be only added at the end, never reordered, never
367 struct lttng_channel_ops
{
368 struct lttng_channel
*(*channel_create
)(const char *name
,
370 size_t subbuf_size
, size_t num_subbuf
,
371 unsigned int switch_timer_interval
,
372 unsigned int read_timer_interval
,
373 int **shm_fd
, int **wait_fd
,
374 uint64_t **memory_map_size
,
375 struct lttng_channel
*chan_priv_init
);
376 void (*channel_destroy
)(struct lttng_channel
*lttng_chan
);
377 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
378 struct lttng_ust_shm_handle
*handle
,
379 int **shm_fd
, int **wait_fd
,
380 uint64_t **memory_map_size
);
381 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
382 struct lttng_ust_shm_handle
*handle
);
383 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
385 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
386 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
389 * packet_avail_size returns the available size in the current
390 * packet. Note that the size returned is only a hint, since it
391 * may change due to concurrent writes.
393 size_t (*packet_avail_size
)(struct channel
*chan
,
394 struct lttng_ust_shm_handle
*handle
);
395 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
396 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
397 int (*is_finalized
)(struct channel
*chan
);
398 int (*is_disabled
)(struct channel
*chan
);
399 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
403 * IMPORTANT: this structure is part of the ABI between the probe and
404 * UST. Fields need to be only added at the end, never reordered, never
407 struct lttng_channel
{
409 * The pointers located in this private data are NOT safe to be
410 * dereferenced by the consumer. The only operations the
411 * consumer process is designed to be allowed to do is to read
412 * and perform subbuffer flush.
414 struct channel
*chan
; /* Channel buffers */
416 struct lttng_ctx
*ctx
;
417 /* Event ID management */
418 struct lttng_session
*session
;
419 int objd
; /* Object associated to channel */
420 unsigned int free_event_id
; /* Next event ID to allocate */
421 unsigned int used_event_id
; /* Max allocated event IDs */
422 struct cds_list_head node
; /* Channel list in session */
423 struct lttng_channel_ops
*ops
;
424 int header_type
; /* 0: unset, 1: compact, 2: large */
425 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
426 unsigned int metadata_dumped
:1;
428 /* Channel ID, available for consumer too */
430 /* Copy of session UUID for consumer (availability through shm) */
431 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
434 #define LTTNG_UST_EVENT_HT_BITS 6
435 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
437 struct lttng_ust_event_ht
{
438 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
442 * IMPORTANT: this structure is part of the ABI between the probe and
443 * UST. Fields need to be only added at the end, never reordered, never
446 struct lttng_session
{
447 int active
; /* Is trace session active ? */
448 int been_active
; /* Been active ? */
449 int objd
; /* Object associated */
450 struct lttng_channel
*metadata
; /* Metadata channel */
451 struct cds_list_head chan_head
; /* Channel list head */
452 struct cds_list_head events_head
; /* list of events */
453 struct cds_list_head _deprecated1
;
454 struct cds_list_head node
; /* Session list */
455 unsigned int free_chan_id
; /* Next chan ID to allocate */
456 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
457 unsigned int metadata_dumped
:1;
460 /* List of enablers */
461 struct cds_list_head enablers_head
;
464 struct lttng_transport
{
466 struct cds_list_head node
;
467 struct lttng_channel_ops ops
;
470 struct lttng_session
*lttng_session_create(void);
471 int lttng_session_enable(struct lttng_session
*session
);
472 int lttng_session_disable(struct lttng_session
*session
);
473 void lttng_session_destroy(struct lttng_session
*session
);
475 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
476 const char *transport_name
,
478 size_t subbuf_size
, size_t num_subbuf
,
479 unsigned int switch_timer_interval
,
480 unsigned int read_timer_interval
,
481 int **shm_fd
, int **wait_fd
,
482 uint64_t **memory_map_size
,
483 struct lttng_channel
*chan_priv_init
);
484 struct lttng_channel
*lttng_global_channel_create(struct lttng_session
*session
,
485 int overwrite
, void *buf_addr
,
486 size_t subbuf_size
, size_t num_subbuf
,
487 unsigned int switch_timer_interval
,
488 unsigned int read_timer_interval
,
489 int **shm_fd
, int **wait_fd
,
490 uint64_t **memory_map_size
);
492 int lttng_channel_enable(struct lttng_channel
*channel
);
493 int lttng_channel_disable(struct lttng_channel
*channel
);
495 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
496 struct lttng_ust_event
*event_param
,
497 struct lttng_channel
*chan
);
498 int lttng_enabler_enable(struct lttng_enabler
*enabler
);
499 int lttng_enabler_disable(struct lttng_enabler
*enabler
);
500 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
501 struct lttng_ust_filter_bytecode_node
*bytecode
);
502 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
503 struct lttng_ust_context
*ctx
);
505 int lttng_attach_context(struct lttng_ust_context
*context_param
,
506 struct lttng_ctx
**ctx
, struct lttng_session
*session
);
508 void lttng_transport_register(struct lttng_transport
*transport
);
509 void lttng_transport_unregister(struct lttng_transport
*transport
);
511 void synchronize_trace(void);
513 int lttng_probe_register(struct lttng_probe_desc
*desc
);
514 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
515 int lttng_fix_pending_event_desc(const struct lttng_event_desc
*desc
);
516 const struct lttng_event_desc
*lttng_event_get(const char *name
);
517 void lttng_event_put(const struct lttng_event_desc
*desc
);
518 int lttng_probes_init(void);
519 void lttng_probes_exit(void);
520 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
521 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
522 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
523 struct lttng_ctx_field
*field
);
524 void lttng_destroy_context(struct lttng_ctx
*ctx
);
525 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
526 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
527 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
528 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
529 void lttng_context_vtid_reset(void);
530 void lttng_context_vpid_reset(void);
532 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
533 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
534 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
536 struct lttng_transport
*lttng_transport_find(const char *name
);
538 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
539 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
540 struct lttng_ust_tracepoint_iter
*
541 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
542 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
543 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
544 struct lttng_ust_field_iter
*
545 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
547 void lttng_filter_event_link_bytecode(struct lttng_event
*event
);
548 void lttng_enabler_event_link_bytecode(struct lttng_event
*event
,
549 struct lttng_enabler
*enabler
);
550 void lttng_free_event_filter_runtime(struct lttng_event
*event
);
551 void lttng_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
553 struct cds_list_head
*lttng_get_probe_list_head(void);
555 #endif /* _LTTNG_UST_EVENTS_H */