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
41 * Tracepoint provider version. Compatibility based on the major number.
42 * Older tracepoint providers can always register to newer lttng-ust
43 * library, but the opposite is rejected: a newer tracepoint provider is
44 * rejected by an older lttng-ust library.
46 #define LTTNG_UST_PROVIDER_MAJOR 1
47 #define LTTNG_UST_PROVIDER_MINOR 0
51 struct lttng_ust_lib_ring_buffer_ctx
;
54 * Data structures used by tracepoint event declarations, and by the
55 * tracer. Those structures have padding for future extension.
59 * LTTng client type enumeration. Used by the consumer to map the
60 * callbacks from its own address space.
62 enum lttng_client_types
{
63 LTTNG_CLIENT_METADATA
= 0,
64 LTTNG_CLIENT_DISCARD
= 1,
65 LTTNG_CLIENT_OVERWRITE
= 2,
66 LTTNG_CLIENT_DISCARD_RT
= 3,
67 LTTNG_CLIENT_OVERWRITE_RT
= 4,
68 LTTNG_NR_CLIENT_TYPES
,
71 /* Type description */
73 /* Update the astract_types name table in lttng-types.c along with this enum */
74 enum lttng_abstract_types
{
84 /* Update the string_encodings name table in lttng-types.c along with this enum */
85 enum lttng_string_encodings
{
86 lttng_encode_none
= 0,
87 lttng_encode_UTF8
= 1,
88 lttng_encode_ASCII
= 2,
92 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
93 struct lttng_enum_entry
{
94 unsigned long long start
, end
; /* start and end are inclusive */
96 char padding
[LTTNG_UST_ENUM_ENTRY_PADDING
];
99 #define __type_integer(_type, _byte_order, _base, _encoding) \
101 .atype = atype_integer, \
108 .size = sizeof(_type) * CHAR_BIT, \
109 .alignment = lttng_alignof(_type) * CHAR_BIT, \
110 .signedness = lttng_is_signed_type(_type), \
111 .reverse_byte_order = _byte_order != BYTE_ORDER, \
113 .encoding = lttng_encode_##_encoding, \
119 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
120 struct lttng_integer_type
{
121 unsigned int size
; /* in bits */
122 unsigned short alignment
; /* in bits */
123 unsigned int signedness
:1;
124 unsigned int reverse_byte_order
:1;
125 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
126 enum lttng_string_encodings encoding
;
127 char padding
[LTTNG_UST_INTEGER_TYPE_PADDING
];
131 * Only float and double are supported. long double is not supported at
134 #define _float_mant_dig(_type) \
135 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
136 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
139 #define __type_float(_type) \
141 .atype = atype_float, \
148 .exp_dig = sizeof(_type) * CHAR_BIT \
149 - _float_mant_dig(_type), \
150 .mant_dig = _float_mant_dig(_type), \
151 .alignment = lttng_alignof(_type) * CHAR_BIT, \
152 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
158 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
159 struct lttng_float_type
{
160 unsigned int exp_dig
; /* exponent digits, in bits */
161 unsigned int mant_dig
; /* mantissa digits, in bits */
162 unsigned short alignment
; /* in bits */
163 unsigned int reverse_byte_order
:1;
164 char padding
[LTTNG_UST_FLOAT_TYPE_PADDING
];
167 #define LTTNG_UST_BASIC_TYPE_PADDING 128
168 union _lttng_basic_type
{
169 struct lttng_integer_type integer
;
174 enum lttng_string_encodings encoding
;
176 struct lttng_float_type _float
;
177 char padding
[LTTNG_UST_BASIC_TYPE_PADDING
];
180 struct lttng_basic_type
{
181 enum lttng_abstract_types atype
;
183 union _lttng_basic_type basic
;
187 #define LTTNG_UST_TYPE_PADDING 128
189 enum lttng_abstract_types atype
;
191 union _lttng_basic_type basic
;
193 struct lttng_basic_type elem_type
;
194 unsigned int length
; /* num. elems. */
197 struct lttng_basic_type length_type
;
198 struct lttng_basic_type elem_type
;
200 char padding
[LTTNG_UST_TYPE_PADDING
];
204 #define LTTNG_UST_ENUM_TYPE_PADDING 24
207 struct lttng_type container_type
;
208 const struct lttng_enum_entry
*entries
;
210 char padding
[LTTNG_UST_ENUM_TYPE_PADDING
];
214 * Event field description
216 * IMPORTANT: this structure is part of the ABI between the probe and
217 * UST. Fields need to be only added at the end, never reordered, never
221 #define LTTNG_UST_EVENT_FIELD_PADDING 28
222 struct lttng_event_field
{
224 struct lttng_type type
;
225 unsigned int nowrite
; /* do not write into trace */
226 char padding
[LTTNG_UST_EVENT_FIELD_PADDING
];
229 union lttng_ctx_value
{
235 #define LTTNG_UST_CTX_FIELD_PADDING 40
236 struct lttng_ctx_field
{
237 struct lttng_event_field event_field
;
238 size_t (*get_size
)(size_t offset
);
239 void (*record
)(struct lttng_ctx_field
*field
,
240 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
241 struct lttng_channel
*chan
);
242 void (*get_value
)(struct lttng_ctx_field
*field
,
243 union lttng_ctx_value
*value
);
245 char padding
[LTTNG_UST_CTX_FIELD_PADDING
];
247 void (*destroy
)(struct lttng_ctx_field
*field
);
250 #define LTTNG_UST_CTX_PADDING 24
252 struct lttng_ctx_field
*fields
;
253 unsigned int nr_fields
;
254 unsigned int allocated_fields
;
255 char padding
[LTTNG_UST_CTX_PADDING
];
258 #define LTTNG_UST_EVENT_DESC_PADDING 40
259 struct lttng_event_desc
{
261 void (*probe_callback
)(void);
262 const struct lttng_event_ctx
*ctx
; /* context */
263 const struct lttng_event_field
*fields
; /* event payload */
264 unsigned int nr_fields
;
265 const int **loglevel
;
266 const char *signature
; /* Argument types/names received */
269 const char **model_emf_uri
;
271 char padding
[LTTNG_UST_EVENT_DESC_PADDING
];
275 #define LTTNG_UST_PROBE_DESC_PADDING 12
276 struct lttng_probe_desc
{
277 const char *provider
;
278 const struct lttng_event_desc
**event_desc
;
279 unsigned int nr_events
;
280 struct cds_list_head head
; /* chain registered probes */
281 struct cds_list_head lazy_init_head
;
282 int lazy
; /* lazy registration */
285 char padding
[LTTNG_UST_PROBE_DESC_PADDING
];
288 /* Data structures used by the tracer. */
290 enum lttng_enabler_type
{
291 LTTNG_ENABLER_WILDCARD
,
296 * Enabler field, within whatever object is enabling an event. Target of
297 * backward reference.
299 struct lttng_enabler
{
300 enum lttng_enabler_type type
;
302 /* head list of struct lttng_ust_filter_bytecode_node */
303 struct cds_list_head filter_bytecode_head
;
304 struct cds_list_head node
; /* per-session list of enablers */
306 struct lttng_ust_event event_param
;
307 struct lttng_channel
*chan
;
308 struct lttng_ctx
*ctx
;
309 unsigned int enabled
:1;
312 struct tp_list_entry
{
313 struct lttng_ust_tracepoint_iter tp
;
314 struct cds_list_head head
;
317 struct lttng_ust_tracepoint_list
{
318 struct tp_list_entry
*iter
;
319 struct cds_list_head head
;
322 struct tp_field_list_entry
{
323 struct lttng_ust_field_iter field
;
324 struct cds_list_head head
;
327 struct lttng_ust_field_list
{
328 struct tp_field_list_entry
*iter
;
329 struct cds_list_head head
;
332 struct ust_pending_probe
;
335 struct lttng_ust_filter_bytecode_node
{
336 struct cds_list_head node
;
337 struct lttng_enabler
*enabler
;
339 * struct lttng_ust_filter_bytecode has var. sized array, must
342 struct lttng_ust_filter_bytecode bc
;
346 * Filter return value masks.
348 enum lttng_filter_ret
{
349 LTTNG_FILTER_DISCARD
= 0,
350 LTTNG_FILTER_RECORD_FLAG
= (1ULL << 0),
351 /* Other bits are kept for future use. */
354 struct lttng_bytecode_runtime
{
355 /* Associated bytecode */
356 struct lttng_ust_filter_bytecode_node
*bc
;
357 uint64_t (*filter
)(void *filter_data
, const char *filter_stack_data
);
359 struct cds_list_head node
; /* list of bytecode runtime in event */
363 * Objects in a linked-list of enablers, owned by an event.
365 struct lttng_enabler_ref
{
366 struct cds_list_head node
; /* enabler ref list */
367 struct lttng_enabler
*ref
; /* backward ref */
371 * lttng_event structure is referred to by the tracing fast path. It
372 * must be kept small.
374 * IMPORTANT: this structure is part of the ABI between the probe and
375 * UST. Fields need to be only added at the end, never reordered, never
379 /* LTTng-UST 2.0 starts here */
381 struct lttng_channel
*chan
;
383 const struct lttng_event_desc
*desc
;
385 struct lttng_ctx
*ctx
;
386 enum lttng_ust_instrumentation instrumentation
;
389 struct cds_list_head node
; /* Event list in session */
390 struct cds_list_head _deprecated2
;
392 unsigned int _deprecated4
:1;
394 /* LTTng-UST 2.1 starts here */
395 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
396 struct cds_list_head bytecode_runtime_head
;
397 int has_enablers_without_bytecode
;
398 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
399 struct cds_list_head enablers_ref_head
;
400 struct cds_hlist_node hlist
; /* session ht of events */
401 int registered
; /* has reg'd tracepoint probe */
405 struct lttng_ust_shm_handle
;
408 * IMPORTANT: this structure is part of the ABI between the probe and
409 * UST. Fields need to be only added at the end, never reordered, never
412 struct lttng_channel_ops
{
413 struct lttng_channel
*(*channel_create
)(const char *name
,
415 size_t subbuf_size
, size_t num_subbuf
,
416 unsigned int switch_timer_interval
,
417 unsigned int read_timer_interval
,
420 void (*channel_destroy
)(struct lttng_channel
*chan
);
423 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
425 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
426 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
427 const void *src
, size_t len
);
429 * packet_avail_size returns the available size in the current
430 * packet. Note that the size returned is only a hint, since it
431 * may change due to concurrent writes.
433 size_t (*packet_avail_size
)(struct channel
*chan
,
434 struct lttng_ust_shm_handle
*handle
);
435 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
436 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
437 int (*is_finalized
)(struct channel
*chan
);
438 int (*is_disabled
)(struct channel
*chan
);
439 int (*flush_buffer
)(struct channel
*chan
, struct lttng_ust_shm_handle
*handle
);
443 * IMPORTANT: this structure is part of the ABI between the probe and
444 * UST. Fields need to be only added at the end, never reordered, never
447 struct lttng_channel
{
449 * The pointers located in this private data are NOT safe to be
450 * dereferenced by the consumer. The only operations the
451 * consumer process is designed to be allowed to do is to read
452 * and perform subbuffer flush.
454 struct channel
*chan
; /* Channel buffers */
456 struct lttng_ctx
*ctx
;
457 /* Event ID management */
458 struct lttng_session
*session
;
459 int objd
; /* Object associated to channel */
460 unsigned int _deprecated1
;
461 unsigned int _deprecated2
;
462 struct cds_list_head node
; /* Channel list in session */
463 const struct lttng_channel_ops
*ops
;
464 int header_type
; /* 0: unset, 1: compact, 2: large */
465 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
466 unsigned int _deprecated3
:1;
470 enum lttng_ust_chan_type type
;
471 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
472 int tstate
:1; /* Transient enable state */
475 #define LTTNG_UST_EVENT_HT_BITS 12
476 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
478 struct lttng_ust_event_ht
{
479 struct cds_hlist_head table
[LTTNG_UST_EVENT_HT_SIZE
];
483 * IMPORTANT: this structure is part of the ABI between the probe and
484 * UST. Fields need to be only added at the end, never reordered, never
487 struct lttng_session
{
488 int active
; /* Is trace session active ? */
489 int been_active
; /* Been active ? */
490 int objd
; /* Object associated */
492 struct cds_list_head chan_head
; /* Channel list head */
493 struct cds_list_head events_head
; /* list of events */
494 struct cds_list_head _deprecated2
;
495 struct cds_list_head node
; /* Session list */
497 unsigned int _deprecated4
:1;
500 /* List of enablers */
501 struct cds_list_head enablers_head
;
502 struct lttng_ust_event_ht events_ht
; /* ht of events */
503 void *owner
; /* object owner */
504 int tstate
:1; /* Transient enable state */
507 struct lttng_transport
{
509 struct cds_list_head node
;
510 struct lttng_channel_ops ops
;
511 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
514 struct lttng_session
*lttng_session_create(void);
515 int lttng_session_enable(struct lttng_session
*session
);
516 int lttng_session_disable(struct lttng_session
*session
);
517 void lttng_session_destroy(struct lttng_session
*session
);
519 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
520 const char *transport_name
,
522 size_t subbuf_size
, size_t num_subbuf
,
523 unsigned int switch_timer_interval
,
524 unsigned int read_timer_interval
,
525 int **shm_fd
, int **wait_fd
,
526 uint64_t **memory_map_size
,
527 struct lttng_channel
*chan_priv_init
);
529 int lttng_channel_enable(struct lttng_channel
*channel
);
530 int lttng_channel_disable(struct lttng_channel
*channel
);
532 struct lttng_enabler
*lttng_enabler_create(enum lttng_enabler_type type
,
533 struct lttng_ust_event
*event_param
,
534 struct lttng_channel
*chan
);
535 int lttng_enabler_enable(struct lttng_enabler
*enabler
);
536 int lttng_enabler_disable(struct lttng_enabler
*enabler
);
537 int lttng_enabler_attach_bytecode(struct lttng_enabler
*enabler
,
538 struct lttng_ust_filter_bytecode_node
*bytecode
);
539 int lttng_enabler_attach_context(struct lttng_enabler
*enabler
,
540 struct lttng_ust_context
*ctx
);
542 int lttng_attach_context(struct lttng_ust_context
*context_param
,
543 struct lttng_ctx
**ctx
, struct lttng_session
*session
);
544 void lttng_context_init(void);
545 void lttng_context_exit(void);
546 struct lttng_ctx
*lttng_static_ctx
; /* Used by filtering */
548 void lttng_transport_register(struct lttng_transport
*transport
);
549 void lttng_transport_unregister(struct lttng_transport
*transport
);
551 void synchronize_trace(void);
553 int lttng_probe_register(struct lttng_probe_desc
*desc
);
554 void lttng_probe_unregister(struct lttng_probe_desc
*desc
);
555 int lttng_fix_pending_events(void);
556 int lttng_probes_init(void);
557 void lttng_probes_exit(void);
558 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
);
559 int lttng_get_context_index(struct lttng_ctx
*ctx
, const char *name
);
560 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
);
561 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
562 struct lttng_ctx_field
*field
);
563 void lttng_destroy_context(struct lttng_ctx
*ctx
);
564 int lttng_add_vtid_to_ctx(struct lttng_ctx
**ctx
);
565 int lttng_add_vpid_to_ctx(struct lttng_ctx
**ctx
);
566 int lttng_add_pthread_id_to_ctx(struct lttng_ctx
**ctx
);
567 int lttng_add_procname_to_ctx(struct lttng_ctx
**ctx
);
568 int lttng_add_ip_to_ctx(struct lttng_ctx
**ctx
);
569 void lttng_context_vtid_reset(void);
570 void lttng_context_vpid_reset(void);
572 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_metadata
;
573 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_discard
;
574 extern const struct lttng_ust_lib_ring_buffer_client_cb
*lttng_client_callbacks_overwrite
;
576 struct lttng_transport
*lttng_transport_find(const char *name
);
578 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
579 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
580 struct lttng_ust_tracepoint_iter
*
581 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
582 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
583 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
584 struct lttng_ust_field_iter
*
585 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
587 void lttng_filter_event_link_bytecode(struct lttng_event
*event
);
588 void lttng_enabler_event_link_bytecode(struct lttng_event
*event
,
589 struct lttng_enabler
*enabler
);
590 void lttng_free_event_filter_runtime(struct lttng_event
*event
);
591 void lttng_filter_sync_state(struct lttng_bytecode_runtime
*runtime
);
593 struct cds_list_head
*lttng_get_probe_list_head(void);
594 int lttng_session_active(void);
596 #endif /* _LTTNG_UST_EVENTS_H */