2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
9 #ifndef _LTTNG_UST_EVENTS_H
10 #define _LTTNG_UST_EVENTS_H
12 #include <urcu/list.h>
13 #include <urcu/hlist.h>
16 #include <lttng/ust-abi.h>
17 #include <lttng/ust-tracer.h>
18 #include <lttng/ust-endian.h>
28 #define LTTNG_UST_UUID_LEN 16
31 * Tracepoint provider version. Compatibility based on the major number.
32 * Older tracepoint providers can always register to newer lttng-ust
33 * library, but the opposite is rejected: a newer tracepoint provider is
34 * rejected by an older lttng-ust library.
36 #define LTTNG_UST_PROVIDER_MAJOR 2
37 #define LTTNG_UST_PROVIDER_MINOR 0
39 struct lttng_ust_channel_buffer
;
40 struct lttng_ust_session
;
41 struct lttng_ust_lib_ring_buffer_ctx
;
42 struct lttng_ust_event_field
;
45 * Data structures used by tracepoint event declarations, and by the
49 /* Type description */
52 lttng_ust_type_integer
,
53 lttng_ust_type_string
,
55 lttng_ust_type_dynamic
,
58 lttng_ust_type_sequence
,
59 lttng_ust_type_struct
,
63 enum lttng_ust_string_encoding
{
64 lttng_ust_string_encoding_none
= 0,
65 lttng_ust_string_encoding_UTF8
= 1,
66 lttng_ust_string_encoding_ASCII
= 2,
67 NR_LTTNG_UST_STRING_ENCODING
,
70 struct lttng_ust_enum_value
{
71 unsigned long long value
;
72 unsigned int signedness
:1;
75 enum lttng_ust_enum_entry_option
{
76 LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
80 * Enumeration entry description
82 * IMPORTANT: this structure is part of the ABI between the probe and
83 * UST. Fields need to be only added at the end, never reordered, never
86 * The field @struct_size should be used to determine the size of the
87 * structure. It should be queried before using additional fields added
88 * at the end of the structure.
91 struct lttng_ust_enum_entry
{
94 struct lttng_ust_enum_value start
, end
; /* start and end are inclusive */
98 /* End of base ABI. Fields below should be used after checking struct_size. */
102 * struct lttng_ust_type_common is fixed-size. Its children inherits
103 * from it by embedding struct lttng_ust_type_common as its first field.
105 struct lttng_ust_type_common
{
106 enum lttng_ust_type type
;
109 struct lttng_ust_type_integer
{
110 struct lttng_ust_type_common parent
;
111 uint32_t struct_size
;
112 unsigned int size
; /* in bits */
113 unsigned short alignment
; /* in bits */
114 unsigned int signedness
:1;
115 unsigned int reverse_byte_order
:1;
116 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
119 #define lttng_ust_type_integer_define(_type, _byte_order, _base) \
120 ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_integer, { \
122 .type = lttng_ust_type_integer, \
124 .struct_size = sizeof(struct lttng_ust_type_integer), \
125 .size = sizeof(_type) * CHAR_BIT, \
126 .alignment = lttng_alignof(_type) * CHAR_BIT, \
127 .signedness = lttng_is_signed_type(_type), \
128 .reverse_byte_order = _byte_order != BYTE_ORDER, \
132 struct lttng_ust_type_float
{
133 struct lttng_ust_type_common parent
;
134 uint32_t struct_size
;
135 unsigned int exp_dig
; /* exponent digits, in bits */
136 unsigned int mant_dig
; /* mantissa digits, in bits */
137 unsigned short alignment
; /* in bits */
138 unsigned int reverse_byte_order
:1;
142 * Only float and double are supported. long double is not supported at
145 #define lttng_ust_float_mant_dig(_type) \
146 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
147 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
150 #define lttng_ust_type_float_define(_type) \
151 ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_float, { \
153 .type = lttng_ust_type_float, \
155 .struct_size = sizeof(struct lttng_ust_type_float), \
156 .exp_dig = sizeof(_type) * CHAR_BIT \
157 - lttng_ust_float_mant_dig(_type), \
158 .mant_dig = lttng_ust_float_mant_dig(_type), \
159 .alignment = lttng_alignof(_type) * CHAR_BIT, \
160 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
164 struct lttng_ust_type_string
{
165 struct lttng_ust_type_common parent
;
166 uint32_t struct_size
;
167 enum lttng_ust_string_encoding encoding
;
170 struct lttng_ust_type_enum
{
171 struct lttng_ust_type_common parent
;
172 uint32_t struct_size
;
173 struct lttng_ust_enum_desc
*desc
; /* Enumeration mapping */
174 struct lttng_ust_type_common
*container_type
;
177 struct lttng_ust_type_array
{
178 struct lttng_ust_type_common parent
;
179 uint32_t struct_size
;
180 struct lttng_ust_type_common
*elem_type
;
181 unsigned int length
; /* Num. elems. */
182 unsigned int alignment
;
183 enum lttng_ust_string_encoding encoding
;
186 struct lttng_ust_type_sequence
{
187 struct lttng_ust_type_common parent
;
188 uint32_t struct_size
;
189 const char *length_name
; /* Length field name. */
190 struct lttng_ust_type_common
*elem_type
;
191 unsigned int alignment
; /* Alignment before elements. */
192 enum lttng_ust_string_encoding encoding
;
195 struct lttng_ust_type_struct
{
196 struct lttng_ust_type_common parent
;
197 uint32_t struct_size
;
198 unsigned int nr_fields
;
199 struct lttng_ust_event_field
**fields
; /* Array of pointers to fields. */
200 unsigned int alignment
;
204 * Enumeration description
206 * IMPORTANT: this structure is part of the ABI between the probe and
207 * UST. Fields need to be only added at the end, never reordered, never
210 * The field @struct_size should be used to determine the size of the
211 * structure. It should be queried before using additional fields added
212 * at the end of the structure.
215 struct lttng_ust_enum_desc
{
216 uint32_t struct_size
;
219 struct lttng_ust_enum_entry
**entries
;
220 unsigned int nr_entries
;
222 /* End of base ABI. Fields below should be used after checking struct_size. */
226 * Event field description
228 * IMPORTANT: this structure is part of the ABI between the probe and
229 * UST. Fields need to be only added at the end, never reordered, never
232 * The field @struct_size should be used to determine the size of the
233 * structure. It should be queried before using additional fields added
234 * at the end of the structure.
237 struct lttng_ust_event_field
{
238 uint32_t struct_size
;
241 struct lttng_ust_type_common
*type
;
242 unsigned int nowrite
:1, /* do not write into trace */
243 nofilter
:1; /* do not consider for filter */
245 /* End of base ABI. Fields below should be used after checking struct_size. */
250 * IMPORTANT: this structure is part of the ABI between the probe and
251 * UST. Fields need to be only added at the end, never reordered, never
254 * The field @struct_size should be used to determine the size of the
255 * structure. It should be queried before using additional fields added
256 * at the end of the structure.
258 struct lttng_ust_event_desc
{
259 uint32_t struct_size
; /* Size of this structure. */
262 void (*probe_callback
)(void);
263 struct lttng_event_ctx
*ctx
; /* context */
264 struct lttng_ust_event_field
**fields
; /* event payload */
265 unsigned int nr_fields
;
266 const int **loglevel
;
267 const char *signature
; /* Argument types/names received */
268 const char **model_emf_uri
;
270 /* End of base ABI. Fields below should be used after checking struct_size. */
274 * IMPORTANT: this structure is part of the ABI between the probe and
275 * UST. Fields need to be only added at the end, never reordered, never
278 * The field @struct_size should be used to determine the size of the
279 * structure. It should be queried before using additional fields added
280 * at the end of the structure.
282 struct lttng_ust_probe_desc
{
283 uint32_t struct_size
; /* Size of this structure. */
285 const char *provider
;
286 struct lttng_ust_event_desc
**event_desc
;
287 unsigned int nr_events
;
288 struct cds_list_head head
; /* chain registered probes */
289 struct cds_list_head lazy_init_head
;
290 int lazy
; /* lazy registration */
294 /* End of base ABI. Fields below should be used after checking struct_size. */
297 /* Data structures used by the tracer. */
300 * Bytecode interpreter return value masks.
302 enum lttng_ust_bytecode_interpreter_ret
{
303 LTTNG_UST_BYTECODE_INTERPRETER_DISCARD
= 0,
304 LTTNG_UST_BYTECODE_INTERPRETER_RECORD_FLAG
= (1ULL << 0),
305 /* Other bits are kept for future use. */
308 struct lttng_interpreter_output
;
309 struct lttng_ust_bytecode_runtime_private
;
312 * IMPORTANT: this structure is part of the ABI between the probe and
313 * UST. Fields need to be only added at the end, never reordered, never
316 * The field @struct_size should be used to determine the size of the
317 * structure. It should be queried before using additional fields added
318 * at the end of the structure.
320 struct lttng_ust_bytecode_runtime
{
321 uint32_t struct_size
; /* Size of this structure. */
323 struct lttng_ust_bytecode_runtime_private
*priv
;
324 /* Associated bytecode */
326 uint64_t (*filter
)(void *interpreter_data
,
327 const char *interpreter_stack_data
);
328 uint64_t (*capture
)(void *interpreter_data
,
329 const char *interpreter_stack_data
,
330 struct lttng_interpreter_output
*interpreter_output
);
332 struct cds_list_head node
; /* list of bytecode runtime in event */
334 /* End of base ABI. Fields below should be used after checking struct_size. */
338 * lttng_event structure is referred to by the tracing fast path. It
339 * must be kept small.
341 * IMPORTANT: this structure is part of the ABI between the probe and
342 * UST. Fields need to be only added at the end, never reordered, never
346 struct lttng_ust_ctx
;
347 struct lttng_ust_event_common_private
;
349 enum lttng_ust_event_type
{
350 LTTNG_UST_EVENT_TYPE_RECORDER
= 0,
351 LTTNG_UST_EVENT_TYPE_NOTIFIER
= 1,
355 * IMPORTANT: this structure is part of the ABI between the probe and
356 * UST. Fields need to be only added at the end, never reordered, never
359 * struct lttng_ust_event_common is the common ancestor of the various
360 * public event actions. Inheritance is done by composition: The parent
361 * has a pointer to its child, and the child has a pointer to its
362 * parent. Inheritance of those public structures is done by composition
363 * to ensure both parent and child structures can be extended.
365 * The field @struct_size should be used to determine the size of the
366 * structure. It should be queried before using additional fields added
367 * at the end of the structure.
369 struct lttng_ust_event_common
{
370 uint32_t struct_size
; /* Size of this structure. */
372 struct lttng_ust_event_common_private
*priv
; /* Private event interface */
374 enum lttng_ust_event_type type
;
375 void *child
; /* Pointer to child, for inheritance by aggregation. */
378 int has_enablers_without_bytecode
;
379 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
380 struct cds_list_head filter_bytecode_runtime_head
;
382 /* End of base ABI. Fields below should be used after checking struct_size. */
385 struct lttng_ust_event_recorder_private
;
388 * IMPORTANT: this structure is part of the ABI between the probe and
389 * UST. Fields need to be only added at the end, never reordered, never
392 * struct lttng_ust_event_recorder is the action for recording events
393 * into a ring buffer. It inherits from struct lttng_ust_event_common
394 * by composition to ensure both parent and child structure are
397 * The field @struct_size should be used to determine the size of the
398 * structure. It should be queried before using additional fields added
399 * at the end of the structure.
401 struct lttng_ust_event_recorder
{
402 uint32_t struct_size
; /* Size of this structure. */
404 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
405 struct lttng_ust_event_recorder_private
*priv
; /* Private event record interface */
408 struct lttng_ust_channel_buffer
*chan
;
409 struct lttng_ust_ctx
*ctx
;
411 /* End of base ABI. Fields below should be used after checking struct_size. */
414 struct lttng_ust_event_notifier_private
;
417 * IMPORTANT: this structure is part of the ABI between the probe and
418 * UST. Fields need to be only added at the end, never reordered, never
421 * struct lttng_ust_event_notifier is the action for sending
422 * notifications. It inherits from struct lttng_ust_event_common
423 * by composition to ensure both parent and child structure are
426 * The field @struct_size should be used to determine the size of the
427 * structure. It should be queried before using additional fields added
428 * at the end of the structure.
430 struct lttng_ust_event_notifier
{
431 uint32_t struct_size
; /* Size of this structure. */
433 struct lttng_ust_event_common
*parent
; /* Inheritance by aggregation. */
434 struct lttng_ust_event_notifier_private
*priv
; /* Private event notifier interface */
436 void (*notification_send
)(struct lttng_ust_event_notifier
*event_notifier
,
437 const char *stack_data
);
438 struct cds_list_head capture_bytecode_runtime_head
;
440 /* End of base ABI. Fields below should be used after checking struct_size. */
443 struct lttng_ust_lib_ring_buffer_channel
;
444 struct lttng_ust_channel_ops_private
;
447 * IMPORTANT: this structure is part of the ABI between the probe and
448 * UST. Fields need to be only added at the end, never reordered, never
451 * The field @struct_size should be used to determine the size of the
452 * structure. It should be queried before using additional fields added
453 * at the end of the structure.
455 struct lttng_ust_channel_ops
{
456 uint32_t struct_size
;
458 struct lttng_ust_channel_ops_private
*priv
; /* Private channel ops interface */
460 int (*event_reserve
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
462 void (*event_commit
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
);
463 void (*event_write
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
464 const void *src
, size_t len
);
465 void (*event_strcpy
)(struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
466 const char *src
, size_t len
);
468 /* End of base ABI. Fields below should be used after checking struct_size. */
471 enum lttng_ust_channel_type
{
472 LTTNG_UST_CHANNEL_TYPE_BUFFER
= 0,
475 struct lttng_ust_channel_common_private
;
478 * IMPORTANT: this structure is part of the ABI between the probe and
479 * UST. Fields need to be only added at the end, never reordered, never
482 * The field @struct_size should be used to determine the size of the
483 * structure. It should be queried before using additional fields added
484 * at the end of the structure.
486 struct lttng_ust_channel_common
{
487 uint32_t struct_size
; /* Size of this structure. */
489 struct lttng_ust_channel_common_private
*priv
; /* Private channel interface */
491 enum lttng_ust_channel_type type
;
492 void *child
; /* Pointer to child, for inheritance by aggregation. */
495 struct lttng_ust_session
*session
;
497 /* End of base ABI. Fields below should be used after checking struct_size. */
500 struct lttng_ust_channel_buffer_private
;
503 * IMPORTANT: this structure is part of the ABI between the probe and
504 * UST. Fields need to be only added at the end, never reordered, never
507 * The field @struct_size should be used to determine the size of the
508 * structure. It should be queried before using additional fields added
509 * at the end of the structure.
511 struct lttng_ust_channel_buffer
{
512 uint32_t struct_size
; /* Size of this structure. */
514 struct lttng_ust_channel_common
*parent
; /* Inheritance by aggregation. */
515 struct lttng_ust_channel_buffer_private
*priv
; /* Private channel buffer interface */
517 struct lttng_ust_channel_ops
*ops
;
518 struct lttng_ust_lib_ring_buffer_channel
*chan
; /* Channel buffers */
519 struct lttng_ust_shm_handle
*handle
; /* shared-memory handle */
521 /* End of base ABI. Fields below should be used after checking struct_size. */
525 * IMPORTANT: this structure is part of the ABI between the probe and
526 * UST. Fields need to be only added at the end, never reordered, never
529 * The field @struct_size should be used to determine the size of the
530 * structure. It should be queried before using additional fields added
531 * at the end of the structure.
533 struct lttng_ust_stack_ctx
{
534 uint32_t struct_size
; /* Size of this structure */
536 struct lttng_ust_event_recorder
*event_recorder
;
537 struct lttng_ust_ctx
*event_ctx
; /* RCU dereferenced. */
539 /* End of base ABI. Fields below should be used after checking struct_size. */
542 struct lttng_ust_session_private
;
545 * IMPORTANT: this structure is part of the ABI between the probe and
546 * UST. Fields need to be only added at the end, never reordered, never
549 * The field @struct_size should be used to determine the size of the
550 * structure. It should be queried before using additional fields added
551 * at the end of the structure.
553 struct lttng_ust_session
{
554 uint32_t struct_size
; /* Size of this structure */
556 struct lttng_ust_session_private
*priv
; /* Private session interface */
558 int active
; /* Is trace session active ? */
560 /* End of base ABI. Fields below should be used after checking struct_size. */
563 int lttng_ust_probe_register(struct lttng_ust_probe_desc
*desc
);
564 void lttng_ust_probe_unregister(struct lttng_ust_probe_desc
*desc
);
567 * Applications that change their procname and need the new value to be
568 * reflected in the procname event context have to call this function to clear
569 * the internally cached value. This should not be called from a signal
572 void lttng_ust_context_procname_reset(void);
578 #endif /* _LTTNG_UST_EVENTS_H */