SoW-2019-0002: Dynamic Snapshot
[lttng-ust.git] / include / lttng / ust-ctl.h
CommitLineData
f3105c67
MD
1/*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
74d81a6c 3 * Copyright (C) 2011-2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
f3105c67 4 *
e92f3e28
MD
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License only.
f3105c67
MD
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
e92f3e28
MD
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f3105c67
MD
17 */
18
19#ifndef _LTTNG_UST_CTL_H
20#define _LTTNG_UST_CTL_H
21
fb31eb73 22#include <limits.h>
b4051ad8 23#include <stddef.h>
fb31eb73 24#include <stdint.h>
32ce8569 25#include <sys/types.h>
fb31eb73
FD
26
27#include <lttng/ust-abi.h>
74d81a6c 28
db56acaf
MD
29#ifndef LTTNG_PACKED
30#error "LTTNG_PACKED should be defined"
31#endif
32
74d81a6c
MD
33#ifndef LTTNG_UST_UUID_LEN
34#define LTTNG_UST_UUID_LEN 16
35#endif
36
32ce8569
MD
37/* Default unix socket path */
38#define LTTNG_UST_SOCK_FILENAME \
39 "lttng-ust-sock-" \
40 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
41
42/*
43 * Shared memory files path are automatically related to shm root, e.g.
44 * /dev/shm under linux.
45 */
46#define LTTNG_UST_WAIT_FILENAME \
47 "lttng-ust-wait-" \
48 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
49
74d81a6c
MD
50struct lttng_ust_shm_handle;
51struct lttng_ust_lib_ring_buffer;
52
53struct ustctl_consumer_channel_attr {
54 enum lttng_ust_chan_type type;
55 uint64_t subbuf_size; /* bytes */
56 uint64_t num_subbuf; /* power of 2 */
57 int overwrite; /* 1: overwrite, 0: discard */
58 unsigned int switch_timer_interval; /* usec */
59 unsigned int read_timer_interval; /* usec */
60 enum lttng_ust_output output; /* splice, mmap */
6ca18e66 61 uint32_t chan_id; /* channel ID */
74d81a6c 62 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
b2c5f61a 63 int64_t blocking_timeout; /* Blocking timeout (usec) */
74d81a6c
MD
64} LTTNG_PACKED;
65
66/*
67 * API used by sessiond.
68 */
69
53f0df51
JG
70struct lttng_ust_context_attr {
71 enum lttng_ust_context_type ctx;
72 union {
73 struct lttng_ust_perf_counter_ctx perf_counter;
74 struct {
75 char *provider_name;
76 char *ctx_name;
77 } app_ctx;
78 } u;
79};
80
7bc53e94
MD
81/*
82 * Error values: all the following functions return:
c354a72c 83 * >= 0: Success (LTTNG_UST_OK)
7bc53e94
MD
84 * < 0: error code.
85 */
1c5e467e 86int ustctl_register_done(int sock);
f3105c67 87int ustctl_create_session(int sock);
f3105c67 88int ustctl_create_event(int sock, struct lttng_ust_event *ev,
61f02aea
MD
89 struct lttng_ust_object_data *channel_data,
90 struct lttng_ust_object_data **event_data);
53f0df51 91int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
61f02aea
MD
92 struct lttng_ust_object_data *obj_data,
93 struct lttng_ust_object_data **context_data);
cd54f6d9
MD
94int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode,
95 struct lttng_ust_object_data *obj_data);
da57c034
JI
96int ustctl_set_exclusion(int sock, struct lttng_ust_event_exclusion *exclusion,
97 struct lttng_ust_object_data *obj_data);
f3105c67 98
61f02aea
MD
99int ustctl_enable(int sock, struct lttng_ust_object_data *object);
100int ustctl_disable(int sock, struct lttng_ust_object_data *object);
4a6ca058
MD
101int ustctl_start_session(int sock, int handle);
102int ustctl_stop_session(int sock, int handle);
f3105c67 103
d5fc3224
FD
104/*
105 * ustctl_create_trigger_group creates a trigger group. It establishes the
106 * connection with the application by providing a file descriptor of the pipe
107 * to be used by the application when a trigger of that group is fired. It
108 * returns a handle to be used when creating trigger in that group.
109 */
110int ustctl_create_trigger_group(int sock, int pipe_fd,
111 struct lttng_ust_object_data **trigger_group);
112
113/*
114 * ustctl_create_trigger creates a trigger in a trigger group giving a trigger
115 * description and a trigger group handle. It returns a trigger handle to be
116 * used when enabling the trigger, attaching filter, attaching exclusion, and
117 * disabling the trigger.
118 */
119int ustctl_create_trigger(int sock, struct lttng_ust_trigger *trigger,
120 struct lttng_ust_object_data *trigger_group,
121 struct lttng_ust_object_data **trigger_data);
122
b115631f
MD
123/*
124 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
125 * error value.
126 */
127int ustctl_tracepoint_list(int sock);
74d81a6c 128
b115631f
MD
129/*
130 * ustctl_tracepoint_list_get is used to iterate on the tp list
7bc53e94
MD
131 * handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
132 * returned.
b115631f
MD
133 */
134int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
cbef6901 135 struct lttng_ust_tracepoint_iter *iter);
b115631f 136
40003310
MD
137/*
138 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
139 * or negative error value.
140 */
141int ustctl_tracepoint_field_list(int sock);
142
143/*
144 * ustctl_tracepoint_field_list_get is used to iterate on the tp field
7bc53e94
MD
145 * list handle. End is iteration is reached when -LTTNG_UST_ERR_NOENT is
146 * returned.
40003310
MD
147 */
148int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle,
149 struct lttng_ust_field_iter *iter);
150
f3105c67
MD
151int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v);
152int ustctl_wait_quiescent(int sock);
153
f1fffc57
MD
154int ustctl_sock_flush_buffer(int sock, struct lttng_ust_object_data *object);
155
f3105c67
MD
156int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate);
157
74d81a6c
MD
158/* Release object created by members of this API. */
159int ustctl_release_object(int sock, struct lttng_ust_object_data *data);
160/* Release handle returned by create session. */
161int ustctl_release_handle(int sock, int handle);
162
163int ustctl_recv_channel_from_consumer(int sock,
164 struct lttng_ust_object_data **channel_data);
165int ustctl_recv_stream_from_consumer(int sock,
166 struct lttng_ust_object_data **stream_data);
167int ustctl_send_channel_to_ust(int sock, int session_handle,
168 struct lttng_ust_object_data *channel_data);
169int ustctl_send_stream_to_ust(int sock,
170 struct lttng_ust_object_data *channel_data,
171 struct lttng_ust_object_data *stream_data);
172
12f3dabc
MD
173/*
174 * ustctl_duplicate_ust_object_data allocated a new object in "dest" if
175 * it succeeds (returns 0). It must be released using
176 * ustctl_release_object() and then freed with free().
177 */
178int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest,
179 struct lttng_ust_object_data *src);
180
f3105c67 181/*
74d81a6c 182 * API used by consumer.
f3105c67 183 */
74d81a6c
MD
184
185struct ustctl_consumer_channel;
186struct ustctl_consumer_stream;
187struct ustctl_consumer_channel_attr;
188
5ea386c3
MD
189int ustctl_get_nr_stream_per_channel(void);
190
74d81a6c 191struct ustctl_consumer_channel *
5ea386c3
MD
192 ustctl_create_channel(struct ustctl_consumer_channel_attr *attr,
193 const int *stream_fds, int nr_stream_fds);
5224b5c8 194/*
74d81a6c
MD
195 * Each stream created needs to be destroyed before calling
196 * ustctl_destroy_channel().
5224b5c8 197 */
74d81a6c 198void ustctl_destroy_channel(struct ustctl_consumer_channel *chan);
f3105c67 199
74d81a6c
MD
200int ustctl_send_channel_to_sessiond(int sock,
201 struct ustctl_consumer_channel *channel);
ff0f5728
MD
202int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan);
203int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan);
204int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *consumer_chan);
205int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *consumer_chan);
c9023c93
MD
206
207int ustctl_write_metadata_to_channel(
208 struct ustctl_consumer_channel *channel,
209 const char *metadata_str, /* NOT null-terminated */
210 size_t len); /* metadata length */
3ef94b0e
JD
211ssize_t ustctl_write_one_packet_to_channel(
212 struct ustctl_consumer_channel *channel,
213 const char *metadata_str, /* NOT null-terminated */
214 size_t len); /* metadata length */
c9023c93 215
74d81a6c
MD
216/*
217 * Send a NULL stream to finish iteration over all streams of a given
218 * channel.
219 */
220int ustctl_send_stream_to_sessiond(int sock,
221 struct ustctl_consumer_stream *stream);
222int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream);
223int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream *stream);
ff0f5728
MD
224int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream);
225int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream);
f3105c67 226
74d81a6c
MD
227/* Create/destroy stream buffers for read */
228struct ustctl_consumer_stream *
229 ustctl_create_stream(struct ustctl_consumer_channel *channel,
230 int cpu);
231void ustctl_destroy_stream(struct ustctl_consumer_stream *stream);
f3105c67
MD
232
233/* For mmap mode, readable without "get" operation */
74d81a6c 234int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream,
f3105c67 235 unsigned long *len);
74d81a6c 236int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream,
f3105c67
MD
237 unsigned long *len);
238
239/*
240 * For mmap mode, operate on the current packet (between get/put or
241 * get_next/put_next).
242 */
74d81a6c
MD
243void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream);
244int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream,
245 unsigned long *off);
246int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream,
247 unsigned long *len);
248int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
249 unsigned long *len);
250int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream);
251int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream);
f3105c67
MD
252
253/* snapshot */
254
74d81a6c 255int ustctl_snapshot(struct ustctl_consumer_stream *stream);
f45930b7 256int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream);
74d81a6c
MD
257int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
258 unsigned long *pos);
259int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,
260 unsigned long *pos);
261int ustctl_get_subbuf(struct ustctl_consumer_stream *stream,
262 unsigned long *pos);
263int ustctl_put_subbuf(struct ustctl_consumer_stream *stream);
5f9d3dbc 264
74d81a6c
MD
265void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
266 int producer_active);
beca55a1 267void ustctl_clear_buffer(struct ustctl_consumer_stream *stream);
f3105c67 268
b2f3252a 269/* index */
82df14e4
MD
270
271/*
272 * Getters which need to be used on the current packet (between get/put
273 * or get_next/put_next.
274 */
275
b2f3252a
JD
276int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream,
277 uint64_t *timestamp_begin);
278int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream,
279 uint64_t *timestamp_end);
280int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream,
281 uint64_t *events_discarded);
282int ustctl_get_content_size(struct ustctl_consumer_stream *stream,
283 uint64_t *content_size);
284int ustctl_get_packet_size(struct ustctl_consumer_stream *stream,
285 uint64_t *packet_size);
1ff31389
JD
286int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
287 uint64_t *seq);
82df14e4
MD
288
289/*
290 * Getter returning state invariant for the stream, which can be used
291 * without "get" operation.
292 */
293
294int ustctl_get_stream_id(struct ustctl_consumer_stream *stream,
295 uint64_t *stream_id);
45a00b05
JD
296int ustctl_get_instance_id(struct ustctl_consumer_stream *stream,
297 uint64_t *id);
b2f3252a 298
82df14e4
MD
299/*
300 * Getter returning the current timestamp as perceived from the
301 * tracer.
302 */
303int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream,
304 uint64_t *ts);
305
57201bb3
MD
306/* returns whether UST has perf counters support. */
307int ustctl_has_perf_counters(void);
308
f53329f3
JD
309/* Regenerate the statedump. */
310int ustctl_regenerate_statedump(int sock, int handle);
311
32ce8569
MD
312/* event registry management */
313
314enum ustctl_socket_type {
315 USTCTL_SOCKET_CMD = 0,
316 USTCTL_SOCKET_NOTIFY = 1,
317};
318
319enum ustctl_notify_cmd {
320 USTCTL_NOTIFY_CMD_EVENT = 0,
321 USTCTL_NOTIFY_CMD_CHANNEL = 1,
c785c634 322 USTCTL_NOTIFY_CMD_ENUM = 2,
32ce8569
MD
323};
324
325enum ustctl_channel_header {
326 USTCTL_CHANNEL_HEADER_UNKNOWN = 0,
327 USTCTL_CHANNEL_HEADER_COMPACT = 1,
328 USTCTL_CHANNEL_HEADER_LARGE = 2,
329};
330
331/* event type structures */
332
333enum ustctl_abstract_types {
334 ustctl_atype_integer,
335 ustctl_atype_enum,
336 ustctl_atype_array,
337 ustctl_atype_sequence,
338 ustctl_atype_string,
339 ustctl_atype_float,
53569322
MD
340 ustctl_atype_variant,
341 ustctl_atype_struct,
32ce8569
MD
342 NR_USTCTL_ABSTRACT_TYPES,
343};
344
345enum ustctl_string_encodings {
346 ustctl_encode_none = 0,
347 ustctl_encode_UTF8 = 1,
348 ustctl_encode_ASCII = 2,
349 NR_USTCTL_STRING_ENCODINGS,
350};
351
352#define USTCTL_UST_INTEGER_TYPE_PADDING 24
353struct ustctl_integer_type {
354 uint32_t size; /* in bits */
355 uint32_t signedness;
356 uint32_t reverse_byte_order;
357 uint32_t base; /* 2, 8, 10, 16, for pretty print */
735ea6a8 358 int32_t encoding; /* enum ustctl_string_encodings */
32ce8569
MD
359 uint16_t alignment; /* in bits */
360 char padding[USTCTL_UST_INTEGER_TYPE_PADDING];
361} LTTNG_PACKED;
362
363#define USTCTL_UST_FLOAT_TYPE_PADDING 24
364struct ustctl_float_type {
365 uint32_t exp_dig; /* exponent digits, in bits */
366 uint32_t mant_dig; /* mantissa digits, in bits */
367 uint32_t reverse_byte_order;
368 uint16_t alignment; /* in bits */
369 char padding[USTCTL_UST_FLOAT_TYPE_PADDING];
370} LTTNG_PACKED;
371
a6f80644
MD
372#define USTCTL_UST_ENUM_VALUE_PADDING 15
373struct ustctl_enum_value {
374 uint64_t value;
375 uint8_t signedness;
376 char padding[USTCTL_UST_ENUM_VALUE_PADDING];
377} LTTNG_PACKED;
378
3e762260
PP
379enum ustctl_ust_enum_entry_options {
380 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
381};
382
c785c634
MD
383#define USTCTL_UST_ENUM_ENTRY_PADDING 32
384struct ustctl_enum_entry {
a6f80644 385 struct ustctl_enum_value start, end; /* start and end are inclusive */
c785c634 386 char string[LTTNG_UST_SYM_NAME_LEN];
3e762260
PP
387 union {
388 struct {
389 uint32_t options;
390 } LTTNG_PACKED extra;
391 char padding[USTCTL_UST_ENUM_ENTRY_PADDING];
392 } u;
a6f80644 393} LTTNG_PACKED;
c785c634 394
32ce8569
MD
395#define USTCTL_UST_BASIC_TYPE_PADDING 296
396union _ustctl_basic_type {
397 struct ustctl_integer_type integer;
c785c634
MD
398 struct {
399 char name[LTTNG_UST_SYM_NAME_LEN];
400 struct ustctl_integer_type container_type;
401 uint64_t id; /* enum ID in sessiond. */
402 } enumeration;
32ce8569 403 struct {
735ea6a8 404 int32_t encoding; /* enum ustctl_string_encodings */
32ce8569
MD
405 } string;
406 struct ustctl_float_type _float;
407 char padding[USTCTL_UST_BASIC_TYPE_PADDING];
408} LTTNG_PACKED;
409
410struct ustctl_basic_type {
411 enum ustctl_abstract_types atype;
412 union {
413 union _ustctl_basic_type basic;
414 } u;
415} LTTNG_PACKED;
416
417#define USTCTL_UST_TYPE_PADDING 128
418struct ustctl_type {
419 enum ustctl_abstract_types atype;
420 union {
421 union _ustctl_basic_type basic;
422 struct {
423 struct ustctl_basic_type elem_type;
424 uint32_t length; /* num. elems. */
425 } array;
426 struct {
427 struct ustctl_basic_type length_type;
428 struct ustctl_basic_type elem_type;
429 } sequence;
53569322
MD
430 struct {
431 uint32_t nr_choices;
432 char tag_name[LTTNG_UST_SYM_NAME_LEN];
433 /* Followed by nr_choices struct ustctl_field. */
434 } variant;
435 struct {
436 uint32_t nr_fields;
437 /* Followed by nr_fields struct ustctl_field. */
438 } _struct;
32ce8569
MD
439 char padding[USTCTL_UST_TYPE_PADDING];
440 } u;
441} LTTNG_PACKED;
442
443#define USTCTL_UST_FIELD_PADDING 28
444struct ustctl_field {
445 char name[LTTNG_UST_SYM_NAME_LEN];
446 struct ustctl_type type;
447 char padding[USTCTL_UST_FIELD_PADDING];
448} LTTNG_PACKED;
449
450/*
451 * Returns 0 on success, negative error value on error.
452 * If an error other than -LTTNG_UST_ERR_UNSUP_MAJOR is returned,
453 * the output fields are not populated.
454 */
455int ustctl_recv_reg_msg(int sock,
456 enum ustctl_socket_type *type,
457 uint32_t *major,
458 uint32_t *minor,
459 uint32_t *pid,
460 uint32_t *ppid,
461 uint32_t *uid,
462 uint32_t *gid,
463 uint32_t *bits_per_long,
464 uint32_t *uint8_t_alignment,
465 uint32_t *uint16_t_alignment,
466 uint32_t *uint32_t_alignment,
467 uint32_t *uint64_t_alignment,
468 uint32_t *long_alignment,
469 int *byte_order,
470 char *name); /* size LTTNG_UST_ABI_PROCNAME_LEN */
471
472/*
473 * Returns 0 on success, negative UST or system error value on error.
474 * Receive the notification command. The "notify_cmd" can then be used
475 * by the caller to find out which ustctl_recv_* function should be
476 * called to receive the notification, and which ustctl_reply_* is
477 * appropriate.
478 */
479int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd);
480
481/*
482 * Returns 0 on success, negative UST or system error value on error.
483 */
484int ustctl_recv_register_event(int sock,
485 int *session_objd, /* session descriptor (output) */
486 int *channel_objd, /* channel descriptor (output) */
487 char *event_name, /*
488 * event name (output,
489 * size LTTNG_UST_SYM_NAME_LEN)
490 */
491 int *loglevel,
492 char **signature, /*
493 * event signature
494 * (output, dynamically
495 * allocated, must be free(3)'d
496 * by the caller if function
497 * returns success.)
498 */
499 size_t *nr_fields,
500 struct ustctl_field **fields,
501 char **model_emf_uri);
502
503/*
504 * Returns 0 on success, negative error value on error.
505 */
506int ustctl_reply_register_event(int sock,
507 uint32_t id, /* event id (input) */
508 int ret_code); /* return code. 0 ok, negative error */
509
c785c634
MD
510/*
511 * Returns 0 on success, negative UST or system error value on error.
512 */
513int ustctl_recv_register_enum(int sock,
514 int *session_objd,
515 char *enum_name,
516 struct ustctl_enum_entry **entries,
517 size_t *nr_entries);
518
519/*
520 * Returns 0 on success, negative error value on error.
521 */
522int ustctl_reply_register_enum(int sock,
523 uint64_t id, /* enum id (input) */
524 int ret_code);
525
32ce8569
MD
526/*
527 * Returns 0 on success, negative UST or system error value on error.
528 */
529int ustctl_recv_register_channel(int sock,
530 int *session_objd, /* session descriptor (output) */
531 int *channel_objd, /* channel descriptor (output) */
532 size_t *nr_fields, /* context fields */
533 struct ustctl_field **fields);
534
535/*
536 * Returns 0 on success, negative error value on error.
537 */
538int ustctl_reply_register_channel(int sock,
539 uint32_t chan_id,
540 enum ustctl_channel_header header_type,
541 int ret_code); /* return code. 0 ok, negative error */
542
f3105c67 543#endif /* _LTTNG_UST_CTL_H */
This page took 0.062678 seconds and 5 git commands to generate.