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.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <urcu/list.h>
31 #include <urcu/hlist.h>
33 #include <lttng/ust-abi.h>
34 #include <lttng/ust-tracer.h>
35 #include <lttng/ust-endian.h>
38 #define LTTNG_UST_UUID_LEN 16
42 struct lttng_ust_lib_ring_buffer_ctx
;
45 * Data structures used by tracepoint event declarations, and by the
46 * tracer. Those structures have padding for future extension.
50 * LTTng client type enumeration. Used by the consumer to map the
51 * callbacks from its own address space.
53 enum lttng_client_types
{
54 LTTNG_CLIENT_METADATA
= 0,
55 LTTNG_CLIENT_DISCARD
= 1,
56 LTTNG_CLIENT_OVERWRITE
= 2,
57 LTTNG_NR_CLIENT_TYPES
,
60 /* Type description */
62 /* Update the astract_types name table in lttng-types.c along with this enum */
63 enum lttng_abstract_types
{
73 /* Update the string_encodings name table in lttng-types.c along with this enum */
74 enum lttng_string_encodings
{
75 lttng_encode_none
= 0,
76 lttng_encode_UTF8
= 1,
77 lttng_encode_ASCII
= 2,
81 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
82 struct lttng_enum_entry
{
83 unsigned long long start
, end
; /* start and end are inclusive */
85 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
88 #define __type_integer(_type, _byte_order, _base, _encoding) \
90 .atype = atype_integer, \
93 .size = sizeof(_type) * CHAR_BIT, \
94 .alignment = lttng_alignof(_type) * CHAR_BIT, \
95 .signedness = lttng_is_signed_type(_type), \
96 .reverse_byte_order = _byte_order != BYTE_ORDER, \
98 .encoding = lttng_encode_##_encoding, \
102 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
103 struct lttng_integer_type
{
104 unsigned int size
; /* in bits */
105 unsigned short alignment
; /* in bits */
106 unsigned int signedness
:1;
107 unsigned int reverse_byte_order
:1;
108 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
109 enum lttng_string_encodings encoding
;
110 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
114 * Only float and double are supported. long double is not supported at
117 #define _float_mant_dig(_type) \
118 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
119 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
122 #define __type_float(_type) \
124 .atype = atype_float, \
127 .exp_dig = sizeof(_type) * CHAR_BIT \
128 - _float_mant_dig(_type), \
129 .mant_dig = _float_mant_dig(_type), \
130 .alignment = lttng_alignof(_type) * CHAR_BIT, \
131 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
135 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
136 struct lttng_float_type
{
137 unsigned int exp_dig
; /* exponent digits, in bits */
138 unsigned int mant_dig
; /* mantissa digits, in bits */
139 unsigned short alignment
; /* in bits */
140 unsigned int reverse_byte_order
:1;
141 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
144 #define LTTNG_UST_BASIC_TYPE_PADDING 128
145 union _lttng_basic_type
{
146 struct lttng_integer_type integer
;
151 enum lttng_string_encodings encoding
;
153 struct lttng_float_type _float
;
154 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
157 struct lttng_basic_type
{
158 enum lttng_abstract_types atype
;
160 union _lttng_basic_type basic
;
164 #define LTTNG_UST_TYPE_PADDING 128
166 enum lttng_abstract_types atype
;
168 union _lttng_basic_type basic
;
170 struct lttng_basic_type elem_type
;
171 unsigned int length
; /* num. elems. */
174 struct lttng_basic_type length_type
;
175 struct lttng_basic_type elem_type
;
177 char padding
[LTTNG_UST_TYPE_PADDING
];
181 #define LTTNG_UST_ENUM_TYPE_PADDING 24
184 struct lttng_type container_type
;
185 const struct lttng_enum_entry
*entries
;
187 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
191 * Event field description
193 * IMPORTANT: this structure is part of the ABI between the probe and
194 * UST. Fields need to be only added at the end, never reordered, never
198 #define LTTNG_UST_EVENT_FIELD_PADDING 28
199 struct lttng_event_field
{
201 struct lttng_type type
;
202 unsigned int nowrite
; /* do not write into trace */
203 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
206 #define LTTNG_UST_CTX_FIELD_PADDING 40
207 struct lttng_ctx_field
{
208 struct lttng_event_field event_field
;
209 size_t (*get_size
)(size_t offset
);
210 void (*record
)(struct lttng_ctx_field
*field
,
211 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
212 struct lttng_channel
*chan
);
214 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
216 void (*destroy
)(struct lttng_ctx_field
*field
);
219 #define LTTNG_UST_CTX_PADDING 24
221 struct lttng_ctx_field
*fields
;
222 unsigned int nr_fields
;
223 unsigned int allocated_fields
;
224 char padding
[LTTNG_UST_CTX_PADDING
];
227 #define LTTNG_UST_EVENT_DESC_PADDING 40
228 struct lttng_event_desc
{
230 void (*probe_callback
)(void);
231 const struct lttng_event_ctx
*ctx
; /* context */
232 const struct lttng_event_field
*fields
; /* event payload */
233 unsigned int nr_fields
;
234 const int **loglevel
;
235 const char *signature
; /* Argument types/names received */
238 const char **model_emf_uri
;
240 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
244 #define LTTNG_UST_PROBE_DESC_PADDING 40
245 struct lttng_probe_desc
{
246 const char *provider
;
247 const struct lttng_event_desc
**event_desc
;
248 unsigned int nr_events
;
249 struct cds_list_head head
; /* chain registered probes */
250 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
253 /* Data structures used by the tracer. */
255 enum lttng_enabler_type
{
256 LTTNG_ENABLER_WILDCARD
,
261 * Enabler field, within whatever object is enabling an event. Target of
262 * backward reference.
264 struct lttng_enabler
{
265 enum lttng_enabler_type type
;
267 /* head list of struct lttng_ust_filter_bytecode_node */
268 struct cds_list_head filter_bytecode_head
;
269 struct cds_list_head node
; /* per-session list of enablers */
271 struct lttng_ust_event event_param
;
272 struct lttng_channel
*chan
;
273 struct lttng_ctx
*ctx
;
274 unsigned int enabled
:1;
277 struct tp_list_entry
{
278 struct lttng_ust_tracepoint_iter tp
;
279 struct cds_list_head head
;
282 struct lttng_ust_tracepoint_list
{
283 struct tp_list_entry
*iter
;
284 struct cds_list_head head
;
287 struct tp_field_list_entry
{
288 struct lttng_ust_field_iter field
;
289 struct cds_list_head head
;
292 struct lttng_ust_field_list
{
293 struct tp_field_list_entry
*iter
;
294 struct cds_list_head head
;
297 struct ust_pending_probe
;
300 struct lttng_ust_filter_bytecode_node
{
301 struct cds_list_head node
;
302 struct lttng_enabler
*enabler
;
304 * struct lttng_ust_filter_bytecode has var. sized array, must
307 struct lttng_ust_filter_bytecode bc
;
311 * Filter return value masks.
313 enum lttng_filter_ret
{
314 LTTNG_FILTER_DISCARD
= 0,
315 LTTNG_FILTER_RECORD_FLAG
= (1ULL << 0),
316 /* Other bits are kept for future use. */
319 struct lttng_bytecode_runtime
{
320 /* Associated bytecode */
321 struct lttng_ust_filter_bytecode_node
*bc
;
322 uint64_t (*filter
)(void *filter_data
, const char *filter_stack_data
);
324 struct cds_list_head node
; /* list of bytecode runtime in event */
328 * Objects in a linked-list of enablers, owned by an event.
330 struct lttng_enabler_ref
{
331 struct cds_list_head node
; /* enabler ref list */
332 struct lttng_enabler
*ref
; /* backward ref */
336 * lttng_event structure is referred to by the tracing fast path. It
337 * must be kept small.
339 * IMPORTANT: this structure is part of the ABI between the probe and
340 * UST. Fields need to be only added at the end, never reordered, never
344 /* LTTng-UST 2.0 starts here */
346 struct lttng_channel
*chan
;
348 const struct lttng_event_desc
*desc
;
350 struct lttng_ctx
*ctx
;
351 enum lttng_ust_instrumentation instrumentation
;
354 struct cds_list_head node
; /* Event list in session */
355 struct cds_list_head _deprecated2
;
357 unsigned int metadata_dumped
:1;
359 /* LTTng-UST 2.1 starts here */
360 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
361 struct cds_list_head bytecode_runtime_head
;
362 int has_enablers_without_bytecode
;
363 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
364 struct cds_list_head enablers_ref_head
;
365 struct cds_hlist_node hlist
; /* session ht of events */
369 struct lttng_ust_shm_handle
;
372 * IMPORTANT: this structure is part of the ABI between the probe and
373 * UST. Fields need to be only added at the end, never reordered, never
376 struct lttng_channel_ops
{
377 struct lttng_channel
*(*channel_create
)(const char *name
,
379 size_t subbuf_size
, size_t num_subbuf
,
380 unsigned int switch_timer_interval
,
381 unsigned int read_timer_interval
,
382 int **shm_fd
, int **wait_fd
,
383 uint64_t **memory_map_size
,
384 struct lttng_channel
*chan_priv_init
);
385 void (*channel_destroy
)(struct lttng_channel
*lttng_chan
);
386 struct lttng_ust_lib_ring_buffer
*(*buffer_read_open
)(struct channel
*chan
,
387 struct lttng_ust_shm_handle
*handle
,
388 int **shm_fd
, int **wait_fd
,
389 uint64_t **memory_map_size
);
390 void (*buffer_read_close
)(struct lttng_ust_lib_ring_buffer
*buf
,
391 struct lttng_ust_shm_handle
*handle
);
392 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
394 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
395 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
, const void *src
,
398 * packet_avail_size returns the available size in the current
399 * packet. Note that the size returned is only a hint, since it
400 * may change due to concurrent writes.
402 size_t (*packet_avail_size
)(struct channel
*chan
,
403 struct lttng_ust_shm_handle
*handle
);
404 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
405 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
406 int (*is_finalized
)(struct channel
*chan
);
407 int (*is_disabled
)(struct channel
*chan
);
408 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
412 * IMPORTANT: this structure is part of the ABI between the probe and
413 * UST. Fields need to be only added at the end, never reordered, never
416 struct lttng_channel
{
418 * The pointers located in this private data are NOT safe to be
419 * dereferenced by the consumer. The only operations the
420 * consumer process is designed to be allowed to do is to read
421 * and perform subbuffer flush.
423 struct channel
*chan
; /* Channel buffers */
425 struct lttng_ctx
*ctx
;
426 /* Event ID management */
427 struct lttng_session
*session
;
428 int objd
; /* Object associated to channel */
429 unsigned int free_event_id
; /* Next event ID to allocate */
430 unsigned int used_event_id
; /* Max allocated event IDs */
431 struct cds_list_head node
; /* Channel list in session */
432 struct lttng_channel_ops
*ops
;
433 int header_type
; /* 0: unset, 1: compact, 2: large */
434 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
435 unsigned int metadata_dumped
:1;
437 /* Channel ID, available for consumer too */
439 /* Copy of session UUID for consumer (availability through shm) */
440 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
443 #define LTTNG_UST_EVENT_HT_BITS 6
444 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
446 struct lttng_ust_event_ht
{
447 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
451 * IMPORTANT: this structure is part of the ABI between the probe and
452 * UST. Fields need to be only added at the end, never reordered, never
455 struct lttng_session
{
456 int active
; /* Is trace session active ? */
457 int been_active
; /* Been active ? */
458 int objd
; /* Object associated */
459 struct lttng_channel
*metadata
; /* Metadata channel */
460 struct cds_list_head chan_head
; /* Channel list head */
461 struct cds_list_head events_head
; /* list of events */
462 struct cds_list_head _deprecated1
;
463 struct cds_list_head node
; /* Session list */
464 unsigned int free_chan_id
; /* Next chan ID to allocate */
465 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
466 unsigned int metadata_dumped
:1;
469 /* List of enablers */
470 struct cds_list_head enablers_head
;
471 struct lttng_ust_event_ht events_ht
; /* ht of events */
474 struct lttng_transport
{
476 struct cds_list_head node
;
477 struct lttng_channel_ops ops
;
480 struct lttng_session
*lttng_session_create(void);
481 int lttng_session_enable(struct lttng_session
*session
);
482 int lttng_session_disable(struct lttng_session
*session
);
483 void lttng_session_destroy(struct lttng_session
*session
);
485 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
486 const char *transport_name
,
488 size_t subbuf_size
, size_t num_subbuf
,
489 unsigned int switch_timer_interval
,
490 unsigned int read_timer_interval
,
491 int **shm_fd
, int **wait_fd
,
492 uint64_t **memory_map_size
,
493 struct lttng_channel
*chan_priv_init
);
494 struct lttng_channel
*lttng_global_channel_create(struct lttng_session
*session
,
495 int overwrite
, void *buf_addr
,
496 size_t subbuf_size
, size_t num_subbuf
,
497 unsigned int switch_timer_interval
,
498 unsigned int read_timer_interval
,
499 int **shm_fd
, int **wait_fd
,
500 uint64_t **memory_map_size
);
502 int lttng_channel_enable(struct lttng_channel
*channel
);
503 int lttng_channel_disable(struct lttng_channel
*channel
);
505 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
506 struct lttng_ust_event
*event_param
,
507 struct lttng_channel
*chan
);
508 int lttng_enabler_enable(struct lttng_enabler
*enabler
);
509 int lttng_enabler_disable(struct lttng_enabler
*enabler
);
510 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
511 struct lttng_ust_filter_bytecode_node
*bytecode
);
512 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
513 struct lttng_ust_context
*ctx
);
515 int lttng_attach_context(struct lttng_ust_context
*context_param
,
516 struct lttng_ctx
**ctx
, struct lttng_session
*session
);
518 void lttng_transport_register(struct lttng_transport
*transport
);
519 void lttng_transport_unregister(struct lttng_transport
*transport
);
521 void synchronize_trace(void);
523 int lttng_probe_register(struct lttng_probe_desc
*desc
);
524 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
525 int lttng_fix_pending_event_desc(const struct lttng_event_desc
*desc
);
526 const struct lttng_event_desc
*lttng_event_get(const char *name
);
527 void lttng_event_put(const struct lttng_event_desc
*desc
);
528 int lttng_probes_init(void);
529 void lttng_probes_exit(void);
530 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
531 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
532 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
533 struct lttng_ctx_field
*field
);
534 void lttng_destroy_context(struct lttng_ctx
*ctx
);
535 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
536 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
537 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
538 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
539 void lttng_context_vtid_reset(void);
540 void lttng_context_vpid_reset(void);
542 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
543 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
544 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
546 struct lttng_transport
*lttng_transport_find(const char *name
);
548 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
549 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
550 struct lttng_ust_tracepoint_iter
*
551 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
552 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
553 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
554 struct lttng_ust_field_iter
*
555 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
557 void lttng_filter_event_link_bytecode(struct lttng_event
*event
);
558 void lttng_enabler_event_link_bytecode(struct lttng_event
*event
,
559 struct lttng_enabler
*enabler
);
560 void lttng_free_event_filter_runtime(struct lttng_event
*event
);
561 void lttng_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
563 struct cds_list_head
*lttng_get_probe_list_head(void);
565 #endif /* _LTTNG_UST_EVENTS_H */