2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
5 * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #ifndef _LTTNG_UST_CTL_H
9 #define _LTTNG_UST_CTL_H
15 #include <sys/types.h>
17 #include <lttng/ust-abi.h>
19 #ifndef LTTNG_UST_UUID_LEN
20 #define LTTNG_UST_UUID_LEN 16
23 /* Default unix socket path */
24 #define LTTNG_UST_SOCK_FILENAME \
26 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
29 * Shared memory files path are automatically related to shm root, e.g.
30 * /dev/shm under linux.
32 #define LTTNG_UST_WAIT_FILENAME \
34 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
36 struct lttng_ust_shm_handle
;
37 struct lttng_ust_lib_ring_buffer
;
39 struct ustctl_consumer_channel_attr
{
40 enum lttng_ust_abi_chan_type type
;
41 uint64_t subbuf_size
; /* bytes */
42 uint64_t num_subbuf
; /* power of 2 */
43 int overwrite
; /* 1: overwrite, 0: discard */
44 unsigned int switch_timer_interval
; /* usec */
45 unsigned int read_timer_interval
; /* usec */
46 enum lttng_ust_abi_output output
; /* splice, mmap */
47 uint32_t chan_id
; /* channel ID */
48 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
49 int64_t blocking_timeout
; /* Blocking timeout (usec) */
50 } __attribute__((packed
));
53 * API used by sessiond.
56 struct lttng_ust_context_attr
{
57 enum lttng_ust_abi_context_type ctx
;
59 struct lttng_ust_abi_perf_counter_ctx perf_counter
;
68 * Error values: all the following functions return:
69 * >= 0: Success (LTTNG_UST_OK)
72 int ustctl_register_done(int sock
);
73 int ustctl_create_session(int sock
);
74 int ustctl_create_event(int sock
, struct lttng_ust_abi_event
*ev
,
75 struct lttng_ust_abi_object_data
*channel_data
,
76 struct lttng_ust_abi_object_data
**event_data
);
77 int ustctl_add_context(int sock
, struct lttng_ust_context_attr
*ctx
,
78 struct lttng_ust_abi_object_data
*obj_data
,
79 struct lttng_ust_abi_object_data
**context_data
);
80 int ustctl_set_filter(int sock
, struct lttng_ust_abi_filter_bytecode
*bytecode
,
81 struct lttng_ust_abi_object_data
*obj_data
);
82 int ustctl_set_capture(int sock
, struct lttng_ust_abi_capture_bytecode
*bytecode
,
83 struct lttng_ust_abi_object_data
*obj_data
);
84 int ustctl_set_exclusion(int sock
, struct lttng_ust_abi_event_exclusion
*exclusion
,
85 struct lttng_ust_abi_object_data
*obj_data
);
87 int ustctl_enable(int sock
, struct lttng_ust_abi_object_data
*object
);
88 int ustctl_disable(int sock
, struct lttng_ust_abi_object_data
*object
);
89 int ustctl_start_session(int sock
, int handle
);
90 int ustctl_stop_session(int sock
, int handle
);
93 * ustctl_create_event notifier_group creates a event notifier group. It
94 * establishes the connection with the application by providing a file
95 * descriptor of the pipe to be used by the application when a event notifier
96 * of that group is fired. It returns a handle to be used when creating event
97 * notifier in that group.
99 int ustctl_create_event_notifier_group(int sock
, int pipe_fd
,
100 struct lttng_ust_abi_object_data
**event_notifier_group
);
103 * ustctl_create_event notifier creates a event notifier in a event notifier
104 * group giving a event notifier description and a event notifier group handle.
105 * It returns a event notifier handle to be used when enabling the event
106 * notifier, attaching filter, attaching exclusion, and disabling the event
109 int ustctl_create_event_notifier(int sock
,
110 struct lttng_ust_abi_event_notifier
*event_notifier
,
111 struct lttng_ust_abi_object_data
*event_notifier_group
,
112 struct lttng_ust_abi_object_data
**event_notifier_data
);
115 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
118 int ustctl_tracepoint_list(int sock
);
121 * ustctl_tracepoint_list_get is used to iterate on the tp list
122 * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
125 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
126 struct lttng_ust_abi_tracepoint_iter
*iter
);
129 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
130 * or negative error value.
132 int ustctl_tracepoint_field_list(int sock
);
135 * ustctl_tracepoint_field_list_get is used to iterate on the tp field
136 * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
139 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
140 struct lttng_ust_abi_field_iter
*iter
);
142 int ustctl_tracer_version(int sock
, struct lttng_ust_abi_tracer_version
*v
);
143 int ustctl_wait_quiescent(int sock
);
145 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_abi_object_data
*object
);
147 int ustctl_calibrate(int sock
, struct lttng_ust_abi_calibrate
*calibrate
);
149 /* Release object created by members of this API. */
150 int ustctl_release_object(int sock
, struct lttng_ust_abi_object_data
*data
);
151 /* Release handle returned by create session. */
152 int ustctl_release_handle(int sock
, int handle
);
154 int ustctl_recv_channel_from_consumer(int sock
,
155 struct lttng_ust_abi_object_data
**channel_data
);
156 int ustctl_recv_stream_from_consumer(int sock
,
157 struct lttng_ust_abi_object_data
**stream_data
);
158 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
159 struct lttng_ust_abi_object_data
*channel_data
);
160 int ustctl_send_stream_to_ust(int sock
,
161 struct lttng_ust_abi_object_data
*channel_data
,
162 struct lttng_ust_abi_object_data
*stream_data
);
165 * ustctl_duplicate_ust_object_data allocated a new object in "dest" if
166 * it succeeds (returns 0). It must be released using
167 * ustctl_release_object() and then freed with free().
169 int ustctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data
**dest
,
170 struct lttng_ust_abi_object_data
*src
);
173 * API used by consumer.
176 struct ustctl_consumer_channel
;
177 struct ustctl_consumer_stream
;
178 struct ustctl_consumer_channel_attr
;
180 int ustctl_get_nr_stream_per_channel(void);
182 struct ustctl_consumer_channel
*
183 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
,
184 const int *stream_fds
, int nr_stream_fds
);
186 * Each stream created needs to be destroyed before calling
187 * ustctl_destroy_channel().
189 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
);
191 int ustctl_send_channel_to_sessiond(int sock
,
192 struct ustctl_consumer_channel
*channel
);
193 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
194 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
195 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
196 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
198 int ustctl_write_metadata_to_channel(
199 struct ustctl_consumer_channel
*channel
,
200 const char *metadata_str
, /* NOT null-terminated */
201 size_t len
); /* metadata length */
202 ssize_t
ustctl_write_one_packet_to_channel(
203 struct ustctl_consumer_channel
*channel
,
204 const char *metadata_str
, /* NOT null-terminated */
205 size_t len
); /* metadata length */
208 * Send a NULL stream to finish iteration over all streams of a given
211 int ustctl_send_stream_to_sessiond(int sock
,
212 struct ustctl_consumer_stream
*stream
);
213 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
);
214 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
);
215 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
);
216 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
);
218 /* Create/destroy stream buffers for read */
219 struct ustctl_consumer_stream
*
220 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
222 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
);
224 /* For mmap mode, readable without "get" operation */
225 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
227 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
231 * For mmap mode, operate on the current packet (between get/put or
232 * get_next/put_next).
234 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
);
235 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
237 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
239 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
241 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
);
242 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
);
246 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
);
247 int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream
*stream
);
248 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
250 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
252 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
254 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
);
256 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
257 int producer_active
);
258 void ustctl_clear_buffer(struct ustctl_consumer_stream
*stream
);
263 * Getters which need to be used on the current packet (between get/put
264 * or get_next/put_next.
267 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
268 uint64_t *timestamp_begin
);
269 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
270 uint64_t *timestamp_end
);
271 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
272 uint64_t *events_discarded
);
273 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
274 uint64_t *content_size
);
275 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
276 uint64_t *packet_size
);
277 int ustctl_get_sequence_number(struct ustctl_consumer_stream
*stream
,
281 * Getter returning state invariant for the stream, which can be used
282 * without "get" operation.
285 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
286 uint64_t *stream_id
);
287 int ustctl_get_instance_id(struct ustctl_consumer_stream
*stream
,
291 * Getter returning the current timestamp as perceived from the
294 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
297 /* returns whether UST has perf counters support. */
298 int ustctl_has_perf_counters(void);
300 /* Regenerate the statedump. */
301 int ustctl_regenerate_statedump(int sock
, int handle
);
303 /* event registry management */
305 enum ustctl_socket_type
{
306 USTCTL_SOCKET_CMD
= 0,
307 USTCTL_SOCKET_NOTIFY
= 1,
310 enum ustctl_notify_cmd
{
311 USTCTL_NOTIFY_CMD_EVENT
= 0,
312 USTCTL_NOTIFY_CMD_CHANNEL
= 1,
313 USTCTL_NOTIFY_CMD_ENUM
= 2,
316 enum ustctl_channel_header
{
317 USTCTL_CHANNEL_HEADER_UNKNOWN
= 0,
318 USTCTL_CHANNEL_HEADER_COMPACT
= 1,
319 USTCTL_CHANNEL_HEADER_LARGE
= 2,
322 /* event type structures */
324 enum ustctl_abstract_types
{
325 ustctl_atype_integer
,
326 ustctl_atype_enum
, /* legacy */
327 ustctl_atype_array
, /* legacy */
328 ustctl_atype_sequence
, /* legacy */
331 ustctl_atype_variant
, /* legacy */
332 ustctl_atype_struct
, /* legacy */
333 ustctl_atype_enum_nestable
,
334 ustctl_atype_array_nestable
,
335 ustctl_atype_sequence_nestable
,
336 ustctl_atype_struct_nestable
,
337 ustctl_atype_variant_nestable
,
338 NR_USTCTL_ABSTRACT_TYPES
,
341 enum ustctl_string_encodings
{
342 ustctl_encode_none
= 0,
343 ustctl_encode_UTF8
= 1,
344 ustctl_encode_ASCII
= 2,
345 NR_USTCTL_STRING_ENCODINGS
,
348 #define USTCTL_UST_INTEGER_TYPE_PADDING 24
349 struct ustctl_integer_type
{
350 uint32_t size
; /* in bits */
352 uint32_t reverse_byte_order
;
353 uint32_t base
; /* 2, 8, 10, 16, for pretty print */
354 int32_t encoding
; /* enum ustctl_string_encodings */
355 uint16_t alignment
; /* in bits */
356 char padding
[USTCTL_UST_INTEGER_TYPE_PADDING
];
357 } __attribute__((packed
));
359 #define USTCTL_UST_FLOAT_TYPE_PADDING 24
360 struct ustctl_float_type
{
361 uint32_t exp_dig
; /* exponent digits, in bits */
362 uint32_t mant_dig
; /* mantissa digits, in bits */
363 uint32_t reverse_byte_order
;
364 uint16_t alignment
; /* in bits */
365 char padding
[USTCTL_UST_FLOAT_TYPE_PADDING
];
366 } __attribute__((packed
));
368 #define USTCTL_UST_ENUM_VALUE_PADDING 15
369 struct ustctl_enum_value
{
372 char padding
[USTCTL_UST_ENUM_VALUE_PADDING
];
373 } __attribute__((packed
));
375 enum ustctl_ust_enum_entry_options
{
376 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
379 #define USTCTL_UST_ENUM_ENTRY_PADDING 32
380 struct ustctl_enum_entry
{
381 struct ustctl_enum_value start
, end
; /* start and end are inclusive */
382 char string
[LTTNG_UST_ABI_SYM_NAME_LEN
];
386 } __attribute__((packed
)) extra
;
387 char padding
[USTCTL_UST_ENUM_ENTRY_PADDING
];
389 } __attribute__((packed
));
392 #define USTCTL_UST_BASIC_TYPE_PADDING 296
393 union _ustctl_basic_type
{
394 struct ustctl_integer_type integer
;
396 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
397 struct ustctl_integer_type container_type
;
398 uint64_t id
; /* enum ID in sessiond. */
401 int32_t encoding
; /* enum ustctl_string_encodings */
403 struct ustctl_float_type _float
;
404 char padding
[USTCTL_UST_BASIC_TYPE_PADDING
];
405 } __attribute__((packed
));
408 struct ustctl_basic_type
{
409 enum ustctl_abstract_types atype
;
411 union _ustctl_basic_type basic
;
413 } __attribute__((packed
));
416 * Padding is derived from largest member: u.legacy.sequence which
417 * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING.
419 #define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING)
421 enum ustctl_abstract_types atype
;
423 struct ustctl_integer_type integer
;
424 struct ustctl_float_type _float
;
426 int32_t encoding
; /* enum ustctl_string_encodings */
429 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
430 uint64_t id
; /* enum ID in sessiond. */
431 /* container_type follows after this struct ustctl_field. */
434 uint32_t length
; /* num. elems. */
436 /* elem_type follows after this struct ustctl_field. */
439 char length_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
440 uint32_t alignment
; /* Alignment before elements. */
441 /* elem_type follows after the length_type. */
446 /* Followed by nr_fields struct ustctl_field. */
450 char tag_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
452 /* Followed by nr_choices struct ustctl_field. */
457 union _ustctl_basic_type basic
;
459 struct ustctl_basic_type elem_type
;
460 uint32_t length
; /* num. elems. */
463 struct ustctl_basic_type length_type
;
464 struct ustctl_basic_type elem_type
;
468 /* Followed by nr_fields struct ustctl_field. */
472 char tag_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
473 /* Followed by nr_choices struct ustctl_field. */
476 char padding
[USTCTL_UST_TYPE_PADDING
];
478 } __attribute__((packed
));
480 #define USTCTL_UST_FIELD_PADDING 28
481 struct ustctl_field
{
482 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
483 struct ustctl_type type
;
484 char padding
[USTCTL_UST_FIELD_PADDING
];
485 } __attribute__((packed
));
488 * Returns 0 on success, negative error value on error.
489 * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned,
490 * the output fields are not populated.
492 int ustctl_recv_reg_msg(int sock
,
493 enum ustctl_socket_type
*type
,
500 uint32_t *bits_per_long
,
501 uint32_t *uint8_t_alignment
,
502 uint32_t *uint16_t_alignment
,
503 uint32_t *uint32_t_alignment
,
504 uint32_t *uint64_t_alignment
,
505 uint32_t *long_alignment
,
507 char *name
); /* size LTTNG_UST_ABI_PROCNAME_LEN */
510 * Returns 0 on success, negative UST or system error value on error.
511 * Receive the notification command. The "notify_cmd" can then be used
512 * by the caller to find out which ustctl_recv_* function should be
513 * called to receive the notification, and which ustctl_reply_* is
516 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
);
519 * Returns 0 on success, negative UST or system error value on error.
521 int ustctl_recv_register_event(int sock
,
522 int *session_objd
, /* session descriptor (output) */
523 int *channel_objd
, /* channel descriptor (output) */
525 * event name (output,
526 * size LTTNG_UST_ABI_SYM_NAME_LEN)
531 * (output, dynamically
532 * allocated, must be free(3)'d
533 * by the caller if function
537 struct ustctl_field
**fields
,
538 char **model_emf_uri
);
541 * Returns 0 on success, negative error value on error.
543 int ustctl_reply_register_event(int sock
,
544 uint32_t id
, /* event id (input) */
545 int ret_code
); /* return code. 0 ok, negative error */
548 * Returns 0 on success, negative UST or system error value on error.
550 int ustctl_recv_register_enum(int sock
,
553 struct ustctl_enum_entry
**entries
,
557 * Returns 0 on success, negative error value on error.
559 int ustctl_reply_register_enum(int sock
,
560 uint64_t id
, /* enum id (input) */
564 * Returns 0 on success, negative UST or system error value on error.
566 int ustctl_recv_register_channel(int sock
,
567 int *session_objd
, /* session descriptor (output) */
568 int *channel_objd
, /* channel descriptor (output) */
569 size_t *nr_fields
, /* context fields */
570 struct ustctl_field
**fields
);
573 * Returns 0 on success, negative error value on error.
575 int ustctl_reply_register_channel(int sock
,
577 enum ustctl_channel_header header_type
,
578 int ret_code
); /* return code. 0 ok, negative error */
584 enum ustctl_counter_bitness
{
585 USTCTL_COUNTER_BITNESS_32
= 0,
586 USTCTL_COUNTER_BITNESS_64
= 1,
589 enum ustctl_counter_arithmetic
{
590 USTCTL_COUNTER_ARITHMETIC_MODULAR
= 0,
591 USTCTL_COUNTER_ARITHMETIC_SATURATION
= 1,
594 /* Used as alloc flags. */
595 enum ustctl_counter_alloc
{
596 USTCTL_COUNTER_ALLOC_PER_CPU
= (1 << 0),
597 USTCTL_COUNTER_ALLOC_GLOBAL
= (1 << 1),
600 struct ustctl_daemon_counter
;
602 int ustctl_get_nr_cpu_per_counter(void);
604 struct ustctl_counter_dimension
{
606 uint64_t underflow_index
;
607 uint64_t overflow_index
;
608 uint8_t has_underflow
;
609 uint8_t has_overflow
;
612 struct ustctl_daemon_counter
*
613 ustctl_create_counter(size_t nr_dimensions
,
614 const struct ustctl_counter_dimension
*dimensions
,
615 int64_t global_sum_step
,
616 int global_counter_fd
,
617 int nr_counter_cpu_fds
,
618 const int *counter_cpu_fds
,
619 enum ustctl_counter_bitness bitness
,
620 enum ustctl_counter_arithmetic arithmetic
,
621 uint32_t alloc_flags
,
624 int ustctl_create_counter_data(struct ustctl_daemon_counter
*counter
,
625 struct lttng_ust_abi_object_data
**counter_data
);
627 int ustctl_create_counter_global_data(struct ustctl_daemon_counter
*counter
,
628 struct lttng_ust_abi_object_data
**counter_global_data
);
629 int ustctl_create_counter_cpu_data(struct ustctl_daemon_counter
*counter
, int cpu
,
630 struct lttng_ust_abi_object_data
**counter_cpu_data
);
633 * Each counter data and counter cpu data created need to be destroyed
634 * before calling ustctl_destroy_counter().
636 void ustctl_destroy_counter(struct ustctl_daemon_counter
*counter
);
638 int ustctl_send_counter_data_to_ust(int sock
, int parent_handle
,
639 struct lttng_ust_abi_object_data
*counter_data
);
640 int ustctl_send_counter_global_data_to_ust(int sock
,
641 struct lttng_ust_abi_object_data
*counter_data
,
642 struct lttng_ust_abi_object_data
*counter_global_data
);
643 int ustctl_send_counter_cpu_data_to_ust(int sock
,
644 struct lttng_ust_abi_object_data
*counter_data
,
645 struct lttng_ust_abi_object_data
*counter_cpu_data
);
647 int ustctl_counter_read(struct ustctl_daemon_counter
*counter
,
648 const size_t *dimension_indexes
,
649 int cpu
, int64_t *value
,
650 bool *overflow
, bool *underflow
);
651 int ustctl_counter_aggregate(struct ustctl_daemon_counter
*counter
,
652 const size_t *dimension_indexes
,
654 bool *overflow
, bool *underflow
);
655 int ustctl_counter_clear(struct ustctl_daemon_counter
*counter
,
656 const size_t *dimension_indexes
);
658 #endif /* _LTTNG_UST_CTL_H */