SoW-2020-0003: Trace Hit Counters
[lttng-tools.git] / src / bin / lttng-sessiond / ust-ctl-internal.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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef LTTNG_UST_CTL_INTERNAL_H
10 #define LTTNG_UST_CTL_INTERNAL_H
11
12 #include <limits.h>
13 #include <stdbool.h>
14 #include <sys/types.h>
15
16 #include "lttng-ust-abi.h"
17
18 #ifndef LTTNG_UST_UUID_LEN
19 #define LTTNG_UST_UUID_LEN 16
20 #endif
21
22 /* Default unix socket path */
23 #define LTTNG_UST_SOCK_FILENAME \
24 "lttng-ust-sock-" \
25 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
26
27 /*
28 * Shared memory files path are automatically related to shm root, e.g.
29 * /dev/shm under linux.
30 */
31 #define LTTNG_UST_WAIT_FILENAME \
32 "lttng-ust-wait-" \
33 __ust_stringify(LTTNG_UST_ABI_MAJOR_VERSION)
34
35 struct lttng_ust_shm_handle;
36 struct lttng_ust_lib_ring_buffer;
37
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) */
49 } LTTNG_PACKED;
50
51 /*
52 * API used by sessiond.
53 */
54
55 struct lttng_ust_context_attr {
56 enum lttng_ust_context_type ctx;
57 union {
58 struct lttng_ust_perf_counter_ctx perf_counter;
59 struct {
60 char *provider_name;
61 char *ctx_name;
62 } app_ctx;
63 } u;
64 };
65
66 /*
67 * Error values: all the following functions return:
68 * >= 0: Success (LTTNG_UST_OK)
69 * < 0: error code.
70 */
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);
85
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);
90
91 int ustctl_create_event_notifier_group(int sock,
92 int pipe_fd,
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);
98
99 /*
100 * ustctl_tracepoint_list returns a tracepoint list handle, or negative
101 * error value.
102 */
103 int ustctl_tracepoint_list(int sock);
104
105 /*
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
108 * returned.
109 */
110 int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
111 struct lttng_ust_tracepoint_iter *iter);
112
113 /*
114 * ustctl_tracepoint_field_list returns a tracepoint field list handle,
115 * or negative error value.
116 */
117 int ustctl_tracepoint_field_list(int sock);
118
119 /*
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
122 * returned.
123 */
124 int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle,
125 struct lttng_ust_field_iter *iter);
126
127 int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v);
128 int ustctl_wait_quiescent(int sock);
129
130 int ustctl_sock_flush_buffer(int sock, struct lttng_ust_object_data *object);
131
132 int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate);
133
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);
138
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);
148
149 /*
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().
153 */
154 int ustctl_duplicate_ust_object_data(struct lttng_ust_object_data **dest,
155 struct lttng_ust_object_data *src);
156
157 /*
158 * API used by consumer.
159 */
160
161 struct ustctl_consumer_channel;
162 struct ustctl_consumer_stream;
163 struct ustctl_consumer_channel_attr;
164
165 int ustctl_get_nr_stream_per_channel(void);
166
167 struct ustctl_consumer_channel *
168 ustctl_create_channel(struct ustctl_consumer_channel_attr *attr,
169 const int *stream_fds, int nr_stream_fds);
170 /*
171 * Each stream created needs to be destroyed before calling
172 * ustctl_destroy_channel().
173 */
174 void ustctl_destroy_channel(struct ustctl_consumer_channel *chan);
175
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);
182
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 */
191
192 /*
193 * Send a NULL stream to finish iteration over all streams of a given
194 * channel.
195 */
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);
202
203 /* Create/destroy stream buffers for read */
204 struct ustctl_consumer_stream *
205 ustctl_create_stream(struct ustctl_consumer_channel *channel,
206 int cpu);
207 void ustctl_destroy_stream(struct ustctl_consumer_stream *stream);
208
209 /* For mmap mode, readable without "get" operation */
210 int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream,
211 unsigned long *len);
212 int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream,
213 unsigned long *len);
214
215 /*
216 * For mmap mode, operate on the current packet (between get/put or
217 * get_next/put_next).
218 */
219 void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream);
220 int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream,
221 unsigned long *off);
222 int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream,
223 unsigned long *len);
224 int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream,
225 unsigned long *len);
226 int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream);
227 int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream);
228
229 /* snapshot */
230
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,
234 unsigned long *pos);
235 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,
236 unsigned long *pos);
237 int ustctl_get_subbuf(struct ustctl_consumer_stream *stream,
238 unsigned long *pos);
239 int ustctl_put_subbuf(struct ustctl_consumer_stream *stream);
240
241 void ustctl_flush_buffer(struct ustctl_consumer_stream *stream,
242 int producer_active);
243
244 /* index */
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,
258 uint64_t *ts);
259 int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream,
260 uint64_t *seq);
261 int ustctl_get_instance_id(struct ustctl_consumer_stream *stream,
262 uint64_t *id);
263
264 /* returns whether UST has perf counters support. */
265 int ustctl_has_perf_counters(void);
266
267 /* Regenerate the statedump. */
268 int ustctl_regenerate_statedump(int sock, int handle);
269
270 /* event registry management */
271
272 enum ustctl_socket_type {
273 USTCTL_SOCKET_CMD = 0,
274 USTCTL_SOCKET_NOTIFY = 1,
275 };
276
277 enum ustctl_notify_cmd {
278 USTCTL_NOTIFY_CMD_EVENT = 0,
279 USTCTL_NOTIFY_CMD_CHANNEL = 1,
280 USTCTL_NOTIFY_CMD_ENUM = 2,
281 };
282
283 enum ustctl_channel_header {
284 USTCTL_CHANNEL_HEADER_UNKNOWN = 0,
285 USTCTL_CHANNEL_HEADER_COMPACT = 1,
286 USTCTL_CHANNEL_HEADER_LARGE = 2,
287 };
288
289 /* event type structures */
290
291 enum ustctl_abstract_types {
292 ustctl_atype_integer,
293 ustctl_atype_enum, /* legacy */
294 ustctl_atype_array, /* legacy */
295 ustctl_atype_sequence, /* legacy */
296 ustctl_atype_string,
297 ustctl_atype_float,
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,
306 };
307
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,
313 };
314
315 #define USTCTL_UST_INTEGER_TYPE_PADDING 24
316 struct ustctl_integer_type {
317 uint32_t size; /* in bits */
318 uint32_t signedness;
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];
324 } LTTNG_PACKED;
325
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];
333 } LTTNG_PACKED;
334
335 #define USTCTL_UST_ENUM_VALUE_PADDING 15
336 struct ustctl_enum_value {
337 uint64_t value;
338 uint8_t signedness;
339 char padding[USTCTL_UST_ENUM_VALUE_PADDING];
340 } LTTNG_PACKED;
341
342 enum ustctl_ust_enum_entry_options {
343 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
344 };
345
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];
350 union {
351 struct {
352 uint32_t options;
353 } LTTNG_PACKED extra;
354 char padding[USTCTL_UST_ENUM_ENTRY_PADDING];
355 } u;
356 } LTTNG_PACKED;
357
358 /* legacy */
359 #define USTCTL_UST_BASIC_TYPE_PADDING 296
360 union _ustctl_basic_type {
361 struct ustctl_integer_type integer;
362 struct {
363 char name[LTTNG_UST_SYM_NAME_LEN];
364 struct ustctl_integer_type container_type;
365 uint64_t id; /* enum ID in sessiond. */
366 } enumeration;
367 struct {
368 int32_t encoding; /* enum ustctl_string_encodings */
369 } string;
370 struct ustctl_float_type _float;
371 char padding[USTCTL_UST_BASIC_TYPE_PADDING];
372 } LTTNG_PACKED;
373
374 /* legacy */
375 struct ustctl_basic_type {
376 enum ustctl_abstract_types atype;
377 union {
378 union _ustctl_basic_type basic;
379 } u;
380 } LTTNG_PACKED;
381
382 /*
383 * Padding is derived from largest member: u.legacy.sequence which
384 * contains two basic types, each with USTCTL_UST_BASIC_TYPE_PADDING.
385 */
386 #define USTCTL_UST_TYPE_PADDING (2 * USTCTL_UST_BASIC_TYPE_PADDING)
387 struct ustctl_type {
388 enum ustctl_abstract_types atype;
389 union {
390 struct ustctl_integer_type integer;
391 struct ustctl_float_type _float;
392 struct {
393 int32_t encoding; /* enum ustctl_string_encodings */
394 } string;
395 struct {
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. */
399 } enum_nestable;
400 struct {
401 uint32_t length; /* num. elems. */
402 uint32_t alignment;
403 /* elem_type follows after this struct ustctl_field. */
404 } array_nestable;
405 struct {
406 char length_name[LTTNG_UST_SYM_NAME_LEN];
407 uint32_t alignment; /* Alignment before elements. */
408 /* elem_type follows after the length_type. */
409 } sequence_nestable;
410 struct {
411 uint32_t nr_fields;
412 uint32_t alignment;
413 /* Followed by nr_fields struct ustctl_field. */
414 } struct_nestable;
415 struct {
416 uint32_t nr_choices;
417 char tag_name[LTTNG_UST_SYM_NAME_LEN];
418 uint32_t alignment;
419 /* Followed by nr_choices struct ustctl_field. */
420 } variant_nestable;
421
422 /* Legacy ABI */
423 union {
424 union _ustctl_basic_type basic;
425 struct {
426 struct ustctl_basic_type elem_type;
427 uint32_t length; /* num. elems. */
428 } array;
429 struct {
430 struct ustctl_basic_type length_type;
431 struct ustctl_basic_type elem_type;
432 } sequence;
433 struct {
434 uint32_t nr_fields;
435 /* Followed by nr_fields struct ustctl_field. */
436 } _struct;
437 struct {
438 uint32_t nr_choices;
439 char tag_name[LTTNG_UST_SYM_NAME_LEN];
440 /* Followed by nr_choices struct ustctl_field. */
441 } variant;
442 } legacy;
443 char padding[USTCTL_UST_TYPE_PADDING];
444 } u;
445 } LTTNG_PACKED;
446
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];
452 } LTTNG_PACKED;
453
454 /*
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.
458 */
459 int ustctl_recv_reg_msg(int sock,
460 enum ustctl_socket_type *type,
461 uint32_t *major,
462 uint32_t *minor,
463 uint32_t *pid,
464 uint32_t *ppid,
465 uint32_t *uid,
466 uint32_t *gid,
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,
473 int *byte_order,
474 char *name); /* size LTTNG_UST_ABI_PROCNAME_LEN */
475
476 /*
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
481 * appropriate.
482 */
483 int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd);
484
485 /*
486 * Returns 0 on success, negative UST or system error value on error.
487 */
488 int ustctl_recv_register_event(int sock,
489 int *session_objd, /* session descriptor (output) */
490 int *channel_objd, /* channel descriptor (output) */
491 char *event_name, /*
492 * event name (output,
493 * size LTTNG_UST_SYM_NAME_LEN)
494 */
495 int *loglevel,
496 char **signature, /*
497 * event signature
498 * (output, dynamically
499 * allocated, must be free(3)'d
500 * by the caller if function
501 * returns success.)
502 */
503 size_t *nr_fields,
504 struct ustctl_field **fields,
505 char **model_emf_uri);
506
507 /*
508 * Returns 0 on success, negative error value on error.
509 */
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 */
513
514 /*
515 * Returns 0 on success, negative UST or system error value on error.
516 */
517 int ustctl_recv_register_enum(int sock,
518 int *session_objd,
519 char *enum_name,
520 struct ustctl_enum_entry **entries,
521 size_t *nr_entries);
522
523 /*
524 * Returns 0 on success, negative error value on error.
525 */
526 int ustctl_reply_register_enum(int sock,
527 uint64_t id, /* enum id (input) */
528 int ret_code);
529
530 /*
531 * Returns 0 on success, negative UST or system error value on error.
532 */
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);
538
539 /*
540 * Returns 0 on success, negative error value on error.
541 */
542 int ustctl_reply_register_channel(int sock,
543 uint32_t chan_id,
544 enum ustctl_channel_header header_type,
545 int ret_code); /* return code. 0 ok, negative error */
546
547 #endif /* LTTNG_UST_CTL_INTERNAL_H */
This page took 0.040578 seconds and 5 git commands to generate.