Refactoring: struct lttng_event_desc and lttng_probe_desc
[lttng-ust.git] / include / lttng / ust-events.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng per-session event registry.
7 */
8
9 #ifndef _LTTNG_UST_EVENTS_H
10 #define _LTTNG_UST_EVENTS_H
11
12 #include <urcu/list.h>
13 #include <urcu/hlist.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <lttng/ust-abi.h>
17 #include <lttng/ust-tracer.h>
18 #include <lttng/ust-endian.h>
19 #include <float.h>
20 #include <errno.h>
21 #include <urcu/ref.h>
22 #include <pthread.h>
23
24 #ifndef LTTNG_PACKED
25 #error "LTTNG_PACKED should be defined"
26 #endif
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #define LTTNG_UST_UUID_LEN 16
33
34 /*
35 * Tracepoint provider version. Compatibility based on the major number.
36 * Older tracepoint providers can always register to newer lttng-ust
37 * library, but the opposite is rejected: a newer tracepoint provider is
38 * rejected by an older lttng-ust library.
39 */
40 #define LTTNG_UST_PROVIDER_MAJOR 2
41 #define LTTNG_UST_PROVIDER_MINOR 0
42
43 struct lttng_channel;
44 struct lttng_session;
45 struct lttng_ust_lib_ring_buffer_ctx;
46 struct lttng_event_field;
47 struct lttng_event_notifier_group;
48
49 /*
50 * Data structures used by tracepoint event declarations, and by the
51 * tracer. Those structures have padding for future extension.
52 */
53
54 /* Type description */
55
56 /* Update the astract_types name table in lttng-types.c along with this enum */
57 enum lttng_abstract_types {
58 atype_integer,
59 atype_string,
60 atype_float,
61 atype_dynamic,
62 atype_enum_nestable,
63 atype_array_nestable,
64 atype_sequence_nestable,
65 atype_struct_nestable,
66 NR_ABSTRACT_TYPES,
67 };
68
69 /* Update the string_encodings name table in lttng-types.c along with this enum */
70 enum lttng_string_encodings {
71 lttng_encode_none = 0,
72 lttng_encode_UTF8 = 1,
73 lttng_encode_ASCII = 2,
74 NR_STRING_ENCODINGS,
75 };
76
77 struct lttng_enum_value {
78 unsigned long long value;
79 unsigned int signedness:1;
80 };
81
82 enum lttng_enum_entry_options {
83 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
84 };
85
86 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
87 struct lttng_enum_entry {
88 struct lttng_enum_value start, end; /* start and end are inclusive */
89 const char *string;
90 union {
91 struct {
92 unsigned int options;
93 } LTTNG_PACKED extra;
94 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
95 } u;
96 };
97
98 #define __type_integer(_type, _byte_order, _base, _encoding) \
99 { \
100 .atype = atype_integer, \
101 .u = \
102 { \
103 .integer = \
104 { \
105 .size = sizeof(_type) * CHAR_BIT, \
106 .alignment = lttng_alignof(_type) * CHAR_BIT, \
107 .signedness = lttng_is_signed_type(_type), \
108 .reverse_byte_order = _byte_order != BYTE_ORDER, \
109 .base = _base, \
110 .encoding = lttng_encode_##_encoding, \
111 } \
112 }, \
113 } \
114
115 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
116 struct lttng_integer_type {
117 unsigned int size; /* in bits */
118 unsigned short alignment; /* in bits */
119 unsigned int signedness:1;
120 unsigned int reverse_byte_order:1;
121 unsigned int base; /* 2, 8, 10, 16, for pretty print */
122 enum lttng_string_encodings encoding;
123 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
124 };
125
126 /*
127 * Only float and double are supported. long double is not supported at
128 * the moment.
129 */
130 #define _float_mant_dig(_type) \
131 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
132 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
133 : 0))
134
135 #define __type_float(_type) \
136 { \
137 .atype = atype_float, \
138 .u = \
139 { \
140 ._float = \
141 { \
142 .exp_dig = sizeof(_type) * CHAR_BIT \
143 - _float_mant_dig(_type), \
144 .mant_dig = _float_mant_dig(_type), \
145 .alignment = lttng_alignof(_type) * CHAR_BIT, \
146 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
147 } \
148 } \
149 } \
150
151 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
152 struct lttng_float_type {
153 unsigned int exp_dig; /* exponent digits, in bits */
154 unsigned int mant_dig; /* mantissa digits, in bits */
155 unsigned short alignment; /* in bits */
156 unsigned int reverse_byte_order:1;
157 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
158 };
159
160 #define LTTNG_UST_TYPE_PADDING 128
161 struct lttng_type {
162 enum lttng_abstract_types atype;
163 union {
164 /* provider ABI 2.0 */
165 struct lttng_integer_type integer;
166 struct lttng_float_type _float;
167 struct {
168 enum lttng_string_encodings encoding;
169 } string;
170 struct {
171 const struct lttng_enum_desc *desc; /* Enumeration mapping */
172 struct lttng_type *container_type;
173 } enum_nestable;
174 struct {
175 const struct lttng_type *elem_type;
176 unsigned int length; /* Num. elems. */
177 unsigned int alignment;
178 } array_nestable;
179 struct {
180 const char *length_name; /* Length field name. */
181 const struct lttng_type *elem_type;
182 unsigned int alignment; /* Alignment before elements. */
183 } sequence_nestable;
184 struct {
185 unsigned int nr_fields;
186 const struct lttng_event_field *fields; /* Array of fields. */
187 unsigned int alignment;
188 } struct_nestable;
189
190 char padding[LTTNG_UST_TYPE_PADDING];
191 } u;
192 };
193
194 #define LTTNG_UST_ENUM_TYPE_PADDING 24
195 struct lttng_enum_desc {
196 const char *name;
197 const struct lttng_enum_entry *entries;
198 unsigned int nr_entries;
199 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
200 };
201
202 /*
203 * Event field description
204 *
205 * IMPORTANT: this structure is part of the ABI between the probe and
206 * UST. Fields need to be only added at the end, never reordered, never
207 * removed.
208 */
209
210 #define LTTNG_UST_EVENT_FIELD_PADDING 28
211 struct lttng_event_field {
212 const char *name;
213 struct lttng_type type;
214 unsigned int nowrite; /* do not write into trace */
215 union {
216 struct {
217 unsigned int nofilter:1; /* do not consider for filter */
218 } ext;
219 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
220 } u;
221 };
222
223 enum lttng_ust_dynamic_type {
224 LTTNG_UST_DYNAMIC_TYPE_NONE,
225 LTTNG_UST_DYNAMIC_TYPE_S8,
226 LTTNG_UST_DYNAMIC_TYPE_S16,
227 LTTNG_UST_DYNAMIC_TYPE_S32,
228 LTTNG_UST_DYNAMIC_TYPE_S64,
229 LTTNG_UST_DYNAMIC_TYPE_U8,
230 LTTNG_UST_DYNAMIC_TYPE_U16,
231 LTTNG_UST_DYNAMIC_TYPE_U32,
232 LTTNG_UST_DYNAMIC_TYPE_U64,
233 LTTNG_UST_DYNAMIC_TYPE_FLOAT,
234 LTTNG_UST_DYNAMIC_TYPE_DOUBLE,
235 LTTNG_UST_DYNAMIC_TYPE_STRING,
236 _NR_LTTNG_UST_DYNAMIC_TYPES,
237 };
238
239 struct lttng_ctx_value {
240 enum lttng_ust_dynamic_type sel;
241 union {
242 int64_t s64;
243 uint64_t u64;
244 const char *str;
245 double d;
246 } u;
247 };
248
249 struct lttng_perf_counter_field;
250
251 #define LTTNG_UST_CTX_FIELD_PADDING 40
252 struct lttng_ctx_field {
253 struct lttng_event_field event_field;
254 size_t (*get_size)(struct lttng_ctx_field *field, size_t offset);
255 void (*record)(struct lttng_ctx_field *field,
256 struct lttng_ust_lib_ring_buffer_ctx *ctx,
257 struct lttng_channel *chan);
258 void (*get_value)(struct lttng_ctx_field *field,
259 struct lttng_ctx_value *value);
260 union {
261 struct lttng_perf_counter_field *perf_counter;
262 char padding[LTTNG_UST_CTX_FIELD_PADDING];
263 } u;
264 void (*destroy)(struct lttng_ctx_field *field);
265 char *field_name; /* Has ownership, dynamically allocated. */
266 };
267
268 #define LTTNG_UST_CTX_PADDING 20
269 struct lttng_ctx {
270 struct lttng_ctx_field *fields;
271 unsigned int nr_fields;
272 unsigned int allocated_fields;
273 unsigned int largest_align;
274 char padding[LTTNG_UST_CTX_PADDING];
275 };
276
277 /*
278 * IMPORTANT: this structure is part of the ABI between the probe and
279 * UST. Fields need to be only added at the end, never reordered, never
280 * removed.
281 *
282 * The field @struct_size should be used to determine the size of the
283 * structure. It should be queried before using additional fields added
284 * at the end of the structure.
285 */
286 struct lttng_ust_event_desc {
287 uint32_t struct_size; /* Size of this structure. */
288 const char *name;
289 void (*probe_callback)(void);
290 const struct lttng_event_ctx *ctx; /* context */
291 const struct lttng_event_field *fields; /* event payload */
292 unsigned int nr_fields;
293 const int **loglevel;
294 const char *signature; /* Argument types/names received */
295 const char **model_emf_uri;
296
297 /* End of base ABI. Fields below should be used after checking struct_size. */
298 };
299
300 /*
301 * IMPORTANT: this structure is part of the ABI between the probe and
302 * UST. Fields need to be only added at the end, never reordered, never
303 * removed.
304 *
305 * The field @struct_size should be used to determine the size of the
306 * structure. It should be queried before using additional fields added
307 * at the end of the structure.
308 */
309 struct lttng_ust_probe_desc {
310 uint32_t struct_size; /* Size of this structure. */
311
312 const char *provider;
313 const struct lttng_ust_event_desc **event_desc;
314 unsigned int nr_events;
315 struct cds_list_head head; /* chain registered probes */
316 struct cds_list_head lazy_init_head;
317 int lazy; /* lazy registration */
318 uint32_t major;
319 uint32_t minor;
320
321 /* End of base ABI. Fields below should be used after checking struct_size. */
322 };
323
324 /* Data structures used by the tracer. */
325
326 /*
327 * Bytecode interpreter return value masks.
328 */
329 enum lttng_bytecode_interpreter_ret {
330 LTTNG_INTERPRETER_DISCARD = 0,
331 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
332 /* Other bits are kept for future use. */
333 };
334
335 struct lttng_interpreter_output;
336 struct lttng_ust_bytecode_runtime_private;
337
338 /*
339 * This structure is used in the probes. More specifically, the
340 * `interpreter_funcs` and `node` fields are explicity used in the
341 * probes. When modifying this structure we must not change the layout
342 * of these two fields as it is considered ABI.
343 */
344 struct lttng_bytecode_runtime {
345 struct lttng_ust_bytecode_runtime_private *priv;
346
347 /* Associated bytecode */
348 union {
349 uint64_t (*filter)(void *interpreter_data,
350 const char *interpreter_stack_data);
351 uint64_t (*capture)(void *interpreter_data,
352 const char *interpreter_stack_data,
353 struct lttng_interpreter_output *interpreter_output);
354 } interpreter_funcs;
355 struct cds_list_head node; /* list of bytecode runtime in event */
356 };
357
358 /*
359 * lttng_event structure is referred to by the tracing fast path. It
360 * must be kept small.
361 *
362 * IMPORTANT: this structure is part of the ABI between the probe and
363 * UST. Fields need to be only added at the end, never reordered, never
364 * removed.
365 */
366
367 struct lttng_ust_event_common_private;
368
369 enum lttng_ust_event_type {
370 LTTNG_UST_EVENT_TYPE_RECORDER = 0,
371 LTTNG_UST_EVENT_TYPE_NOTIFIER = 1,
372 };
373
374 /*
375 * IMPORTANT: this structure is part of the ABI between the probe and
376 * UST. Fields need to be only added at the end, never reordered, never
377 * removed.
378 *
379 * struct lttng_ust_event_common is the common ancestor of the various
380 * public event actions. Inheritance is done by composition: The parent
381 * has a pointer to its child, and the child has a pointer to its
382 * parent. Inheritance of those public structures is done by composition
383 * to ensure both parent and child structures can be extended.
384 *
385 * The field @struct_size should be used to determine the size of the
386 * structure. It should be queried before using additional fields added
387 * at the end of the structure.
388 */
389 struct lttng_ust_event_common {
390 uint32_t struct_size; /* Size of this structure. */
391 struct lttng_ust_event_common_private *priv; /* Private event interface */
392
393 enum lttng_ust_event_type type;
394 void *child; /* Pointer to child, for inheritance by aggregation. */
395
396 int enabled;
397 int has_enablers_without_bytecode;
398 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
399 struct cds_list_head filter_bytecode_runtime_head;
400
401 /* End of base ABI. Fields below should be used after checking struct_size. */
402 };
403
404 struct lttng_ust_event_recorder_private;
405
406 /*
407 * IMPORTANT: this structure is part of the ABI between the probe and
408 * UST. Fields need to be only added at the end, never reordered, never
409 * removed.
410 *
411 * struct lttng_ust_event_recorder is the action for recording events
412 * into a ring buffer. It inherits from struct lttng_ust_event_common
413 * by composition to ensure both parent and child structure are
414 * extensible.
415 *
416 * The field @struct_size should be used to determine the size of the
417 * structure. It should be queried before using additional fields added
418 * at the end of the structure.
419 */
420 struct lttng_ust_event_recorder {
421 uint32_t struct_size; /* Size of this structure. */
422 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
423 struct lttng_ust_event_recorder_private *priv; /* Private event record interface */
424
425 unsigned int id;
426 struct lttng_channel *chan;
427 struct lttng_ctx *ctx;
428
429 /* End of base ABI. Fields below should be used after checking struct_size. */
430 };
431
432 struct lttng_ust_event_notifier_private;
433
434 /*
435 * IMPORTANT: this structure is part of the ABI between the probe and
436 * UST. Fields need to be only added at the end, never reordered, never
437 * removed.
438 *
439 * struct lttng_ust_event_notifier is the action for sending
440 * notifications. It inherits from struct lttng_ust_event_common
441 * by composition to ensure both parent and child structure are
442 * extensible.
443 *
444 * The field @struct_size should be used to determine the size of the
445 * structure. It should be queried before using additional fields added
446 * at the end of the structure.
447 */
448 struct lttng_ust_event_notifier {
449 uint32_t struct_size; /* Size of this structure. */
450 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
451 struct lttng_ust_event_notifier_private *priv; /* Private event notifier interface */
452
453 void (*notification_send)(struct lttng_ust_event_notifier *event_notifier,
454 const char *stack_data);
455 struct cds_list_head capture_bytecode_runtime_head;
456
457 /* End of base ABI. Fields below should be used after checking struct_size. */
458 };
459
460 struct lttng_enum {
461 const struct lttng_enum_desc *desc;
462 struct lttng_session *session;
463 struct cds_list_head node; /* Enum list in session */
464 struct cds_hlist_node hlist; /* Session ht of enums */
465 uint64_t id; /* Enumeration ID in sessiond */
466 };
467
468 struct channel;
469 struct lttng_ust_shm_handle;
470
471 /*
472 * IMPORTANT: this structure is part of the ABI between the probe and
473 * UST. Fields need to be only added at the end, never reordered, never
474 * removed.
475 */
476 struct lttng_channel_ops {
477 struct lttng_channel *(*channel_create)(const char *name,
478 void *buf_addr,
479 size_t subbuf_size, size_t num_subbuf,
480 unsigned int switch_timer_interval,
481 unsigned int read_timer_interval,
482 unsigned char *uuid,
483 uint32_t chan_id,
484 const int *stream_fds, int nr_stream_fds,
485 int64_t blocking_timeout);
486 void (*channel_destroy)(struct lttng_channel *chan);
487 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
488 uint32_t event_id);
489 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
490 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
491 const void *src, size_t len);
492 /*
493 * packet_avail_size returns the available size in the current
494 * packet. Note that the size returned is only a hint, since it
495 * may change due to concurrent writes.
496 */
497 size_t (*packet_avail_size)(struct channel *chan,
498 struct lttng_ust_shm_handle *handle);
499 int (*is_finalized)(struct channel *chan);
500 int (*is_disabled)(struct channel *chan);
501 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
502 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
503 const char *src, size_t len);
504 };
505
506 /*
507 * IMPORTANT: this structure is part of the ABI between the probe and
508 * UST. Fields need to be only added at the end, never reordered, never
509 * removed.
510 */
511 struct lttng_channel {
512 /*
513 * The pointers located in this private data are NOT safe to be
514 * dereferenced by the consumer. The only operations the
515 * consumer process is designed to be allowed to do is to read
516 * and perform subbuffer flush.
517 */
518 struct channel *chan; /* Channel buffers */
519 int enabled;
520 struct lttng_ctx *ctx;
521 /* Event ID management */
522 struct lttng_session *session;
523 int objd; /* Object associated to channel */
524 struct cds_list_head node; /* Channel list in session */
525 const struct lttng_channel_ops *ops;
526 int header_type; /* 0: unset, 1: compact, 2: large */
527 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
528
529 /* Channel ID */
530 unsigned int id;
531 enum lttng_ust_abi_chan_type type;
532 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
533 int tstate:1; /* Transient enable state */
534 };
535
536 struct lttng_counter_dimension;
537
538 struct lttng_counter_ops {
539 struct lib_counter *(*counter_create)(size_t nr_dimensions,
540 const struct lttng_counter_dimension *dimensions,
541 int64_t global_sum_step,
542 int global_counter_fd,
543 int nr_counter_cpu_fds,
544 const int *counter_cpu_fds,
545 bool is_daemon);
546 void (*counter_destroy)(struct lib_counter *counter);
547 int (*counter_add)(struct lib_counter *counter,
548 const size_t *dimension_indexes, int64_t v);
549 int (*counter_read)(struct lib_counter *counter,
550 const size_t *dimension_indexes, int cpu,
551 int64_t *value, bool *overflow, bool *underflow);
552 int (*counter_aggregate)(struct lib_counter *counter,
553 const size_t *dimension_indexes, int64_t *value,
554 bool *overflow, bool *underflow);
555 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
556 };
557
558 #define LTTNG_UST_STACK_CTX_PADDING 32
559 struct lttng_stack_ctx {
560 struct lttng_ust_event_recorder *event_recorder;
561 struct lttng_ctx *chan_ctx; /* RCU dereferenced. */
562 struct lttng_ctx *event_ctx; /* RCU dereferenced. */
563 char padding[LTTNG_UST_STACK_CTX_PADDING];
564 };
565
566 #define LTTNG_UST_EVENT_HT_BITS 12
567 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
568
569 struct lttng_ust_event_ht {
570 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
571 };
572
573 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
574 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
575 struct lttng_ust_event_notifier_ht {
576 struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
577 };
578
579 #define LTTNG_UST_ENUM_HT_BITS 12
580 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
581
582 struct lttng_ust_enum_ht {
583 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
584 };
585
586 struct lttng_ust_session_private;
587
588 /*
589 * IMPORTANT: this structure is part of the ABI between the probe and
590 * UST. Fields need to be only added at the end, never reordered, never
591 * removed.
592 *
593 * The field @struct_size should be used to determine the size of the
594 * structure. It should be queried before using additional fields added
595 * at the end of the structure.
596 */
597 struct lttng_session {
598 uint32_t struct_size; /* Size of this structure */
599 struct lttng_ust_session_private *priv; /* Private session interface */
600
601 int active; /* Is trace session active ? */
602
603 /* End of base ABI. Fields below should be used after checking struct_size. */
604 };
605
606 int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc);
607 void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc);
608
609 /*
610 * Can be used by applications that change their procname to clear the ust cached value.
611 */
612 void lttng_context_procname_reset(void);
613
614 struct lttng_transport *lttng_transport_find(const char *name);
615
616 int lttng_session_active(void);
617
618 void lttng_ust_dl_update(void *ip);
619
620 #ifdef __cplusplus
621 }
622 #endif
623
624 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.064719 seconds and 4 git commands to generate.