Refactoring: context structures
[lttng-ust.git] / include / lttng / ust-events.h
... / ...
CommitLineData
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
29extern "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
43struct lttng_channel;
44struct lttng_session;
45struct lttng_ust_lib_ring_buffer_ctx;
46struct lttng_ust_event_field;
47struct 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 */
57enum 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 */
70enum lttng_string_encodings {
71 lttng_encode_none = 0,
72 lttng_encode_UTF8 = 1,
73 lttng_encode_ASCII = 2,
74 NR_STRING_ENCODINGS,
75};
76
77struct lttng_enum_value {
78 unsigned long long value;
79 unsigned int signedness:1;
80};
81
82enum lttng_enum_entry_options {
83 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
84};
85
86/*
87 * Enumeration entry description
88 *
89 * IMPORTANT: this structure is part of the ABI between the probe and
90 * UST. Fields need to be only added at the end, never reordered, never
91 * removed.
92 *
93 * The field @struct_size should be used to determine the size of the
94 * structure. It should be queried before using additional fields added
95 * at the end of the structure.
96 */
97
98struct lttng_ust_enum_entry {
99 uint32_t struct_size;
100
101 struct lttng_enum_value start, end; /* start and end are inclusive */
102 const char *string;
103 unsigned int options;
104
105 /* End of base ABI. Fields below should be used after checking struct_size. */
106};
107
108#define __type_integer(_type, _byte_order, _base, _encoding) \
109 { \
110 .atype = atype_integer, \
111 .u = \
112 { \
113 .integer = \
114 { \
115 .size = sizeof(_type) * CHAR_BIT, \
116 .alignment = lttng_alignof(_type) * CHAR_BIT, \
117 .signedness = lttng_is_signed_type(_type), \
118 .reverse_byte_order = _byte_order != BYTE_ORDER, \
119 .base = _base, \
120 .encoding = lttng_encode_##_encoding, \
121 } \
122 }, \
123 } \
124
125#define LTTNG_UST_INTEGER_TYPE_PADDING 24
126struct lttng_integer_type {
127 unsigned int size; /* in bits */
128 unsigned short alignment; /* in bits */
129 unsigned int signedness:1;
130 unsigned int reverse_byte_order:1;
131 unsigned int base; /* 2, 8, 10, 16, for pretty print */
132 enum lttng_string_encodings encoding;
133 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
134};
135
136/*
137 * Only float and double are supported. long double is not supported at
138 * the moment.
139 */
140#define _float_mant_dig(_type) \
141 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
142 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
143 : 0))
144
145#define __type_float(_type) \
146 { \
147 .atype = atype_float, \
148 .u = \
149 { \
150 ._float = \
151 { \
152 .exp_dig = sizeof(_type) * CHAR_BIT \
153 - _float_mant_dig(_type), \
154 .mant_dig = _float_mant_dig(_type), \
155 .alignment = lttng_alignof(_type) * CHAR_BIT, \
156 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
157 } \
158 } \
159 } \
160
161#define LTTNG_UST_FLOAT_TYPE_PADDING 24
162struct lttng_float_type {
163 unsigned int exp_dig; /* exponent digits, in bits */
164 unsigned int mant_dig; /* mantissa digits, in bits */
165 unsigned short alignment; /* in bits */
166 unsigned int reverse_byte_order:1;
167 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
168};
169
170#define LTTNG_UST_TYPE_PADDING 128
171struct lttng_type {
172 enum lttng_abstract_types atype;
173 union {
174 /* provider ABI 2.0 */
175 struct lttng_integer_type integer;
176 struct lttng_float_type _float;
177 struct {
178 enum lttng_string_encodings encoding;
179 } string;
180 struct {
181 const struct lttng_ust_enum_desc *desc; /* Enumeration mapping */
182 struct lttng_type *container_type;
183 } enum_nestable;
184 struct {
185 const struct lttng_type *elem_type;
186 unsigned int length; /* Num. elems. */
187 unsigned int alignment;
188 } array_nestable;
189 struct {
190 const char *length_name; /* Length field name. */
191 const struct lttng_type *elem_type;
192 unsigned int alignment; /* Alignment before elements. */
193 } sequence_nestable;
194 struct {
195 unsigned int nr_fields;
196 const struct lttng_ust_event_field **fields; /* Array of pointers to fields. */
197 unsigned int alignment;
198 } struct_nestable;
199
200 char padding[LTTNG_UST_TYPE_PADDING];
201 } u;
202};
203
204/*
205 * Enumeration description
206 *
207 * IMPORTANT: this structure is part of the ABI between the probe and
208 * UST. Fields need to be only added at the end, never reordered, never
209 * removed.
210 *
211 * The field @struct_size should be used to determine the size of the
212 * structure. It should be queried before using additional fields added
213 * at the end of the structure.
214 */
215
216struct lttng_ust_enum_desc {
217 uint32_t struct_size;
218
219 const char *name;
220 const struct lttng_ust_enum_entry **entries;
221 unsigned int nr_entries;
222
223 /* End of base ABI. Fields below should be used after checking struct_size. */
224};
225
226/*
227 * Event field description
228 *
229 * IMPORTANT: this structure is part of the ABI between the probe and
230 * UST. Fields need to be only added at the end, never reordered, never
231 * removed.
232 *
233 * The field @struct_size should be used to determine the size of the
234 * structure. It should be queried before using additional fields added
235 * at the end of the structure.
236 */
237
238struct lttng_ust_event_field {
239 uint32_t struct_size;
240
241 const char *name;
242 struct lttng_type type;
243 unsigned int nowrite:1, /* do not write into trace */
244 nofilter:1; /* do not consider for filter */
245
246 /* End of base ABI. Fields below should be used after checking struct_size. */
247};
248
249
250/*
251 * IMPORTANT: this structure is part of the ABI between the probe and
252 * UST. Fields need to be only added at the end, never reordered, never
253 * removed.
254 *
255 * The field @struct_size should be used to determine the size of the
256 * structure. It should be queried before using additional fields added
257 * at the end of the structure.
258 */
259struct lttng_ust_event_desc {
260 uint32_t struct_size; /* Size of this structure. */
261 const char *name;
262 void (*probe_callback)(void);
263 const struct lttng_event_ctx *ctx; /* context */
264 const struct lttng_ust_event_field **fields; /* event payload */
265 unsigned int nr_fields;
266 const int **loglevel;
267 const char *signature; /* Argument types/names received */
268 const char **model_emf_uri;
269
270 /* End of base ABI. Fields below should be used after checking struct_size. */
271};
272
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
285 const char *provider;
286 const struct lttng_ust_event_desc **event_desc;
287 unsigned int nr_events;
288 struct cds_list_head head; /* chain registered probes */
289 struct cds_list_head lazy_init_head;
290 int lazy; /* lazy registration */
291 uint32_t major;
292 uint32_t minor;
293
294 /* End of base ABI. Fields below should be used after checking struct_size. */
295};
296
297/* Data structures used by the tracer. */
298
299/*
300 * Bytecode interpreter return value masks.
301 */
302enum lttng_bytecode_interpreter_ret {
303 LTTNG_INTERPRETER_DISCARD = 0,
304 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
305 /* Other bits are kept for future use. */
306};
307
308struct lttng_interpreter_output;
309struct lttng_ust_bytecode_runtime_private;
310
311/*
312 * IMPORTANT: this structure is part of the ABI between the probe and
313 * UST. Fields need to be only added at the end, never reordered, never
314 * removed.
315 *
316 * The field @struct_size should be used to determine the size of the
317 * structure. It should be queried before using additional fields added
318 * at the end of the structure.
319 */
320struct lttng_ust_bytecode_runtime {
321 uint32_t struct_size; /* Size of this structure. */
322
323 struct lttng_ust_bytecode_runtime_private *priv;
324 /* Associated bytecode */
325 union {
326 uint64_t (*filter)(void *interpreter_data,
327 const char *interpreter_stack_data);
328 uint64_t (*capture)(void *interpreter_data,
329 const char *interpreter_stack_data,
330 struct lttng_interpreter_output *interpreter_output);
331 } interpreter_funcs;
332 struct cds_list_head node; /* list of bytecode runtime in event */
333
334 /* End of base ABI. Fields below should be used after checking struct_size. */
335};
336
337/*
338 * lttng_event structure is referred to by the tracing fast path. It
339 * must be kept small.
340 *
341 * IMPORTANT: this structure is part of the ABI between the probe and
342 * UST. Fields need to be only added at the end, never reordered, never
343 * removed.
344 */
345
346struct lttng_ust_ctx;
347struct lttng_ust_event_common_private;
348
349enum lttng_ust_event_type {
350 LTTNG_UST_EVENT_TYPE_RECORDER = 0,
351 LTTNG_UST_EVENT_TYPE_NOTIFIER = 1,
352};
353
354/*
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 *
359 * struct lttng_ust_event_common is the common ancestor of the various
360 * public event actions. Inheritance is done by composition: The parent
361 * has a pointer to its child, and the child has a pointer to its
362 * parent. Inheritance of those public structures is done by composition
363 * to ensure both parent and child structures can be extended.
364 *
365 * The field @struct_size should be used to determine the size of the
366 * structure. It should be queried before using additional fields added
367 * at the end of the structure.
368 */
369struct lttng_ust_event_common {
370 uint32_t struct_size; /* Size of this structure. */
371 struct lttng_ust_event_common_private *priv; /* Private event interface */
372
373 enum lttng_ust_event_type type;
374 void *child; /* Pointer to child, for inheritance by aggregation. */
375
376 int enabled;
377 int has_enablers_without_bytecode;
378 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
379 struct cds_list_head filter_bytecode_runtime_head;
380
381 /* End of base ABI. Fields below should be used after checking struct_size. */
382};
383
384struct lttng_ust_event_recorder_private;
385
386/*
387 * IMPORTANT: this structure is part of the ABI between the probe and
388 * UST. Fields need to be only added at the end, never reordered, never
389 * removed.
390 *
391 * struct lttng_ust_event_recorder is the action for recording events
392 * into a ring buffer. It inherits from struct lttng_ust_event_common
393 * by composition to ensure both parent and child structure are
394 * extensible.
395 *
396 * The field @struct_size should be used to determine the size of the
397 * structure. It should be queried before using additional fields added
398 * at the end of the structure.
399 */
400struct lttng_ust_event_recorder {
401 uint32_t struct_size; /* Size of this structure. */
402 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
403 struct lttng_ust_event_recorder_private *priv; /* Private event record interface */
404
405 unsigned int id;
406 struct lttng_channel *chan;
407 struct lttng_ust_ctx *ctx;
408
409 /* End of base ABI. Fields below should be used after checking struct_size. */
410};
411
412struct lttng_ust_event_notifier_private;
413
414/*
415 * IMPORTANT: this structure is part of the ABI between the probe and
416 * UST. Fields need to be only added at the end, never reordered, never
417 * removed.
418 *
419 * struct lttng_ust_event_notifier is the action for sending
420 * notifications. It inherits from struct lttng_ust_event_common
421 * by composition to ensure both parent and child structure are
422 * extensible.
423 *
424 * The field @struct_size should be used to determine the size of the
425 * structure. It should be queried before using additional fields added
426 * at the end of the structure.
427 */
428struct lttng_ust_event_notifier {
429 uint32_t struct_size; /* Size of this structure. */
430
431 struct lttng_ust_event_common *parent; /* Inheritance by aggregation. */
432 struct lttng_ust_event_notifier_private *priv; /* Private event notifier interface */
433
434 void (*notification_send)(struct lttng_ust_event_notifier *event_notifier,
435 const char *stack_data);
436 struct cds_list_head capture_bytecode_runtime_head;
437
438 /* End of base ABI. Fields below should be used after checking struct_size. */
439};
440
441struct lttng_ust_lib_ring_buffer_channel;
442struct lttng_ust_shm_handle;
443
444/*
445 * IMPORTANT: this structure is part of the ABI between the probe and
446 * UST. Fields need to be only added at the end, never reordered, never
447 * removed.
448 *
449 * The field @struct_size should be used to determine the size of the
450 * structure. It should be queried before using additional fields added
451 * at the end of the structure.
452 */
453struct lttng_ust_channel_ops {
454 uint32_t struct_size;
455
456 struct lttng_channel *(*channel_create)(const char *name,
457 void *buf_addr,
458 size_t subbuf_size, size_t num_subbuf,
459 unsigned int switch_timer_interval,
460 unsigned int read_timer_interval,
461 unsigned char *uuid,
462 uint32_t chan_id,
463 const int *stream_fds, int nr_stream_fds,
464 int64_t blocking_timeout);
465 void (*channel_destroy)(struct lttng_channel *chan);
466 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
467 uint32_t event_id);
468 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
469 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
470 const void *src, size_t len);
471 /*
472 * packet_avail_size returns the available size in the current
473 * packet. Note that the size returned is only a hint, since it
474 * may change due to concurrent writes.
475 */
476 size_t (*packet_avail_size)(struct lttng_ust_lib_ring_buffer_channel *chan,
477 struct lttng_ust_shm_handle *handle);
478 int (*is_finalized)(struct lttng_ust_lib_ring_buffer_channel *chan);
479 int (*is_disabled)(struct lttng_ust_lib_ring_buffer_channel *chan);
480 int (*flush_buffer)(struct lttng_ust_lib_ring_buffer_channel *chan,
481 struct lttng_ust_shm_handle *handle);
482 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
483 const char *src, size_t len);
484
485 /* End of base ABI. Fields below should be used after checking struct_size. */
486};
487
488/*
489 * IMPORTANT: this structure is part of the ABI between the probe and
490 * UST. Fields need to be only added at the end, never reordered, never
491 * removed.
492 */
493struct lttng_channel {
494 /*
495 * The pointers located in this private data are NOT safe to be
496 * dereferenced by the consumer. The only operations the
497 * consumer process is designed to be allowed to do is to read
498 * and perform subbuffer flush.
499 */
500 struct lttng_ust_lib_ring_buffer_channel *chan; /* Channel buffers */
501 int enabled;
502 struct lttng_ust_ctx *ctx;
503 /* Event ID management */
504 struct lttng_session *session;
505 int objd; /* Object associated to channel */
506 struct cds_list_head node; /* Channel list in session */
507 const struct lttng_ust_channel_ops *ops;
508 int header_type; /* 0: unset, 1: compact, 2: large */
509 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
510
511 /* Channel ID */
512 unsigned int id;
513 enum lttng_ust_abi_chan_type type;
514 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
515 int tstate:1; /* Transient enable state */
516};
517
518/*
519 * IMPORTANT: this structure is part of the ABI between the probe and
520 * UST. Fields need to be only added at the end, never reordered, never
521 * removed.
522 *
523 * The field @struct_size should be used to determine the size of the
524 * structure. It should be queried before using additional fields added
525 * at the end of the structure.
526 */
527struct lttng_ust_stack_ctx {
528 uint32_t struct_size; /* Size of this structure */
529
530 struct lttng_ust_event_recorder *event_recorder;
531 struct lttng_ust_ctx *chan_ctx; /* RCU dereferenced. */
532 struct lttng_ust_ctx *event_ctx; /* RCU dereferenced. */
533
534 /* End of base ABI. Fields below should be used after checking struct_size. */
535};
536
537struct lttng_ust_session_private;
538
539/*
540 * IMPORTANT: this structure is part of the ABI between the probe and
541 * UST. Fields need to be only added at the end, never reordered, never
542 * removed.
543 *
544 * The field @struct_size should be used to determine the size of the
545 * structure. It should be queried before using additional fields added
546 * at the end of the structure.
547 */
548struct lttng_session {
549 uint32_t struct_size; /* Size of this structure */
550 struct lttng_ust_session_private *priv; /* Private session interface */
551
552 int active; /* Is trace session active ? */
553
554 /* End of base ABI. Fields below should be used after checking struct_size. */
555};
556
557int lttng_ust_probe_register(struct lttng_ust_probe_desc *desc);
558void lttng_ust_probe_unregister(struct lttng_ust_probe_desc *desc);
559
560/*
561 * Applications that change their procname and need the new value to be
562 * reflected in the procname event context have to call this function to clear
563 * the internally cached value. This should not be called from a signal
564 * handler.
565 */
566void lttng_ust_context_procname_reset(void);
567
568#ifdef __cplusplus
569}
570#endif
571
572#endif /* _LTTNG_UST_EVENTS_H */
This page took 0.024633 seconds and 4 git commands to generate.