2 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef LTTNG_UST_CTL_INTERNAL_H
10 #define LTTNG_UST_CTL_INTERNAL_H
14 #include <sys/types.h>
16 #include "lttng-ust-abi.h"
18 #ifndef LTTNG_UST_UUID_LEN
19 #define LTTNG_UST_UUID_LEN 16
22 /* Default unix socket path */
23 #define LTTNG_UST_SOCK_FILENAME \
25 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
28 * Shared memory files path are automatically related to shm root, e.g.
29 * /dev/shm under linux.
31 #define LTTNG_UST_WAIT_FILENAME \
33 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
35 struct lttng_ust_shm_handle
;
36 struct lttng_ust_lib_ring_buffer
;
38 struct ustctl_consumer_channel_attr
{
39 enum lttng_ust_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_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) */
52 * API used by sessiond.
55 struct lttng_ust_context_attr
{
56 enum lttng_ust_context_type ctx
;
58 struct lttng_ust_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_event
*ev
,
74 struct lttng_ust_object_data
*channel_data
,
75 struct lttng_ust_object_data
**event_data
);
76 int ustctl_add_context(int sock
, struct lttng_ust_context_attr
*ctx
,
77 struct lttng_ust_object_data
*obj_data
,
78 struct lttng_ust_object_data
**context_data
);
79 int ustctl_set_filter(int sock
, struct lttng_ust_filter_bytecode
*bytecode
,
80 struct lttng_ust_object_data
*obj_data
);
81 int ustctl_set_exclusion(int sock
, struct lttng_ust_event_exclusion
*exclusion
,
82 struct lttng_ust_object_data
*obj_data
);
83 int ustctl_set_capture(int sock
, struct lttng_ust_capture_bytecode
*bytecode
,
84 struct lttng_ust_object_data
*obj_data
);
86 int ustctl_enable(int sock
, struct lttng_ust_object_data
*object
);
87 int ustctl_disable(int sock
, struct lttng_ust_object_data
*object
);
88 int ustctl_start_session(int sock
, int handle
);
89 int ustctl_stop_session(int sock
, int handle
);
91 int ustctl_create_event_notifier_group(int sock
,
93 struct lttng_ust_object_data
**event_notifier_group_handle
);
94 int ustctl_create_event_notifier(int sock
,
95 struct lttng_ust_event_notifier
*event_notifier
,
96 struct lttng_ust_object_data
*event_notifier_group_handle
,
97 struct lttng_ust_object_data
**event_notifier_data
);
100 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
103 int ustctl_tracepoint_list(int sock
);
106 * ustctl_tracepoint_list_get is used to iterate on the tp list
107 * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
110 int ustctl_tracepoint_list_get(int sock
, int tp_list_handle
,
111 struct lttng_ust_tracepoint_iter
*iter
);
114 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
115 * or negative error value.
117 int ustctl_tracepoint_field_list(int sock
);
120 * ustctl_tracepoint_field_list_get is used to iterate on the tp field
121 * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
124 int ustctl_tracepoint_field_list_get(int sock
, int tp_field_list_handle
,
125 struct lttng_ust_field_iter
*iter
);
127 int ustctl_tracer_version(int sock
, struct lttng_ust_tracer_version
*v
);
128 int ustctl_wait_quiescent(int sock
);
130 int ustctl_sock_flush_buffer(int sock
, struct lttng_ust_object_data
*object
);
132 int ustctl_calibrate(int sock
, struct lttng_ust_calibrate
*calibrate
);
134 /* Release object created by members of this API. */
135 int ustctl_release_object(int sock
, struct lttng_ust_object_data
*data
);
136 /* Release handle returned by create session. */
137 int ustctl_release_handle(int sock
, int handle
);
139 int ustctl_recv_channel_from_consumer(int sock
,
140 struct lttng_ust_object_data
**channel_data
);
141 int ustctl_recv_stream_from_consumer(int sock
,
142 struct lttng_ust_object_data
**stream_data
);
143 int ustctl_send_channel_to_ust(int sock
, int session_handle
,
144 struct lttng_ust_object_data
*channel_data
);
145 int ustctl_send_stream_to_ust(int sock
,
146 struct lttng_ust_object_data
*channel_data
,
147 struct lttng_ust_object_data
*stream_data
);
150 * ustctl_duplicate_ust_object_data allocated a new object in "dest" if
151 * it succeeds (returns 0). It must be released using
152 * ustctl_release_object() and then freed with free().
154 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data
**dest
,
155 struct lttng_ust_object_data
*src
);
158 * API used by consumer.
161 struct ustctl_consumer_channel
;
162 struct ustctl_consumer_stream
;
163 struct ustctl_consumer_channel_attr
;
165 int ustctl_get_nr_stream_per_channel(void);
167 struct ustctl_consumer_channel
*
168 ustctl_create_channel(struct ustctl_consumer_channel_attr
*attr
,
169 const int *stream_fds
, int nr_stream_fds
);
171 * Each stream created needs to be destroyed before calling
172 * ustctl_destroy_channel().
174 void ustctl_destroy_channel(struct ustctl_consumer_channel
*chan
);
176 int ustctl_send_channel_to_sessiond(int sock
,
177 struct ustctl_consumer_channel
*channel
);
178 int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
179 int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
180 int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel
*consumer_chan
);
181 int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel
*consumer_chan
);
183 int ustctl_write_metadata_to_channel(
184 struct ustctl_consumer_channel
*channel
,
185 const char *metadata_str
, /* NOT null-terminated */
186 size_t len
); /* metadata length */
187 ssize_t
ustctl_write_one_packet_to_channel(
188 struct ustctl_consumer_channel
*channel
,
189 const char *metadata_str
, /* NOT null-terminated */
190 size_t len
); /* metadata length */
193 * Send a NULL stream to finish iteration over all streams of a given
196 int ustctl_send_stream_to_sessiond(int sock
,
197 struct ustctl_consumer_stream
*stream
);
198 int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream
*stream
);
199 int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream
*stream
);
200 int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream
*stream
);
201 int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream
*stream
);
203 /* Create/destroy stream buffers for read */
204 struct ustctl_consumer_stream
*
205 ustctl_create_stream(struct ustctl_consumer_channel
*channel
,
207 void ustctl_destroy_stream(struct ustctl_consumer_stream
*stream
);
209 /* For mmap mode, readable without "get" operation */
210 int ustctl_get_mmap_len(struct ustctl_consumer_stream
*stream
,
212 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream
*stream
,
216 * For mmap mode, operate on the current packet (between get/put or
217 * get_next/put_next).
219 void *ustctl_get_mmap_base(struct ustctl_consumer_stream
*stream
);
220 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream
*stream
,
222 int ustctl_get_subbuf_size(struct ustctl_consumer_stream
*stream
,
224 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream
*stream
,
226 int ustctl_get_next_subbuf(struct ustctl_consumer_stream
*stream
);
227 int ustctl_put_next_subbuf(struct ustctl_consumer_stream
*stream
);
231 int ustctl_snapshot(struct ustctl_consumer_stream
*stream
);
232 int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream
*stream
);
233 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream
*stream
,
235 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream
*stream
,
237 int ustctl_get_subbuf(struct ustctl_consumer_stream
*stream
,
239 int ustctl_put_subbuf(struct ustctl_consumer_stream
*stream
);
241 void ustctl_flush_buffer(struct ustctl_consumer_stream
*stream
,
242 int producer_active
);
245 int ustctl_get_timestamp_begin(struct ustctl_consumer_stream
*stream
,
246 uint64_t *timestamp_begin
);
247 int ustctl_get_timestamp_end(struct ustctl_consumer_stream
*stream
,
248 uint64_t *timestamp_end
);
249 int ustctl_get_events_discarded(struct ustctl_consumer_stream
*stream
,
250 uint64_t *events_discarded
);
251 int ustctl_get_content_size(struct ustctl_consumer_stream
*stream
,
252 uint64_t *content_size
);
253 int ustctl_get_packet_size(struct ustctl_consumer_stream
*stream
,
254 uint64_t *packet_size
);
255 int ustctl_get_stream_id(struct ustctl_consumer_stream
*stream
,
256 uint64_t *stream_id
);
257 int ustctl_get_current_timestamp(struct ustctl_consumer_stream
*stream
,
259 int ustctl_get_sequence_number(struct ustctl_consumer_stream
*stream
,
261 int ustctl_get_instance_id(struct ustctl_consumer_stream
*stream
,
264 /* returns whether UST has perf counters support. */
265 int ustctl_has_perf_counters(void);
267 /* Regenerate the statedump. */
268 int ustctl_regenerate_statedump(int sock
, int handle
);
270 /* event registry management */
272 enum ustctl_socket_type
{
273 USTCTL_SOCKET_CMD
= 0,
274 USTCTL_SOCKET_NOTIFY
= 1,
277 enum ustctl_notify_cmd
{
278 USTCTL_NOTIFY_CMD_EVENT
= 0,
279 USTCTL_NOTIFY_CMD_CHANNEL
= 1,
280 USTCTL_NOTIFY_CMD_ENUM
= 2,
283 enum ustctl_channel_header
{
284 USTCTL_CHANNEL_HEADER_UNKNOWN
= 0,
285 USTCTL_CHANNEL_HEADER_COMPACT
= 1,
286 USTCTL_CHANNEL_HEADER_LARGE
= 2,
289 /* event type structures */
291 enum ustctl_abstract_types
{
292 ustctl_atype_integer
,
293 ustctl_atype_enum
, /* legacy */
294 ustctl_atype_array
, /* legacy */
295 ustctl_atype_sequence
, /* legacy */
298 ustctl_atype_variant
, /* legacy */
299 ustctl_atype_struct
, /* legacy */
300 ustctl_atype_enum_nestable
,
301 ustctl_atype_array_nestable
,
302 ustctl_atype_sequence_nestable
,
303 ustctl_atype_struct_nestable
,
304 ustctl_atype_variant_nestable
,
305 NR_USTCTL_ABSTRACT_TYPES
,
308 enum ustctl_string_encodings
{
309 ustctl_encode_none
= 0,
310 ustctl_encode_UTF8
= 1,
311 ustctl_encode_ASCII
= 2,
312 NR_USTCTL_STRING_ENCODINGS
,
315 #define USTCTL_UST_INTEGER_TYPE_PADDING 24
316 struct ustctl_integer_type
{
317 uint32_t size
; /* in bits */
319 uint32_t reverse_byte_order
;
320 uint32_t base
; /* 2, 8, 10, 16, for pretty print */
321 int32_t encoding
; /* enum ustctl_string_encodings */
322 uint16_t alignment
; /* in bits */
323 char padding
[USTCTL_UST_INTEGER_TYPE_PADDING
];
326 #define USTCTL_UST_FLOAT_TYPE_PADDING 24
327 struct ustctl_float_type
{
328 uint32_t exp_dig
; /* exponent digits, in bits */
329 uint32_t mant_dig
; /* mantissa digits, in bits */
330 uint32_t reverse_byte_order
;
331 uint16_t alignment
; /* in bits */
332 char padding
[USTCTL_UST_FLOAT_TYPE_PADDING
];
335 #define USTCTL_UST_ENUM_VALUE_PADDING 15
336 struct ustctl_enum_value
{
339 char padding
[USTCTL_UST_ENUM_VALUE_PADDING
];
342 enum ustctl_ust_enum_entry_options
{
343 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
= 1U << 0,
346 #define USTCTL_UST_ENUM_ENTRY_PADDING 32
347 struct ustctl_enum_entry
{
348 struct ustctl_enum_value start
, end
; /* start and end are inclusive */
349 char string
[LTTNG_UST_SYM_NAME_LEN
];
353 } LTTNG_PACKED extra
;
354 char padding
[USTCTL_UST_ENUM_ENTRY_PADDING
];
359 #define USTCTL_UST_BASIC_TYPE_PADDING 296
360 union _ustctl_basic_type
{
361 struct ustctl_integer_type integer
;
363 char name
[LTTNG_UST_SYM_NAME_LEN
];
364 struct ustctl_integer_type container_type
;
365 uint64_t id
; /* enum ID in sessiond. */
368 int32_t encoding
; /* enum ustctl_string_encodings */
370 struct ustctl_float_type _float
;
371 char padding
[USTCTL_UST_BASIC_TYPE_PADDING
];
375 struct ustctl_basic_type
{
376 enum ustctl_abstract_types atype
;
378 union _ustctl_basic_type basic
;
383 * Padding is derived from largest member: u.legacy.sequence which
384 * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING.
386 #define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING)
388 enum ustctl_abstract_types atype
;
390 struct ustctl_integer_type integer
;
391 struct ustctl_float_type _float
;
393 int32_t encoding
; /* enum ustctl_string_encodings */
396 char name
[LTTNG_UST_SYM_NAME_LEN
];
397 uint64_t id
; /* enum ID in sessiond. */
398 /* container_type follows after this struct ustctl_field. */
401 uint32_t length
; /* num. elems. */
403 /* elem_type follows after this struct ustctl_field. */
406 char length_name
[LTTNG_UST_SYM_NAME_LEN
];
407 uint32_t alignment
; /* Alignment before elements. */
408 /* elem_type follows after the length_type. */
413 /* Followed by nr_fields struct ustctl_field. */
417 char tag_name
[LTTNG_UST_SYM_NAME_LEN
];
419 /* Followed by nr_choices struct ustctl_field. */
424 union _ustctl_basic_type basic
;
426 struct ustctl_basic_type elem_type
;
427 uint32_t length
; /* num. elems. */
430 struct ustctl_basic_type length_type
;
431 struct ustctl_basic_type elem_type
;
435 /* Followed by nr_fields struct ustctl_field. */
439 char tag_name
[LTTNG_UST_SYM_NAME_LEN
];
440 /* Followed by nr_choices struct ustctl_field. */
443 char padding
[USTCTL_UST_TYPE_PADDING
];
447 #define USTCTL_UST_FIELD_PADDING 28
448 struct ustctl_field
{
449 char name
[LTTNG_UST_SYM_NAME_LEN
];
450 struct ustctl_type type
;
451 char padding
[USTCTL_UST_FIELD_PADDING
];
455 * Returns 0 on success, negative error value on error.
456 * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned,
457 * the output fields are not populated.
459 int ustctl_recv_reg_msg(int sock
,
460 enum ustctl_socket_type
*type
,
467 uint32_t *bits_per_long
,
468 uint32_t *uint8_t_alignment
,
469 uint32_t *uint16_t_alignment
,
470 uint32_t *uint32_t_alignment
,
471 uint32_t *uint64_t_alignment
,
472 uint32_t *long_alignment
,
474 char *name
); /* size LTTNG_UST_ABI_PROCNAME_LEN */
477 * Returns 0 on success, negative UST or system error value on error.
478 * Receive the notification command. The "notify_cmd" can then be used
479 * by the caller to find out which ustctl_recv_* function should be
480 * called to receive the notification, and which ustctl_reply_* is
483 int ustctl_recv_notify(int sock
, enum ustctl_notify_cmd
*notify_cmd
);
486 * Returns 0 on success, negative UST or system error value on error.
488 int ustctl_recv_register_event(int sock
,
489 int *session_objd
, /* session descriptor (output) */
490 int *channel_objd
, /* channel descriptor (output) */
492 * event name (output,
493 * size LTTNG_UST_SYM_NAME_LEN)
498 * (output, dynamically
499 * allocated, must be free(3)'d
500 * by the caller if function
504 struct ustctl_field
**fields
,
505 char **model_emf_uri
);
508 * Returns 0 on success, negative error value on error.
510 int ustctl_reply_register_event(int sock
,
511 uint32_t id
, /* event id (input) */
512 int ret_code
); /* return code. 0 ok, negative error */
515 * Returns 0 on success, negative UST or system error value on error.
517 int ustctl_recv_register_enum(int sock
,
520 struct ustctl_enum_entry
**entries
,
524 * Returns 0 on success, negative error value on error.
526 int ustctl_reply_register_enum(int sock
,
527 uint64_t id
, /* enum id (input) */
531 * Returns 0 on success, negative UST or system error value on error.
533 int ustctl_recv_register_channel(int sock
,
534 int *session_objd
, /* session descriptor (output) */
535 int *channel_objd
, /* channel descriptor (output) */
536 size_t *nr_fields
, /* context fields */
537 struct ustctl_field
**fields
);
540 * Returns 0 on success, negative error value on error.
542 int ustctl_reply_register_channel(int sock
,
544 enum ustctl_channel_header header_type
,
545 int ret_code
); /* return code. 0 ok, negative error */
547 #endif /* LTTNG_UST_CTL_INTERNAL_H */