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