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>
42 #define LTTNG_UST_UUID_LEN 16
45 * Tracepoint provider version. Compatibility based on the major number.
46 * Older tracepoint providers can always register to newer lttng-ust
47 * library, but the opposite is rejected: a newer tracepoint provider is
48 * rejected by an older lttng-ust library.
50 #define LTTNG_UST_PROVIDER_MAJOR 1
51 #define LTTNG_UST_PROVIDER_MINOR 0
55 struct lttng_ust_lib_ring_buffer_ctx
;
58 * Data structures used by tracepoint event declarations, and by the
59 * tracer. Those structures have padding for future extension.
63 * LTTng client type enumeration. Used by the consumer to map the
64 * callbacks from its own address space.
66 enum lttng_client_types
{
67 LTTNG_CLIENT_METADATA
= 0,
68 LTTNG_CLIENT_DISCARD
= 1,
69 LTTNG_CLIENT_OVERWRITE
= 2,
70 LTTNG_CLIENT_DISCARD_RT
= 3,
71 LTTNG_CLIENT_OVERWRITE_RT
= 4,
72 LTTNG_NR_CLIENT_TYPES
,
75 /* Type description */
77 /* Update the astract_types name table in lttng-types.c along with this enum */
78 enum lttng_abstract_types
{
88 /* Update the string_encodings name table in lttng-types.c along with this enum */
89 enum lttng_string_encodings
{
90 lttng_encode_none
= 0,
91 lttng_encode_UTF8
= 1,
92 lttng_encode_ASCII
= 2,
96 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
97 struct lttng_enum_entry
{
98 unsigned long long start
, end
; /* start and end are inclusive */
100 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
103 #define __type_integer(_type, _byte_order, _base, _encoding) \
105 .atype = atype_integer, \
112 .size = sizeof(_type) * CHAR_BIT, \
113 .alignment = lttng_alignof(_type) * CHAR_BIT, \
114 .signedness = lttng_is_signed_type(_type), \
115 .reverse_byte_order = _byte_order != BYTE_ORDER, \
117 .encoding = lttng_encode_##_encoding, \
123 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
124 struct lttng_integer_type
{
125 unsigned int size
; /* in bits */
126 unsigned short alignment
; /* in bits */
127 unsigned int signedness
:1;
128 unsigned int reverse_byte_order
:1;
129 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
130 enum lttng_string_encodings encoding
;
131 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
135 * Only float and double are supported. long double is not supported at
138 #define _float_mant_dig(_type) \
139 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
140 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
143 #define __type_float(_type) \
145 .atype = atype_float, \
152 .exp_dig = sizeof(_type) * CHAR_BIT \
153 - _float_mant_dig(_type), \
154 .mant_dig = _float_mant_dig(_type), \
155 .alignment = lttng_alignof(_type) * CHAR_BIT, \
156 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
162 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
163 struct lttng_float_type
{
164 unsigned int exp_dig
; /* exponent digits, in bits */
165 unsigned int mant_dig
; /* mantissa digits, in bits */
166 unsigned short alignment
; /* in bits */
167 unsigned int reverse_byte_order
:1;
168 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
171 #define LTTNG_UST_BASIC_TYPE_PADDING 128
172 union _lttng_basic_type
{
173 struct lttng_integer_type integer
;
178 enum lttng_string_encodings encoding
;
180 struct lttng_float_type _float
;
181 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
184 struct lttng_basic_type
{
185 enum lttng_abstract_types atype
;
187 union _lttng_basic_type basic
;
191 #define LTTNG_UST_TYPE_PADDING 128
193 enum lttng_abstract_types atype
;
195 union _lttng_basic_type basic
;
197 struct lttng_basic_type elem_type
;
198 unsigned int length
; /* num. elems. */
201 struct lttng_basic_type length_type
;
202 struct lttng_basic_type elem_type
;
204 char padding
[LTTNG_UST_TYPE_PADDING
];
208 #define LTTNG_UST_ENUM_TYPE_PADDING 24
211 struct lttng_type container_type
;
212 const struct lttng_enum_entry
*entries
;
214 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
218 * Event field description
220 * IMPORTANT: this structure is part of the ABI between the probe and
221 * UST. Fields need to be only added at the end, never reordered, never
225 #define LTTNG_UST_EVENT_FIELD_PADDING 28
226 struct lttng_event_field
{
228 struct lttng_type type
;
229 unsigned int nowrite
; /* do not write into trace */
230 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
233 union lttng_ctx_value
{
239 #define LTTNG_UST_CTX_FIELD_PADDING 40
240 struct lttng_ctx_field
{
241 struct lttng_event_field event_field
;
242 size_t (*get_size
)(size_t offset
);
243 void (*record
)(struct lttng_ctx_field
*field
,
244 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
245 struct lttng_channel
*chan
);
246 void (*get_value
)(struct lttng_ctx_field
*field
,
247 union lttng_ctx_value
*value
);
249 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
251 void (*destroy
)(struct lttng_ctx_field
*field
);
254 #define LTTNG_UST_CTX_PADDING 20
256 struct lttng_ctx_field
*fields
;
257 unsigned int nr_fields
;
258 unsigned int allocated_fields
;
259 unsigned int largest_align
;
260 char padding
[LTTNG_UST_CTX_PADDING
];
263 #define LTTNG_UST_EVENT_DESC_PADDING 40
264 struct lttng_event_desc
{
266 void (*probe_callback
)(void);
267 const struct lttng_event_ctx
*ctx
; /* context */
268 const struct lttng_event_field
*fields
; /* event payload */
269 unsigned int nr_fields
;
270 const int **loglevel
;
271 const char *signature
; /* Argument types/names received */
274 const char **model_emf_uri
;
276 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
280 #define LTTNG_UST_PROBE_DESC_PADDING 12
281 struct lttng_probe_desc
{
282 const char *provider
;
283 const struct lttng_event_desc
**event_desc
;
284 unsigned int nr_events
;
285 struct cds_list_head head
; /* chain registered probes */
286 struct cds_list_head lazy_init_head
;
287 int lazy
; /* lazy registration */
290 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
293 /* Data structures used by the tracer. */
295 enum lttng_enabler_type
{
296 LTTNG_ENABLER_WILDCARD
,
301 * Enabler field, within whatever object is enabling an event. Target of
302 * backward reference.
304 struct lttng_enabler
{
305 enum lttng_enabler_type type
;
307 /* head list of struct lttng_ust_filter_bytecode_node */
308 struct cds_list_head filter_bytecode_head
;
309 /* head list of struct lttng_ust_excluder_node */
310 struct cds_list_head excluder_head
;
311 struct cds_list_head node
; /* per-session list of enablers */
313 struct lttng_ust_event event_param
;
314 struct lttng_channel
*chan
;
315 struct lttng_ctx
*ctx
;
316 unsigned int enabled
:1;
319 struct tp_list_entry
{
320 struct lttng_ust_tracepoint_iter tp
;
321 struct cds_list_head head
;
324 struct lttng_ust_tracepoint_list
{
325 struct tp_list_entry
*iter
;
326 struct cds_list_head head
;
329 struct tp_field_list_entry
{
330 struct lttng_ust_field_iter field
;
331 struct cds_list_head head
;
334 struct lttng_ust_field_list
{
335 struct tp_field_list_entry
*iter
;
336 struct cds_list_head head
;
339 struct ust_pending_probe
;
342 struct lttng_ust_filter_bytecode_node
{
343 struct cds_list_head node
;
344 struct lttng_enabler
*enabler
;
346 * struct lttng_ust_filter_bytecode has var. sized array, must
349 struct lttng_ust_filter_bytecode bc
;
352 struct lttng_ust_excluder_node
{
353 struct cds_list_head node
;
354 struct lttng_enabler
*enabler
;
356 * struct lttng_ust_event_exclusion had variable sized array,
357 * must be last field.
359 struct lttng_ust_event_exclusion excluder
;
362 * Filter return value masks.
364 enum lttng_filter_ret
{
365 LTTNG_FILTER_DISCARD
= 0,
366 LTTNG_FILTER_RECORD_FLAG
= (1ULL << 0),
367 /* Other bits are kept for future use. */
370 struct lttng_bytecode_runtime
{
371 /* Associated bytecode */
372 struct lttng_ust_filter_bytecode_node
*bc
;
373 uint64_t (*filter
)(void *filter_data
, const char *filter_stack_data
);
375 struct cds_list_head node
; /* list of bytecode runtime in event */
379 * Objects in a linked-list of enablers, owned by an event.
381 struct lttng_enabler_ref
{
382 struct cds_list_head node
; /* enabler ref list */
383 struct lttng_enabler
*ref
; /* backward ref */
387 * lttng_event structure is referred to by the tracing fast path. It
388 * must be kept small.
390 * IMPORTANT: this structure is part of the ABI between the probe and
391 * UST. Fields need to be only added at the end, never reordered, never
395 /* LTTng-UST 2.0 starts here */
397 struct lttng_channel
*chan
;
399 const struct lttng_event_desc
*desc
;
401 struct lttng_ctx
*ctx
;
402 enum lttng_ust_instrumentation instrumentation
;
405 struct cds_list_head node
; /* Event list in session */
406 struct cds_list_head _deprecated2
;
408 unsigned int _deprecated4
:1;
410 /* LTTng-UST 2.1 starts here */
411 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
412 struct cds_list_head bytecode_runtime_head
;
413 int has_enablers_without_bytecode
;
414 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
415 struct cds_list_head enablers_ref_head
;
416 struct cds_hlist_node hlist
; /* session ht of events */
417 int registered
; /* has reg'd tracepoint probe */
421 struct lttng_ust_shm_handle
;
424 * IMPORTANT: this structure is part of the ABI between the probe and
425 * UST. Fields need to be only added at the end, never reordered, never
428 struct lttng_channel_ops
{
429 struct lttng_channel
*(*channel_create
)(const char *name
,
431 size_t subbuf_size
, size_t num_subbuf
,
432 unsigned int switch_timer_interval
,
433 unsigned int read_timer_interval
,
436 void (*channel_destroy
)(struct lttng_channel
*chan
);
439 unsigned long has_strcpy
:1; /* ABI has strcpy */
442 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
444 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
445 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
446 const void *src
, size_t len
);
448 * packet_avail_size returns the available size in the current
449 * packet. Note that the size returned is only a hint, since it
450 * may change due to concurrent writes.
452 size_t (*packet_avail_size
)(struct channel
*chan
,
453 struct lttng_ust_shm_handle
*handle
);
454 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
455 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
456 int (*is_finalized
)(struct channel
*chan
);
457 int (*is_disabled
)(struct channel
*chan
);
458 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
459 void (*event_strcpy
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
460 const char *src
, size_t len
);
464 * IMPORTANT: this structure is part of the ABI between the probe and
465 * UST. Fields need to be only added at the end, never reordered, never
468 struct lttng_channel
{
470 * The pointers located in this private data are NOT safe to be
471 * dereferenced by the consumer. The only operations the
472 * consumer process is designed to be allowed to do is to read
473 * and perform subbuffer flush.
475 struct channel
*chan
; /* Channel buffers */
477 struct lttng_ctx
*ctx
;
478 /* Event ID management */
479 struct lttng_session
*session
;
480 int objd
; /* Object associated to channel */
481 unsigned int _deprecated1
;
482 unsigned int _deprecated2
;
483 struct cds_list_head node
; /* Channel list in session */
484 const struct lttng_channel_ops
*ops
;
485 int header_type
; /* 0: unset, 1: compact, 2: large */
486 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
487 unsigned int _deprecated3
:1;
491 enum lttng_ust_chan_type type
;
492 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
493 int tstate
:1; /* Transient enable state */
496 #define LTTNG_UST_EVENT_HT_BITS 12
497 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
499 struct lttng_ust_event_ht
{
500 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
504 * IMPORTANT: this structure is part of the ABI between the probe and
505 * UST. Fields need to be only added at the end, never reordered, never
508 struct lttng_session
{
509 int active
; /* Is trace session active ? */
510 int been_active
; /* Been active ? */
511 int objd
; /* Object associated */
513 struct cds_list_head chan_head
; /* Channel list head */
514 struct cds_list_head events_head
; /* list of events */
515 struct cds_list_head _deprecated2
;
516 struct cds_list_head node
; /* Session list */
518 unsigned int _deprecated4
:1;
521 /* List of enablers */
522 struct cds_list_head enablers_head
;
523 struct lttng_ust_event_ht events_ht
; /* ht of events */
524 void *owner
; /* object owner */
525 int tstate
:1; /* Transient enable state */
528 int statedump_pending
:1;
531 struct lttng_transport
{
533 struct cds_list_head node
;
534 struct lttng_channel_ops ops
;
535 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
538 struct lttng_session
*lttng_session_create(void);
539 int lttng_session_enable(struct lttng_session
*session
);
540 int lttng_session_disable(struct lttng_session
*session
);
541 void lttng_session_destroy(struct lttng_session
*session
);
543 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
544 const char *transport_name
,
546 size_t subbuf_size
, size_t num_subbuf
,
547 unsigned int switch_timer_interval
,
548 unsigned int read_timer_interval
,
549 int **shm_fd
, int **wait_fd
,
550 uint64_t **memory_map_size
,
551 struct lttng_channel
*chan_priv_init
);
553 int lttng_channel_enable(struct lttng_channel
*channel
);
554 int lttng_channel_disable(struct lttng_channel
*channel
);
556 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
557 struct lttng_ust_event
*event_param
,
558 struct lttng_channel
*chan
);
559 int lttng_enabler_enable(struct lttng_enabler
*enabler
);
560 int lttng_enabler_disable(struct lttng_enabler
*enabler
);
561 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
562 struct lttng_ust_filter_bytecode_node
*bytecode
);
563 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
564 struct lttng_ust_context
*ctx
);
565 int lttng_enabler_attach_exclusion(struct lttng_enabler
*enabler
,
566 struct lttng_ust_excluder_node
*excluder
);
568 int lttng_attach_context(struct lttng_ust_context
*context_param
,
569 struct lttng_ctx
**ctx
, struct lttng_session
*session
);
570 void lttng_context_init(void);
571 void lttng_context_exit(void);
572 extern struct lttng_ctx
*lttng_static_ctx
; /* Used by filtering */
574 void lttng_transport_register(struct lttng_transport
*transport
);
575 void lttng_transport_unregister(struct lttng_transport
*transport
);
577 void synchronize_trace(void);
579 int lttng_probe_register(struct lttng_probe_desc
*desc
);
580 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
581 int lttng_fix_pending_events(void);
582 int lttng_probes_init(void);
583 void lttng_probes_exit(void);
584 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
585 int lttng_get_context_index(struct lttng_ctx
*ctx
, const char *name
);
586 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
587 void lttng_context_update(struct lttng_ctx
*ctx
);
588 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
589 struct lttng_ctx_field
*field
);
590 void lttng_destroy_context(struct lttng_ctx
*ctx
);
591 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
592 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
593 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
594 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
595 int lttng_add_ip_to_ctx(struct lttng_ctx
**ctx
);
596 void lttng_context_vtid_reset(void);
597 void lttng_context_vpid_reset(void);
599 extern const struct lttng_ust_client_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
600 extern const struct lttng_ust_client_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
601 extern const struct lttng_ust_client_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
603 struct lttng_transport
*lttng_transport_find(const char *name
);
605 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
606 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
607 struct lttng_ust_tracepoint_iter
*
608 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
609 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
610 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
611 struct lttng_ust_field_iter
*
612 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
614 void lttng_filter_event_link_bytecode(struct lttng_event
*event
);
615 void lttng_enabler_event_link_bytecode(struct lttng_event
*event
,
616 struct lttng_enabler
*enabler
);
617 void lttng_free_event_filter_runtime(struct lttng_event
*event
);
618 void lttng_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
620 struct cds_list_head
*lttng_get_probe_list_head(void);
621 int lttng_session_active(void);
623 typedef int (*t_statedump_func_ptr
)(struct lttng_session
*session
);
624 void lttng_handle_pending_statedump(void *owner
);
625 struct cds_list_head
*_lttng_get_sessions(void);
631 #endif /* _LTTNG_UST_EVENTS_H */