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_lib_ring_buffer
;
38 struct ustctl_consumer_channel_attr
{
39 enum lttng_ust_abi_chan_type type
;
40 uint64_t subbuf_size
; /* bytes */
41 uint64_t num_subbuf
; /* power of 2 */
42 int overwrite
; /* 1: overwrite, 0: discard */
43 unsigned int switch_timer_interval
; /* usec */
44 unsigned int read_timer_interval
; /* usec */
45 enum lttng_ust_abi_output output
; /* splice, mmap */
46 uint32_t chan_id
; /* channel ID */
47 unsigned char uuid
[LTTNG_UST_UUID_LEN
]; /* Trace session unique ID */
48 int64_t blocking_timeout
; /* Blocking timeout (usec) */
49 } __attribute__((packed
));
52 * API used by sessiond.
55 struct lttng_ust_context_attr
{
56 enum lttng_ust_abi_context_type ctx
;
58 struct lttng_ust_abi_perf_counter_ctx perf_counter
;
67 * Error values: all the following functions return:
68 * >= 0: Success (LTTNG_UST_OK)
71 int ustctl_register_done(int sock
);
72 int ustctl_create_session(int sock
);
73 int ustctl_create_event(int sock
, struct lttng_ust_abi_event
*ev
,
74 struct lttng_ust_abi_object_data
*channel_data
,
75 struct lttng_ust_abi_object_data
**event_data
);
76 int ustctl_add_context(int sock
, struct lttng_ust_context_attr
*ctx
,
77 struct lttng_ust_abi_object_data
*obj_data
,
78 struct lttng_ust_abi_object_data
**context_data
);
79 int ustctl_set_filter(int sock
, struct lttng_ust_abi_filter_bytecode
*bytecode
,
80 struct lttng_ust_abi_object_data
*obj_data
);
81 int ustctl_set_capture(int sock
, struct lttng_ust_abi_capture_bytecode
*bytecode
,
82 struct lttng_ust_abi_object_data
*obj_data
);
83 int ustctl_set_exclusion(int sock
, struct lttng_ust_abi_event_exclusion
*exclusion
,
84 struct lttng_ust_abi_object_data
*obj_data
);
86 int ustctl_enable(int sock
, struct lttng_ust_abi_object_data
*object
);
87 int ustctl_disable(int sock
, struct lttng_ust_abi_object_data
*object
);
88 int ustctl_start_session(int sock
, int handle
);
89 int ustctl_stop_session(int sock
, int handle
);
92 * ustctl_create_event notifier_group creates a event notifier group. It
93 * establishes the connection with the application by providing a file
94 * descriptor of the pipe to be used by the application when a event notifier
95 * of that group is fired. It returns a handle to be used when creating event
96 * notifier in that group.
98 int ustctl_create_event_notifier_group(int sock
, int pipe_fd
,
99 struct lttng_ust_abi_object_data
**event_notifier_group
);
102 * ustctl_create_event notifier creates a event notifier in a event notifier
103 * group giving a event notifier description and a event notifier group handle.
104 * It returns a event notifier handle to be used when enabling the event
105 * notifier, attaching filter, attaching exclusion, and disabling the event
108 int ustctl_create_event_notifier(int sock
,
109 struct lttng_ust_abi_event_notifier
*event_notifier
,
110 struct lttng_ust_abi_object_data
*event_notifier_group
,
111 struct lttng_ust_abi_object_data
**event_notifier_data
);
114 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
117 int ustctl_tracepoint_list(int sock
);
120 * ustctl_tracepoint_list_get is used to iterate on the tp list
121 * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
124 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
125 struct lttng_ust_abi_tracepoint_iter
*iter
);
128 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
129 * or negative error value.
131 int ustctl_tracepoint_field_list(int sock
);
134 * ustctl_tracepoint_field_list_get is used to iterate on the tp field
135 * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
138 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
139 struct lttng_ust_abi_field_iter
*iter
);
141 int ustctl_tracer_version(int sock
, struct lttng_ust_abi_tracer_version
*v
);
142 int ustctl_wait_quiescent(int sock
);
144 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_abi_object_data
*object
);
146 int ustctl_calibrate(int sock
, struct lttng_ust_abi_calibrate
*calibrate
);
148 /* Release object created by members of this API. */
149 int ustctl_release_object(int sock
, struct lttng_ust_abi_object_data
*data
);
150 /* Release handle returned by create session. */
151 int ustctl_release_handle(int sock
, int handle
);
153 int ustctl_recv_channel_from_consumer(int sock
,
154 struct lttng_ust_abi_object_data
**channel_data
);
155 int ustctl_recv_stream_from_consumer(int sock
,
156 struct lttng_ust_abi_object_data
**stream_data
);
157 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
158 struct lttng_ust_abi_object_data
*channel_data
);
159 int ustctl_send_stream_to_ust(int sock
,
160 struct lttng_ust_abi_object_data
*channel_data
,
161 struct lttng_ust_abi_object_data
*stream_data
);
164 * ustctl_duplicate_ust_object_data allocated a new object in "dest" if
165 * it succeeds (returns 0). It must be released using
166 * ustctl_release_object() and then freed with free().
168 int ustctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data
**dest
,
169 struct lttng_ust_abi_object_data
*src
);
172 * API used by consumer.
175 struct ustctl_consumer_channel
;
176 struct ustctl_consumer_stream
;
177 struct ustctl_consumer_channel_attr
;
179 int ustctl_get_nr_stream_per_channel(void);
181 struct ustctl_consumer_channel
*
182 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
,
183 const int *stream_fds
, int nr_stream_fds
);
185 * Each stream created needs to be destroyed before calling
186 * ustctl_destroy_channel().
188 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
);
190 int ustctl_send_channel_to_sessiond(int sock
,
191 struct ustctl_consumer_channel
*channel
);
192 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
193 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
194 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
195 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
197 int ustctl_write_metadata_to_channel(
198 struct ustctl_consumer_channel
*channel
,
199 const char *metadata_str
, /* NOT null-terminated */
200 size_t len
); /* metadata length */
201 ssize_t
ustctl_write_one_packet_to_channel(
202 struct ustctl_consumer_channel
*channel
,
203 const char *metadata_str
, /* NOT null-terminated */
204 size_t len
); /* metadata length */
207 * Send a NULL stream to finish iteration over all streams of a given
210 int ustctl_send_stream_to_sessiond(int sock
,
211 struct ustctl_consumer_stream
*stream
);
212 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
);
213 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
);
214 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
);
215 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
);
217 /* Create/destroy stream buffers for read */
218 struct ustctl_consumer_stream
*
219 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
221 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
);
223 /* For mmap mode, readable without "get" operation */
224 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
226 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
230 * For mmap mode, operate on the current packet (between get/put or
231 * get_next/put_next).
233 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
);
234 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
236 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
238 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
240 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
);
241 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
);
245 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
);
246 int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream
*stream
);
247 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
249 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
251 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
253 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
);
255 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
256 int producer_active
);
257 void ustctl_clear_buffer(struct ustctl_consumer_stream
*stream
);
262 * Getters which need to be used on the current packet (between get/put
263 * or get_next/put_next.
266 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
267 uint64_t *timestamp_begin
);
268 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
269 uint64_t *timestamp_end
);
270 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
271 uint64_t *events_discarded
);
272 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
273 uint64_t *content_size
);
274 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
275 uint64_t *packet_size
);
276 int ustctl_get_sequence_number(struct ustctl_consumer_stream
*stream
,
280 * Getter returning state invariant for the stream, which can be used
281 * without "get" operation.
284 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
285 uint64_t *stream_id
);
286 int ustctl_get_instance_id(struct ustctl_consumer_stream
*stream
,
290 * Getter returning the current timestamp as perceived from the
293 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
296 /* returns whether UST has perf counters support. */
297 int ustctl_has_perf_counters(void);
299 /* Regenerate the statedump. */
300 int ustctl_regenerate_statedump(int sock
, int handle
);
302 /* event registry management */
304 enum ustctl_socket_type
{
305 USTCTL_SOCKET_CMD
= 0,
306 USTCTL_SOCKET_NOTIFY
= 1,
309 enum ustctl_notify_cmd
{
310 USTCTL_NOTIFY_CMD_EVENT
= 0,
311 USTCTL_NOTIFY_CMD_CHANNEL
= 1,
312 USTCTL_NOTIFY_CMD_ENUM
= 2,
315 enum ustctl_channel_header
{
316 USTCTL_CHANNEL_HEADER_UNKNOWN
= 0,
317 USTCTL_CHANNEL_HEADER_COMPACT
= 1,
318 USTCTL_CHANNEL_HEADER_LARGE
= 2,
321 /* event type structures */
323 enum ustctl_abstract_types
{
324 ustctl_atype_integer
,
325 ustctl_atype_enum
, /* legacy */
326 ustctl_atype_array
, /* legacy */
327 ustctl_atype_sequence
, /* legacy */
330 ustctl_atype_variant
, /* legacy */
331 ustctl_atype_struct
, /* legacy */
332 ustctl_atype_enum_nestable
,
333 ustctl_atype_array_nestable
,
334 ustctl_atype_sequence_nestable
,
335 ustctl_atype_struct_nestable
,
336 ustctl_atype_variant_nestable
,
337 NR_USTCTL_ABSTRACT_TYPES
,
340 enum ustctl_string_encodings
{
341 ustctl_encode_none
= 0,
342 ustctl_encode_UTF8
= 1,
343 ustctl_encode_ASCII
= 2,
344 NR_USTCTL_STRING_ENCODINGS
,
347 #define USTCTL_UST_INTEGER_TYPE_PADDING 24
348 struct ustctl_integer_type
{
349 uint32_t size
; /* in bits */
351 uint32_t reverse_byte_order
;
352 uint32_t base
; /* 2, 8, 10, 16, for pretty print */
353 int32_t encoding
; /* enum ustctl_string_encodings */
354 uint16_t alignment
; /* in bits */
355 char padding
[USTCTL_UST_INTEGER_TYPE_PADDING
];
356 } __attribute__((packed
));
358 #define USTCTL_UST_FLOAT_TYPE_PADDING 24
359 struct ustctl_float_type
{
360 uint32_t exp_dig
; /* exponent digits, in bits */
361 uint32_t mant_dig
; /* mantissa digits, in bits */
362 uint32_t reverse_byte_order
;
363 uint16_t alignment
; /* in bits */
364 char padding
[USTCTL_UST_FLOAT_TYPE_PADDING
];
365 } __attribute__((packed
));
367 #define USTCTL_UST_ENUM_VALUE_PADDING 15
368 struct ustctl_enum_value
{
371 char padding
[USTCTL_UST_ENUM_VALUE_PADDING
];
372 } __attribute__((packed
));
374 enum ustctl_ust_enum_entry_options
{
375 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
378 #define USTCTL_UST_ENUM_ENTRY_PADDING 32
379 struct ustctl_enum_entry
{
380 struct ustctl_enum_value start
, end
; /* start and end are inclusive */
381 char string
[LTTNG_UST_ABI_SYM_NAME_LEN
];
385 } __attribute__((packed
)) extra
;
386 char padding
[USTCTL_UST_ENUM_ENTRY_PADDING
];
388 } __attribute__((packed
));
391 #define USTCTL_UST_BASIC_TYPE_PADDING 296
392 union _ustctl_basic_type
{
393 struct ustctl_integer_type integer
;
395 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
396 struct ustctl_integer_type container_type
;
397 uint64_t id
; /* enum ID in sessiond. */
400 int32_t encoding
; /* enum ustctl_string_encodings */
402 struct ustctl_float_type _float
;
403 char padding
[USTCTL_UST_BASIC_TYPE_PADDING
];
404 } __attribute__((packed
));
407 struct ustctl_basic_type
{
408 enum ustctl_abstract_types atype
;
410 union _ustctl_basic_type basic
;
412 } __attribute__((packed
));
415 * Padding is derived from largest member: u.legacy.sequence which
416 * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING.
418 #define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING)
420 enum ustctl_abstract_types atype
;
422 struct ustctl_integer_type integer
;
423 struct ustctl_float_type _float
;
425 int32_t encoding
; /* enum ustctl_string_encodings */
428 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
429 uint64_t id
; /* enum ID in sessiond. */
430 /* container_type follows after this struct ustctl_field. */
433 uint32_t length
; /* num. elems. */
435 /* elem_type follows after this struct ustctl_field. */
438 char length_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
439 uint32_t alignment
; /* Alignment before elements. */
440 /* elem_type follows after the length_type. */
445 /* Followed by nr_fields struct ustctl_field. */
449 char tag_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
451 /* Followed by nr_choices struct ustctl_field. */
456 union _ustctl_basic_type basic
;
458 struct ustctl_basic_type elem_type
;
459 uint32_t length
; /* num. elems. */
462 struct ustctl_basic_type length_type
;
463 struct ustctl_basic_type elem_type
;
467 /* Followed by nr_fields struct ustctl_field. */
471 char tag_name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
472 /* Followed by nr_choices struct ustctl_field. */
475 char padding
[USTCTL_UST_TYPE_PADDING
];
477 } __attribute__((packed
));
479 #define USTCTL_UST_FIELD_PADDING 28
480 struct ustctl_field
{
481 char name
[LTTNG_UST_ABI_SYM_NAME_LEN
];
482 struct ustctl_type type
;
483 char padding
[USTCTL_UST_FIELD_PADDING
];
484 } __attribute__((packed
));
487 * Returns 0 on success, negative error value on error.
488 * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned,
489 * the output fields are not populated.
491 int ustctl_recv_reg_msg(int sock
,
492 enum ustctl_socket_type
*type
,
499 uint32_t *bits_per_long
,
500 uint32_t *uint8_t_alignment
,
501 uint32_t *uint16_t_alignment
,
502 uint32_t *uint32_t_alignment
,
503 uint32_t *uint64_t_alignment
,
504 uint32_t *long_alignment
,
506 char *name
); /* size LTTNG_UST_ABI_PROCNAME_LEN */
509 * Returns 0 on success, negative UST or system error value on error.
510 * Receive the notification command. The "notify_cmd" can then be used
511 * by the caller to find out which ustctl_recv_* function should be
512 * called to receive the notification, and which ustctl_reply_* is
515 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
);
518 * Returns 0 on success, negative UST or system error value on error.
520 int ustctl_recv_register_event(int sock
,
521 int *session_objd
, /* session descriptor (output) */
522 int *channel_objd
, /* channel descriptor (output) */
524 * event name (output,
525 * size LTTNG_UST_ABI_SYM_NAME_LEN)
530 * (output, dynamically
531 * allocated, must be free(3)'d
532 * by the caller if function
536 struct ustctl_field
**fields
,
537 char **model_emf_uri
);
540 * Returns 0 on success, negative error value on error.
542 int ustctl_reply_register_event(int sock
,
543 uint32_t id
, /* event id (input) */
544 int ret_code
); /* return code. 0 ok, negative error */
547 * Returns 0 on success, negative UST or system error value on error.
549 int ustctl_recv_register_enum(int sock
,
552 struct ustctl_enum_entry
**entries
,
556 * Returns 0 on success, negative error value on error.
558 int ustctl_reply_register_enum(int sock
,
559 uint64_t id
, /* enum id (input) */
563 * Returns 0 on success, negative UST or system error value on error.
565 int ustctl_recv_register_channel(int sock
,
566 int *session_objd
, /* session descriptor (output) */
567 int *channel_objd
, /* channel descriptor (output) */
568 size_t *nr_fields
, /* context fields */
569 struct ustctl_field
**fields
);
572 * Returns 0 on success, negative error value on error.
574 int ustctl_reply_register_channel(int sock
,
576 enum ustctl_channel_header header_type
,
577 int ret_code
); /* return code. 0 ok, negative error */
583 enum ustctl_counter_bitness
{
584 USTCTL_COUNTER_BITNESS_32
= 0,
585 USTCTL_COUNTER_BITNESS_64
= 1,
588 enum ustctl_counter_arithmetic
{
589 USTCTL_COUNTER_ARITHMETIC_MODULAR
= 0,
590 USTCTL_COUNTER_ARITHMETIC_SATURATION
= 1,
593 /* Used as alloc flags. */
594 enum ustctl_counter_alloc
{
595 USTCTL_COUNTER_ALLOC_PER_CPU
= (1 << 0),
596 USTCTL_COUNTER_ALLOC_GLOBAL
= (1 << 1),
599 struct ustctl_daemon_counter
;
601 int ustctl_get_nr_cpu_per_counter(void);
603 struct ustctl_counter_dimension
{
605 uint64_t underflow_index
;
606 uint64_t overflow_index
;
607 uint8_t has_underflow
;
608 uint8_t has_overflow
;
611 struct ustctl_daemon_counter
*
612 ustctl_create_counter(size_t nr_dimensions
,
613 const struct ustctl_counter_dimension
*dimensions
,
614 int64_t global_sum_step
,
615 int global_counter_fd
,
616 int nr_counter_cpu_fds
,
617 const int *counter_cpu_fds
,
618 enum ustctl_counter_bitness bitness
,
619 enum ustctl_counter_arithmetic arithmetic
,
620 uint32_t alloc_flags
,
623 int ustctl_create_counter_data(struct ustctl_daemon_counter
*counter
,
624 struct lttng_ust_abi_object_data
**counter_data
);
626 int ustctl_create_counter_global_data(struct ustctl_daemon_counter
*counter
,
627 struct lttng_ust_abi_object_data
**counter_global_data
);
628 int ustctl_create_counter_cpu_data(struct ustctl_daemon_counter
*counter
, int cpu
,
629 struct lttng_ust_abi_object_data
**counter_cpu_data
);
632 * Each counter data and counter cpu data created need to be destroyed
633 * before calling ustctl_destroy_counter().
635 void ustctl_destroy_counter(struct ustctl_daemon_counter
*counter
);
637 int ustctl_send_counter_data_to_ust(int sock
, int parent_handle
,
638 struct lttng_ust_abi_object_data
*counter_data
);
639 int ustctl_send_counter_global_data_to_ust(int sock
,
640 struct lttng_ust_abi_object_data
*counter_data
,
641 struct lttng_ust_abi_object_data
*counter_global_data
);
642 int ustctl_send_counter_cpu_data_to_ust(int sock
,
643 struct lttng_ust_abi_object_data
*counter_data
,
644 struct lttng_ust_abi_object_data
*counter_cpu_data
);
646 int ustctl_counter_read(struct ustctl_daemon_counter
*counter
,
647 const size_t *dimension_indexes
,
648 int cpu
, int64_t *value
,
649 bool *overflow
, bool *underflow
);
650 int ustctl_counter_aggregate(struct ustctl_daemon_counter
*counter
,
651 const size_t *dimension_indexes
,
653 bool *overflow
, bool *underflow
);
654 int ustctl_counter_clear(struct ustctl_daemon_counter
*counter
,
655 const size_t *dimension_indexes
);
657 #endif /* _LTTNG_UST_CTL_H */