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