Refactoring: add back constness of public API structures
[lttng-ust.git] / include / lttng / ust-events.h
CommitLineData
8020ceb5 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
8020ceb5 3 *
c0c0989a 4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8020ceb5
MD
5 *
6 * Holds LTTng per-session event registry.
8020ceb5
MD
7 */
8
c0c0989a
MJ
9#ifndef _LTTNG_UST_EVENTS_H
10#define _LTTNG_UST_EVENTS_H
11
b4051ad8 12#include <stddef.h>
9f3fdbc6 13#include <stdint.h>
4318ae1b
MD
14#include <lttng/ust-abi.h>
15#include <lttng/ust-tracer.h>
2ae57758 16#include <lttng/ust-endian.h>
20f1eee7 17#include <float.h>
d58d1454
MD
18#include <errno.h>
19#include <urcu/ref.h>
20#include <pthread.h>
9af5d97a 21#include <limits.h>
8020ceb5 22
6453d237
MD
23#ifdef __cplusplus
24extern "C" {
25#endif
26
19d8b1b3
MD
27#define LTTNG_UST_UUID_LEN 16
28
71d31690
MD
29/*
30 * Tracepoint provider version. Compatibility based on the major number.
31 * Older tracepoint providers can always register to newer lttng-ust
32 * library, but the opposite is rejected: a newer tracepoint provider is
33 * rejected by an older lttng-ust library.
34 */
04f0b55a 35#define LTTNG_UST_PROVIDER_MAJOR 2
71d31690
MD
36#define LTTNG_UST_PROVIDER_MINOR 0
37
e7bc0ef6 38struct lttng_ust_channel_buffer;
f69fe5fb 39struct lttng_ust_session;
4cfec15c 40struct lttng_ust_lib_ring_buffer_ctx;
25cff019 41struct lttng_ust_event_field;
4e48b5d2 42struct lttng_ust_registered_probe;
8020ceb5 43
37d5e202
MD
44/*
45 * Data structures used by tracepoint event declarations, and by the
a084756d 46 * tracer.
37d5e202
MD
47 */
48
8020ceb5
MD
49/* Type description */
50
a084756d
MD
51enum lttng_ust_type {
52 lttng_ust_type_integer,
53 lttng_ust_type_string,
54 lttng_ust_type_float,
55 lttng_ust_type_dynamic,
56 lttng_ust_type_enum,
57 lttng_ust_type_array,
58 lttng_ust_type_sequence,
59 lttng_ust_type_struct,
60 NR_LTTNG_UST_TYPE,
8020ceb5
MD
61};
62
a084756d
MD
63enum lttng_ust_string_encoding {
64 lttng_ust_string_encoding_none = 0,
65 lttng_ust_string_encoding_UTF8 = 1,
66 lttng_ust_string_encoding_ASCII = 2,
67 NR_LTTNG_UST_STRING_ENCODING,
8020ceb5
MD
68};
69
1a37a873 70struct lttng_ust_enum_value {
a6f80644
MD
71 unsigned long long value;
72 unsigned int signedness:1;
73};
74
1a37a873
MD
75enum lttng_ust_enum_entry_option {
76 LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
3e762260
PP
77};
78
891d6b55
MD
79/*
80 * Enumeration entry description
81 *
82 * IMPORTANT: this structure is part of the ABI between the probe and
83 * UST. Fields need to be only added at the end, never reordered, never
84 * removed.
85 *
86 * The field @struct_size should be used to determine the size of the
87 * structure. It should be queried before using additional fields added
88 * at the end of the structure.
89 */
90
91struct lttng_ust_enum_entry {
92 uint32_t struct_size;
93
1a37a873 94 struct lttng_ust_enum_value start, end; /* start and end are inclusive */
8020ceb5 95 const char *string;
891d6b55
MD
96 unsigned int options;
97
98 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
99};
100
a084756d
MD
101/*
102 * struct lttng_ust_type_common is fixed-size. Its children inherits
103 * from it by embedding struct lttng_ust_type_common as its first field.
104 */
105struct lttng_ust_type_common {
106 enum lttng_ust_type type;
107};
108
109struct lttng_ust_type_integer {
110 struct lttng_ust_type_common parent;
111 uint32_t struct_size;
8020ceb5
MD
112 unsigned int size; /* in bits */
113 unsigned short alignment; /* in bits */
114 unsigned int signedness:1;
115 unsigned int reverse_byte_order:1;
116 unsigned int base; /* 2, 8, 10, 16, for pretty print */
a084756d
MD
117};
118
119#define lttng_ust_type_integer_define(_type, _byte_order, _base) \
120 ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_integer, { \
121 .parent = { \
122 .type = lttng_ust_type_integer, \
123 }, \
124 .struct_size = sizeof(struct lttng_ust_type_integer), \
125 .size = sizeof(_type) * CHAR_BIT, \
dc325c1d 126 .alignment = lttng_ust_rb_alignof(_type) * CHAR_BIT, \
eae3c729 127 .signedness = lttng_ust_is_signed_type(_type), \
a084756d
MD
128 .reverse_byte_order = _byte_order != BYTE_ORDER, \
129 .base = _base, \
130 }))
131
132struct lttng_ust_type_float {
133 struct lttng_ust_type_common parent;
134 uint32_t struct_size;
135 unsigned int exp_dig; /* exponent digits, in bits */
136 unsigned int mant_dig; /* mantissa digits, in bits */
137 unsigned short alignment; /* in bits */
138 unsigned int reverse_byte_order:1;
8020ceb5
MD
139};
140
d3ed854b
MD
141/*
142 * Only float and double are supported. long double is not supported at
143 * the moment.
144 */
89080a49 145#define lttng_ust_float_mant_dig(_type) \
20f1eee7
MD
146 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
147 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
d3ed854b 148 : 0))
20f1eee7 149
a084756d
MD
150#define lttng_ust_type_float_define(_type) \
151 ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_float, { \
152 .parent = { \
153 .type = lttng_ust_type_float, \
154 }, \
155 .struct_size = sizeof(struct lttng_ust_type_float), \
156 .exp_dig = sizeof(_type) * CHAR_BIT \
89080a49
MD
157 - lttng_ust_float_mant_dig(_type), \
158 .mant_dig = lttng_ust_float_mant_dig(_type), \
dc325c1d 159 .alignment = lttng_ust_rb_alignof(_type) * CHAR_BIT, \
a084756d
MD
160 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
161 }))
162
163
164struct lttng_ust_type_string {
165 struct lttng_ust_type_common parent;
166 uint32_t struct_size;
167 enum lttng_ust_string_encoding encoding;
20f1eee7
MD
168};
169
a084756d
MD
170struct lttng_ust_type_enum {
171 struct lttng_ust_type_common parent;
172 uint32_t struct_size;
4e48b5d2
MD
173 const struct lttng_ust_enum_desc *desc; /* Enumeration mapping */
174 const struct lttng_ust_type_common *container_type;
a084756d
MD
175};
176
177struct lttng_ust_type_array {
178 struct lttng_ust_type_common parent;
179 uint32_t struct_size;
4e48b5d2 180 const struct lttng_ust_type_common *elem_type;
a084756d
MD
181 unsigned int length; /* Num. elems. */
182 unsigned int alignment;
183 enum lttng_ust_string_encoding encoding;
184};
185
186struct lttng_ust_type_sequence {
187 struct lttng_ust_type_common parent;
188 uint32_t struct_size;
189 const char *length_name; /* Length field name. */
4e48b5d2 190 const struct lttng_ust_type_common *elem_type;
a084756d
MD
191 unsigned int alignment; /* Alignment before elements. */
192 enum lttng_ust_string_encoding encoding;
193};
194
195struct lttng_ust_type_struct {
196 struct lttng_ust_type_common parent;
197 uint32_t struct_size;
198 unsigned int nr_fields;
4e48b5d2 199 const struct lttng_ust_event_field **fields; /* Array of pointers to fields. */
a084756d 200 unsigned int alignment;
8020ceb5
MD
201};
202
891d6b55
MD
203/*
204 * Enumeration description
205 *
206 * IMPORTANT: this structure is part of the ABI between the probe and
207 * UST. Fields need to be only added at the end, never reordered, never
208 * removed.
209 *
210 * The field @struct_size should be used to determine the size of the
211 * structure. It should be queried before using additional fields added
212 * at the end of the structure.
213 */
214
215struct lttng_ust_enum_desc {
216 uint32_t struct_size;
217
8020ceb5 218 const char *name;
4e48b5d2 219 const struct lttng_ust_enum_entry **entries;
c785c634 220 unsigned int nr_entries;
891d6b55
MD
221
222 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
223};
224
180901e6
MD
225/*
226 * Event field description
227 *
228 * IMPORTANT: this structure is part of the ABI between the probe and
229 * UST. Fields need to be only added at the end, never reordered, never
230 * removed.
25cff019
MD
231 *
232 * The field @struct_size should be used to determine the size of the
233 * structure. It should be queried before using additional fields added
234 * at the end of the structure.
180901e6 235 */
8020ceb5 236
25cff019
MD
237struct lttng_ust_event_field {
238 uint32_t struct_size;
239
8020ceb5 240 const char *name;
4e48b5d2 241 const struct lttng_ust_type_common *type;
25cff019
MD
242 unsigned int nowrite:1, /* do not write into trace */
243 nofilter:1; /* do not consider for filter */
244
245 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
246};
247
37d5e202 248
dc11f93f
MD
249/*
250 * IMPORTANT: this structure is part of the ABI between the probe and
251 * UST. Fields need to be only added at the end, never reordered, never
252 * removed.
253 *
254 * The field @struct_size should be used to determine the size of the
255 * structure. It should be queried before using additional fields added
256 * at the end of the structure.
257 */
258struct lttng_ust_event_desc {
4e48b5d2 259 uint32_t struct_size; /* Size of this structure. */
dc177d11 260
5b4c6da4 261 const char *event_name;
4e48b5d2 262 const struct lttng_ust_probe_desc *probe_desc;
fbdeb5ec 263 void (*probe_callback)(void);
4e48b5d2 264 const struct lttng_ust_event_field **fields; /* event payload */
37d5e202
MD
265 unsigned int nr_fields;
266 const int **loglevel;
4e48b5d2 267 const char *signature; /* Argument types/names received */
dc11f93f
MD
268 const char **model_emf_uri;
269
270 /* End of base ABI. Fields below should be used after checking struct_size. */
37d5e202
MD
271};
272
dc11f93f
MD
273/*
274 * IMPORTANT: this structure is part of the ABI between the probe and
275 * UST. Fields need to be only added at the end, never reordered, never
276 * removed.
277 *
278 * The field @struct_size should be used to determine the size of the
279 * structure. It should be queried before using additional fields added
280 * at the end of the structure.
281 */
282struct lttng_ust_probe_desc {
283 uint32_t struct_size; /* Size of this structure. */
284
5b4c6da4 285 const char *provider_name;
4e48b5d2 286 const struct lttng_ust_event_desc **event_desc;
37d5e202 287 unsigned int nr_events;
71d31690
MD
288 uint32_t major;
289 uint32_t minor;
dc11f93f
MD
290
291 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
292};
293
37d5e202
MD
294/* Data structures used by the tracer. */
295
8020ceb5 296/*
7dd08bec
MD
297 * lttng_event structure is referred to by the tracing fast path. It
298 * must be kept small.
180901e6
MD
299 *
300 * IMPORTANT: this structure is part of the ABI between the probe and
301 * UST. Fields need to be only added at the end, never reordered, never
302 * removed.
8020ceb5 303 */
68bb7559 304
80333dfa
MD
305struct lttng_ust_event_common_private;
306
808edfc8
MD
307enum lttng_ust_event_type {
308 LTTNG_UST_EVENT_TYPE_RECORDER = 0,
309 LTTNG_UST_EVENT_TYPE_NOTIFIER = 1,
310};
311
a2e4d05e
MD
312/*
313 * Result of the run_filter() callback.
314 */
315enum lttng_ust_event_filter_result {
316 LTTNG_UST_EVENT_FILTER_ACCEPT = 0,
317 LTTNG_UST_EVENT_FILTER_REJECT = 1,
318};
319
93cfd247 320/*
6d35572a
MD
321 * IMPORTANT: this structure is part of the ABI between the probe and
322 * UST. Fields need to be only added at the end, never reordered, never
323 * removed.
324 *
93cfd247
MD
325 * struct lttng_ust_event_common is the common ancestor of the various
326 * public event actions. Inheritance is done by composition: The parent
327 * has a pointer to its child, and the child has a pointer to its
328 * parent. Inheritance of those public structures is done by composition
329 * to ensure both parent and child structures can be extended.
330 *
331 * The field @struct_size should be used to determine the size of the
332 * structure. It should be queried before using additional fields added
333 * at the end of the structure.
334 */
7ee76145 335struct lttng_ust_event_common {
80333dfa 336 uint32_t struct_size; /* Size of this structure. */
dc177d11 337
80333dfa
MD
338 struct lttng_ust_event_common_private *priv; /* Private event interface */
339
808edfc8 340 enum lttng_ust_event_type type;
ba99fbe2
MD
341 void *child; /* Pointer to child, for inheritance by aggregation. */
342
80333dfa 343 int enabled;
a2e4d05e
MD
344 int eval_filter; /* Need to evaluate filters */
345 int (*run_filter)(struct lttng_ust_event_common *event,
346 const char *stack_data,
347 void *filter_ctx);
93cfd247
MD
348
349 /* End of base ABI. Fields below should be used after checking struct_size. */
80333dfa
MD
350};
351
2e70391c 352struct lttng_ust_event_recorder_private;
68bb7559 353
93cfd247 354/*
6d35572a
MD
355 * IMPORTANT: this structure is part of the ABI between the probe and
356 * UST. Fields need to be only added at the end, never reordered, never
357 * removed.
358 *
93cfd247
MD
359 * struct lttng_ust_event_recorder is the action for recording events
360 * into a ring buffer. It inherits from struct lttng_ust_event_common
361 * by composition to ensure both parent and child structure are
362 * extensible.
363 *
364 * The field @struct_size should be used to determine the size of the
365 * structure. It should be queried before using additional fields added
366 * at the end of the structure.
367 */
2e70391c
MD
368struct lttng_ust_event_recorder {
369 uint32_t struct_size; /* Size of this structure. */
dc177d11 370
ba99fbe2 371 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
2e70391c 372 struct lttng_ust_event_recorder_private *priv; /* Private event record interface */
68bb7559 373
e7bc0ef6 374 struct lttng_ust_channel_buffer *chan;
93cfd247
MD
375
376 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
377};
378
a2e4d05e
MD
379/*
380 * IMPORTANT: this structure is part of the ABI between the probe and
381 * UST. Fields need to be only added at the end, never reordered, never
382 * removed.
383 *
384 * The field @struct_size should be used to determine the size of the
385 * structure. It should be queried before using additional fields added
386 * at the end of the structure.
387 */
388struct lttng_ust_notification_ctx {
389 uint32_t struct_size; /* Size of this structure. */
390 int eval_capture; /* Capture evaluation available. */
391
392 /* End of base ABI. Fields below should be used after checking struct_size. */
393};
394
115db533
MD
395struct lttng_ust_event_notifier_private;
396
93cfd247 397/*
6d35572a
MD
398 * IMPORTANT: this structure is part of the ABI between the probe and
399 * UST. Fields need to be only added at the end, never reordered, never
400 * removed.
401 *
93cfd247
MD
402 * struct lttng_ust_event_notifier is the action for sending
403 * notifications. It inherits from struct lttng_ust_event_common
404 * by composition to ensure both parent and child structure are
405 * extensible.
406 *
407 * The field @struct_size should be used to determine the size of the
408 * structure. It should be queried before using additional fields added
409 * at the end of the structure.
410 */
d7d45c0d 411struct lttng_ust_event_notifier {
115db533 412 uint32_t struct_size; /* Size of this structure. */
105cf2eb 413
ba99fbe2 414 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
115db533
MD
415 struct lttng_ust_event_notifier_private *priv; /* Private event notifier interface */
416
a2e4d05e 417 int eval_capture; /* Need to evaluate capture */
d7d45c0d 418 void (*notification_send)(struct lttng_ust_event_notifier *event_notifier,
a2e4d05e
MD
419 const char *stack_data,
420 struct lttng_ust_notification_ctx *notif_ctx);
93cfd247
MD
421
422 /* End of base ABI. Fields below should be used after checking struct_size. */
d8d2416d
FD
423};
424
5198080d 425struct lttng_ust_lib_ring_buffer_channel;
14b6f891 426struct lttng_ust_channel_buffer_ops_private;
8d8a24c8 427
180901e6
MD
428/*
429 * IMPORTANT: this structure is part of the ABI between the probe and
430 * UST. Fields need to be only added at the end, never reordered, never
431 * removed.
49926dbd
MD
432 *
433 * The field @struct_size should be used to determine the size of the
434 * structure. It should be queried before using additional fields added
435 * at the end of the structure.
180901e6 436 */
14b6f891 437struct lttng_ust_channel_buffer_ops {
49926dbd
MD
438 uint32_t struct_size;
439
14b6f891 440 struct lttng_ust_channel_buffer_ops_private *priv; /* Private channel buffer ops interface */
a880bae5 441
8936b6c0 442 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
4cfec15c 443 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
74d81a6c 444 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
8936b6c0 445 const void *src, size_t len, size_t alignment);
a44c74d9
MD
446 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
447 const char *src, size_t len);
879f9b0a 448 void (*event_pstrcpy_pad)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
27927814 449 const char *src, size_t len);
49926dbd
MD
450
451 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
452};
453
e7bc0ef6
MD
454enum lttng_ust_channel_type {
455 LTTNG_UST_CHANNEL_TYPE_BUFFER = 0,
456};
457
458struct lttng_ust_channel_common_private;
459
180901e6
MD
460/*
461 * IMPORTANT: this structure is part of the ABI between the probe and
462 * UST. Fields need to be only added at the end, never reordered, never
463 * removed.
e7bc0ef6
MD
464 *
465 * The field @struct_size should be used to determine the size of the
466 * structure. It should be queried before using additional fields added
467 * at the end of the structure.
180901e6 468 */
e7bc0ef6
MD
469struct lttng_ust_channel_common {
470 uint32_t struct_size; /* Size of this structure. */
471
472 struct lttng_ust_channel_common_private *priv; /* Private channel interface */
473
474 enum lttng_ust_channel_type type;
475 void *child; /* Pointer to child, for inheritance by aggregation. */
476
976fe9ea 477 int enabled;
f69fe5fb 478 struct lttng_ust_session *session;
e7bc0ef6
MD
479
480 /* End of base ABI. Fields below should be used after checking struct_size. */
481};
482
483struct lttng_ust_channel_buffer_private;
484
485/*
486 * IMPORTANT: this structure is part of the ABI between the probe and
487 * UST. Fields need to be only added at the end, never reordered, never
488 * removed.
489 *
490 * The field @struct_size should be used to determine the size of the
491 * structure. It should be queried before using additional fields added
492 * at the end of the structure.
493 */
494struct lttng_ust_channel_buffer {
495 uint32_t struct_size; /* Size of this structure. */
496
497 struct lttng_ust_channel_common *parent; /* Inheritance by aggregation. */
498 struct lttng_ust_channel_buffer_private *priv; /* Private channel buffer interface */
499
14b6f891 500 struct lttng_ust_channel_buffer_ops *ops;
a3f61e7f 501
e7bc0ef6 502 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
503};
504
2a9d9339
MD
505/*
506 * IMPORTANT: this structure is part of the ABI between the probe and
507 * UST. Fields need to be only added at the end, never reordered, never
508 * removed.
509 *
510 * The field @struct_size should be used to determine the size of the
511 * structure. It should be queried before using additional fields added
512 * at the end of the structure.
513 */
514struct lttng_ust_stack_ctx {
515 uint32_t struct_size; /* Size of this structure */
516
2e70391c 517 struct lttng_ust_event_recorder *event_recorder;
2a9d9339
MD
518
519 /* End of base ABI. Fields below should be used after checking struct_size. */
53569322
MD
520};
521
bdb12629
MD
522struct lttng_ust_session_private;
523
180901e6
MD
524/*
525 * IMPORTANT: this structure is part of the ABI between the probe and
526 * UST. Fields need to be only added at the end, never reordered, never
527 * removed.
6d35572a
MD
528 *
529 * The field @struct_size should be used to determine the size of the
530 * structure. It should be queried before using additional fields added
531 * at the end of the structure.
180901e6 532 */
f69fe5fb 533struct lttng_ust_session {
bd640d74 534 uint32_t struct_size; /* Size of this structure */
dc177d11 535
bdb12629
MD
536 struct lttng_ust_session_private *priv; /* Private session interface */
537
e58095ef 538 int active; /* Is trace session active ? */
6d35572a
MD
539
540 /* End of base ABI. Fields below should be used after checking struct_size. */
8020ceb5
MD
541};
542
4e48b5d2
MD
543/*
544 * On successful registration of a probe, a pointer to an opaque
545 * structure is returned. This pointer should be passed to
546 * lttng_ust_probe_unregister for unregistration.
547 * lttng_ust_probe_register returns NULL on error.
548 */
549struct lttng_ust_registered_probe *lttng_ust_probe_register(const struct lttng_ust_probe_desc *desc);
550
551void lttng_ust_probe_unregister(struct lttng_ust_registered_probe *reg_probe);
9f3fdbc6 552
fc80554e 553/*
0af0bdb2
MJ
554 * Applications that change their procname and need the new value to be
555 * reflected in the procname event context have to call this function to clear
556 * the internally cached value. This should not be called from a signal
557 * handler.
fc80554e 558 */
0af0bdb2 559void lttng_ust_context_procname_reset(void);
d58d1454 560
6453d237
MD
561#ifdef __cplusplus
562}
563#endif
564
51489cad 565#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.073103 seconds and 4 git commands to generate.