Implement libcounter
[lttng-ust.git] / include / lttng / ust-events.h
1 #ifndef _LTTNG_UST_EVENTS_H
2 #define _LTTNG_UST_EVENTS_H
3
4 /*
5 * lttng/ust-events.h
6 *
7 * Copyright 2010-2012 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Holds LTTng per-session event registry.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30 #include <urcu/list.h>
31 #include <urcu/hlist.h>
32 #include <stddef.h>
33 #include <stdint.h>
34 #include <lttng/ust-config.h>
35 #include <lttng/ust-abi.h>
36 #include <lttng/ust-tracer.h>
37 #include <lttng/ust-endian.h>
38 #include <float.h>
39 #include <errno.h>
40 #include <urcu/ref.h>
41 #include <pthread.h>
42
43 #ifndef LTTNG_PACKED
44 #error "LTTNG_PACKED should be defined"
45 #endif
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 #define LTTNG_UST_UUID_LEN 16
52
53 /*
54 * Tracepoint provider version. Compatibility based on the major number.
55 * Older tracepoint providers can always register to newer lttng-ust
56 * library, but the opposite is rejected: a newer tracepoint provider is
57 * rejected by an older lttng-ust library.
58 */
59 #define LTTNG_UST_PROVIDER_MAJOR 2
60 #define LTTNG_UST_PROVIDER_MINOR 0
61
62 struct lttng_channel;
63 struct lttng_session;
64 struct lttng_ust_lib_ring_buffer_ctx;
65 struct lttng_ust_context_app;
66 struct lttng_event_field;
67 struct lttng_event_notifier_group;
68
69 /*
70 * Data structures used by tracepoint event declarations, and by the
71 * tracer. Those structures have padding for future extension.
72 */
73
74 /*
75 * LTTng client type enumeration. Used by the consumer to map the
76 * callbacks from its own address space.
77 */
78 enum lttng_client_types {
79 LTTNG_CLIENT_METADATA = 0,
80 LTTNG_CLIENT_DISCARD = 1,
81 LTTNG_CLIENT_OVERWRITE = 2,
82 LTTNG_CLIENT_DISCARD_RT = 3,
83 LTTNG_CLIENT_OVERWRITE_RT = 4,
84 LTTNG_NR_CLIENT_TYPES,
85 };
86
87 /* Type description */
88
89 /* Update the astract_types name table in lttng-types.c along with this enum */
90 enum lttng_abstract_types {
91 atype_integer,
92 atype_enum, /* legacy */
93 atype_array, /* legacy */
94 atype_sequence, /* legacy */
95 atype_string,
96 atype_float,
97 atype_dynamic,
98 atype_struct, /* legacy */
99 atype_enum_nestable,
100 atype_array_nestable,
101 atype_sequence_nestable,
102 atype_struct_nestable,
103 NR_ABSTRACT_TYPES,
104 };
105
106 /* Update the string_encodings name table in lttng-types.c along with this enum */
107 enum lttng_string_encodings {
108 lttng_encode_none = 0,
109 lttng_encode_UTF8 = 1,
110 lttng_encode_ASCII = 2,
111 NR_STRING_ENCODINGS,
112 };
113
114 struct lttng_enum_value {
115 unsigned long long value;
116 unsigned int signedness:1;
117 };
118
119 enum lttng_enum_entry_options {
120 LTTNG_ENUM_ENTRY_OPTION_IS_AUTO = 1U << 0,
121 };
122
123 #define LTTNG_UST_ENUM_ENTRY_PADDING 16
124 struct lttng_enum_entry {
125 struct lttng_enum_value start, end; /* start and end are inclusive */
126 const char *string;
127 union {
128 struct {
129 unsigned int options;
130 } LTTNG_PACKED extra;
131 char padding[LTTNG_UST_ENUM_ENTRY_PADDING];
132 } u;
133 };
134
135 #define __type_integer(_type, _byte_order, _base, _encoding) \
136 { \
137 .atype = atype_integer, \
138 .u = \
139 { \
140 .integer = \
141 { \
142 .size = sizeof(_type) * CHAR_BIT, \
143 .alignment = lttng_alignof(_type) * CHAR_BIT, \
144 .signedness = lttng_is_signed_type(_type), \
145 .reverse_byte_order = _byte_order != BYTE_ORDER, \
146 .base = _base, \
147 .encoding = lttng_encode_##_encoding, \
148 } \
149 }, \
150 } \
151
152 #define LTTNG_UST_INTEGER_TYPE_PADDING 24
153 struct lttng_integer_type {
154 unsigned int size; /* in bits */
155 unsigned short alignment; /* in bits */
156 unsigned int signedness:1;
157 unsigned int reverse_byte_order:1;
158 unsigned int base; /* 2, 8, 10, 16, for pretty print */
159 enum lttng_string_encodings encoding;
160 char padding[LTTNG_UST_INTEGER_TYPE_PADDING];
161 };
162
163 /*
164 * Only float and double are supported. long double is not supported at
165 * the moment.
166 */
167 #define _float_mant_dig(_type) \
168 (sizeof(_type) == sizeof(float) ? FLT_MANT_DIG \
169 : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \
170 : 0))
171
172 #define __type_float(_type) \
173 { \
174 .atype = atype_float, \
175 .u = \
176 { \
177 ._float = \
178 { \
179 .exp_dig = sizeof(_type) * CHAR_BIT \
180 - _float_mant_dig(_type), \
181 .mant_dig = _float_mant_dig(_type), \
182 .alignment = lttng_alignof(_type) * CHAR_BIT, \
183 .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \
184 } \
185 } \
186 } \
187
188 #define LTTNG_UST_FLOAT_TYPE_PADDING 24
189 struct lttng_float_type {
190 unsigned int exp_dig; /* exponent digits, in bits */
191 unsigned int mant_dig; /* mantissa digits, in bits */
192 unsigned short alignment; /* in bits */
193 unsigned int reverse_byte_order:1;
194 char padding[LTTNG_UST_FLOAT_TYPE_PADDING];
195 };
196
197 /* legacy */
198 #define LTTNG_UST_BASIC_TYPE_PADDING 128
199 union _lttng_basic_type {
200 struct lttng_integer_type integer; /* legacy */
201 struct {
202 const struct lttng_enum_desc *desc; /* Enumeration mapping */
203 struct lttng_integer_type container_type;
204 } enumeration; /* legacy */
205 struct {
206 enum lttng_string_encodings encoding;
207 } string; /* legacy */
208 struct lttng_float_type _float; /* legacy */
209 char padding[LTTNG_UST_BASIC_TYPE_PADDING];
210 };
211
212 /* legacy */
213 struct lttng_basic_type {
214 enum lttng_abstract_types atype;
215 union {
216 union _lttng_basic_type basic;
217 } u;
218 };
219
220 #define LTTNG_UST_TYPE_PADDING 128
221 struct lttng_type {
222 enum lttng_abstract_types atype;
223 union {
224 /* provider ABI 2.0 */
225 struct lttng_integer_type integer;
226 struct lttng_float_type _float;
227 struct {
228 enum lttng_string_encodings encoding;
229 } string;
230 struct {
231 const struct lttng_enum_desc *desc; /* Enumeration mapping */
232 struct lttng_type *container_type;
233 } enum_nestable;
234 struct {
235 const struct lttng_type *elem_type;
236 unsigned int length; /* Num. elems. */
237 unsigned int alignment;
238 } array_nestable;
239 struct {
240 const char *length_name; /* Length field name. */
241 const struct lttng_type *elem_type;
242 unsigned int alignment; /* Alignment before elements. */
243 } sequence_nestable;
244 struct {
245 unsigned int nr_fields;
246 const struct lttng_event_field *fields; /* Array of fields. */
247 unsigned int alignment;
248 } struct_nestable;
249
250 union {
251 /* legacy provider ABI 1.0 */
252 union _lttng_basic_type basic; /* legacy */
253 struct {
254 struct lttng_basic_type elem_type;
255 unsigned int length; /* Num. elems. */
256 } array; /* legacy */
257 struct {
258 struct lttng_basic_type length_type;
259 struct lttng_basic_type elem_type;
260 } sequence; /* legacy */
261 struct {
262 unsigned int nr_fields;
263 struct lttng_event_field *fields; /* Array of fields. */
264 } _struct; /* legacy */
265 } legacy;
266 char padding[LTTNG_UST_TYPE_PADDING];
267 } u;
268 };
269
270 #define LTTNG_UST_ENUM_TYPE_PADDING 24
271 struct lttng_enum_desc {
272 const char *name;
273 const struct lttng_enum_entry *entries;
274 unsigned int nr_entries;
275 char padding[LTTNG_UST_ENUM_TYPE_PADDING];
276 };
277
278 /*
279 * Event field description
280 *
281 * IMPORTANT: this structure is part of the ABI between the probe and
282 * UST. Fields need to be only added at the end, never reordered, never
283 * removed.
284 */
285
286 #define LTTNG_UST_EVENT_FIELD_PADDING 28
287 struct lttng_event_field {
288 const char *name;
289 struct lttng_type type;
290 unsigned int nowrite; /* do not write into trace */
291 union {
292 struct {
293 unsigned int nofilter:1; /* do not consider for filter */
294 } ext;
295 char padding[LTTNG_UST_EVENT_FIELD_PADDING];
296 } u;
297 };
298
299 enum lttng_ust_dynamic_type {
300 LTTNG_UST_DYNAMIC_TYPE_NONE,
301 LTTNG_UST_DYNAMIC_TYPE_S8,
302 LTTNG_UST_DYNAMIC_TYPE_S16,
303 LTTNG_UST_DYNAMIC_TYPE_S32,
304 LTTNG_UST_DYNAMIC_TYPE_S64,
305 LTTNG_UST_DYNAMIC_TYPE_U8,
306 LTTNG_UST_DYNAMIC_TYPE_U16,
307 LTTNG_UST_DYNAMIC_TYPE_U32,
308 LTTNG_UST_DYNAMIC_TYPE_U64,
309 LTTNG_UST_DYNAMIC_TYPE_FLOAT,
310 LTTNG_UST_DYNAMIC_TYPE_DOUBLE,
311 LTTNG_UST_DYNAMIC_TYPE_STRING,
312 _NR_LTTNG_UST_DYNAMIC_TYPES,
313 };
314
315 struct lttng_ctx_value {
316 enum lttng_ust_dynamic_type sel;
317 union {
318 int64_t s64;
319 uint64_t u64;
320 const char *str;
321 double d;
322 } u;
323 };
324
325 struct lttng_perf_counter_field;
326
327 #define LTTNG_UST_CTX_FIELD_PADDING 40
328 struct lttng_ctx_field {
329 struct lttng_event_field event_field;
330 size_t (*get_size)(struct lttng_ctx_field *field, size_t offset);
331 void (*record)(struct lttng_ctx_field *field,
332 struct lttng_ust_lib_ring_buffer_ctx *ctx,
333 struct lttng_channel *chan);
334 void (*get_value)(struct lttng_ctx_field *field,
335 struct lttng_ctx_value *value);
336 union {
337 struct lttng_perf_counter_field *perf_counter;
338 char padding[LTTNG_UST_CTX_FIELD_PADDING];
339 } u;
340 void (*destroy)(struct lttng_ctx_field *field);
341 char *field_name; /* Has ownership, dynamically allocated. */
342 };
343
344 #define LTTNG_UST_CTX_PADDING 20
345 struct lttng_ctx {
346 struct lttng_ctx_field *fields;
347 unsigned int nr_fields;
348 unsigned int allocated_fields;
349 unsigned int largest_align;
350 char padding[LTTNG_UST_CTX_PADDING];
351 };
352
353 #define LTTNG_UST_EVENT_DESC_PADDING 40
354 struct lttng_event_desc {
355 const char *name;
356 void (*probe_callback)(void);
357 const struct lttng_event_ctx *ctx; /* context */
358 const struct lttng_event_field *fields; /* event payload */
359 unsigned int nr_fields;
360 const int **loglevel;
361 const char *signature; /* Argument types/names received */
362 union {
363 struct {
364 const char **model_emf_uri;
365 void (*event_notifier_callback)(void);
366 } ext;
367 char padding[LTTNG_UST_EVENT_DESC_PADDING];
368 } u;
369 };
370
371 #define LTTNG_UST_PROBE_DESC_PADDING 12
372 struct lttng_probe_desc {
373 const char *provider;
374 const struct lttng_event_desc **event_desc;
375 unsigned int nr_events;
376 struct cds_list_head head; /* chain registered probes */
377 struct cds_list_head lazy_init_head;
378 int lazy; /* lazy registration */
379 uint32_t major;
380 uint32_t minor;
381 char padding[LTTNG_UST_PROBE_DESC_PADDING];
382 };
383
384 /* Data structures used by the tracer. */
385
386 enum lttng_enabler_format_type {
387 LTTNG_ENABLER_FORMAT_STAR_GLOB,
388 LTTNG_ENABLER_FORMAT_EVENT,
389 };
390
391 /*
392 * Enabler field, within whatever object is enabling an event. Target of
393 * backward reference.
394 */
395 struct lttng_enabler {
396 enum lttng_enabler_format_type format_type;
397
398 /* head list of struct lttng_ust_filter_bytecode_node */
399 struct cds_list_head filter_bytecode_head;
400 /* head list of struct lttng_ust_excluder_node */
401 struct cds_list_head excluder_head;
402
403 struct lttng_ust_event event_param;
404 unsigned int enabled:1;
405 };
406
407 struct tp_list_entry {
408 struct lttng_ust_tracepoint_iter tp;
409 struct cds_list_head head;
410 };
411
412 struct lttng_ust_tracepoint_list {
413 struct tp_list_entry *iter;
414 struct cds_list_head head;
415 };
416
417 struct tp_field_list_entry {
418 struct lttng_ust_field_iter field;
419 struct cds_list_head head;
420 };
421
422 struct lttng_ust_field_list {
423 struct tp_field_list_entry *iter;
424 struct cds_list_head head;
425 };
426
427 struct ust_pending_probe;
428 struct lttng_event;
429
430 /*
431 * Bytecode interpreter return value masks.
432 */
433 enum lttng_bytecode_interpreter_ret {
434 LTTNG_INTERPRETER_DISCARD = 0,
435 LTTNG_INTERPRETER_RECORD_FLAG = (1ULL << 0),
436 /* Other bits are kept for future use. */
437 };
438
439 struct lttng_interpreter_output;
440
441 /*
442 * This structure is used in the probes. More specifically, the `filter` and
443 * `node` fields are explicity used in the probes. When modifying this
444 * structure we must not change the layout of these two fields as it is
445 * considered ABI.
446 */
447 struct lttng_bytecode_runtime {
448 /* Associated bytecode */
449 struct lttng_ust_bytecode_node *bc;
450 union {
451 uint64_t (*filter)(void *interpreter_data,
452 const char *interpreter_stack_data);
453 uint64_t (*capture)(void *interpreter_data,
454 const char *interpreter_stack_data,
455 struct lttng_interpreter_output *interpreter_output);
456 } interpreter_funcs;
457 int link_failed;
458 struct cds_list_head node; /* list of bytecode runtime in event */
459 /*
460 * Pointer to a URCU-protected pointer owned by an `struct
461 * lttng_session`or `struct lttng_event_notifier_group`.
462 */
463 struct lttng_ctx **pctx;
464 };
465
466 /*
467 * Objects in a linked-list of enablers, owned by an event or event_notifier.
468 * This is used because an event (or a event_notifier) can be enabled by more
469 * than one enabler and we want a quick way to iterate over all enablers of an
470 * object.
471 *
472 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
473 * event with the name "my_app:abc".
474 */
475 struct lttng_enabler_ref {
476 struct cds_list_head node; /* enabler ref list */
477 struct lttng_enabler *ref; /* backward ref */
478 };
479
480 /*
481 * lttng_event structure is referred to by the tracing fast path. It
482 * must be kept small.
483 *
484 * IMPORTANT: this structure is part of the ABI between the probe and
485 * UST. Fields need to be only added at the end, never reordered, never
486 * removed.
487 */
488 struct lttng_event {
489 /* LTTng-UST 2.0 starts here */
490 unsigned int id;
491 struct lttng_channel *chan;
492 int enabled;
493 const struct lttng_event_desc *desc;
494 void *_deprecated1;
495 struct lttng_ctx *ctx;
496 enum lttng_ust_instrumentation instrumentation;
497 struct cds_list_head node; /* Event list in session */
498 struct cds_list_head _deprecated2;
499 void *_deprecated3;
500 unsigned int _deprecated4:1;
501
502 /* LTTng-UST 2.1 starts here */
503 /* list of struct lttng_bytecode_runtime, sorted by seqnum */
504 struct cds_list_head filter_bytecode_runtime_head;
505 int has_enablers_without_bytecode;
506 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
507 struct cds_list_head enablers_ref_head;
508 struct cds_hlist_node hlist; /* session ht of events */
509 int registered; /* has reg'd tracepoint probe */
510 };
511
512 struct lttng_event_notifier {
513 uint64_t user_token;
514 int enabled;
515 int registered; /* has reg'd tracepoint probe */
516 size_t num_captures; /* Needed to allocate the msgpack array. */
517 struct cds_list_head filter_bytecode_runtime_head;
518 struct cds_list_head capture_bytecode_runtime_head;
519 int has_enablers_without_bytecode;
520 struct cds_list_head enablers_ref_head;
521 const struct lttng_event_desc *desc;
522 struct cds_hlist_node hlist; /* hashtable of event_notifiers */
523 struct cds_list_head node; /* event_notifier list in session */
524 struct lttng_event_notifier_group *group; /* weak ref */
525 };
526
527 struct lttng_enum {
528 const struct lttng_enum_desc *desc;
529 struct lttng_session *session;
530 struct cds_list_head node; /* Enum list in session */
531 struct cds_hlist_node hlist; /* Session ht of enums */
532 uint64_t id; /* Enumeration ID in sessiond */
533 };
534
535 struct channel;
536 struct lttng_ust_shm_handle;
537
538 /*
539 * IMPORTANT: this structure is part of the ABI between the probe and
540 * UST. Fields need to be only added at the end, never reordered, never
541 * removed.
542 */
543 struct lttng_channel_ops {
544 struct lttng_channel *(*channel_create)(const char *name,
545 void *buf_addr,
546 size_t subbuf_size, size_t num_subbuf,
547 unsigned int switch_timer_interval,
548 unsigned int read_timer_interval,
549 unsigned char *uuid,
550 uint32_t chan_id,
551 const int *stream_fds, int nr_stream_fds,
552 int64_t blocking_timeout);
553 void (*channel_destroy)(struct lttng_channel *chan);
554 union {
555 void *_deprecated1;
556 /*
557 * has_strcpy is needed by probe providers version 1.0 to
558 * dynamically detect whether the LTTng-UST tracepoint
559 * provider ABI implements event_strcpy. Starting from
560 * probe providers version 2.0, the check is not needed,
561 * but backward compatibility is provided for older versions.
562 */
563 unsigned long has_strcpy:1; /* ABI has strcpy */
564 } u;
565 void *_deprecated2;
566 int (*event_reserve)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
567 uint32_t event_id);
568 void (*event_commit)(struct lttng_ust_lib_ring_buffer_ctx *ctx);
569 void (*event_write)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
570 const void *src, size_t len);
571 /*
572 * packet_avail_size returns the available size in the current
573 * packet. Note that the size returned is only a hint, since it
574 * may change due to concurrent writes.
575 */
576 size_t (*packet_avail_size)(struct channel *chan,
577 struct lttng_ust_shm_handle *handle);
578 //wait_queue_head_t *(*get_reader_wait_queue)(struct channel *chan);
579 //wait_queue_head_t *(*get_hp_wait_queue)(struct channel *chan);
580 int (*is_finalized)(struct channel *chan);
581 int (*is_disabled)(struct channel *chan);
582 int (*flush_buffer)(struct channel *chan, struct lttng_ust_shm_handle *handle);
583 void (*event_strcpy)(struct lttng_ust_lib_ring_buffer_ctx *ctx,
584 const char *src, size_t len);
585 };
586
587 /*
588 * IMPORTANT: this structure is part of the ABI between the probe and
589 * UST. Fields need to be only added at the end, never reordered, never
590 * removed.
591 */
592 struct lttng_channel {
593 /*
594 * The pointers located in this private data are NOT safe to be
595 * dereferenced by the consumer. The only operations the
596 * consumer process is designed to be allowed to do is to read
597 * and perform subbuffer flush.
598 */
599 struct channel *chan; /* Channel buffers */
600 int enabled;
601 struct lttng_ctx *ctx;
602 /* Event ID management */
603 struct lttng_session *session;
604 int objd; /* Object associated to channel */
605 unsigned int _deprecated1;
606 unsigned int _deprecated2;
607 struct cds_list_head node; /* Channel list in session */
608 const struct lttng_channel_ops *ops;
609 int header_type; /* 0: unset, 1: compact, 2: large */
610 struct lttng_ust_shm_handle *handle; /* shared-memory handle */
611 unsigned int _deprecated3:1;
612
613 /* Channel ID */
614 unsigned int id;
615 enum lttng_ust_chan_type type;
616 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
617 int tstate:1; /* Transient enable state */
618 };
619
620 #define LTTNG_COUNTER_DIMENSION_MAX 8
621
622 struct lttng_counter_dimension {
623 uint64_t size;
624 uint64_t underflow_index;
625 uint64_t overflow_index;
626 uint8_t has_underflow;
627 uint8_t has_overflow;
628 };
629
630 struct lttng_counter_ops {
631 struct lib_counter *(*counter_create)(size_t nr_dimensions,
632 const struct lttng_counter_dimension *dimensions,
633 int64_t global_sum_step,
634 int global_counter_fd,
635 int nr_counter_cpu_fds,
636 const int *counter_cpu_fds,
637 bool is_daemon);
638 void (*counter_destroy)(struct lib_counter *counter);
639 int (*counter_add)(struct lib_counter *counter,
640 const size_t *dimension_indexes, int64_t v);
641 int (*counter_read)(struct lib_counter *counter,
642 const size_t *dimension_indexes, int cpu,
643 int64_t *value, bool *overflow, bool *underflow);
644 int (*counter_aggregate)(struct lib_counter *counter,
645 const size_t *dimension_indexes, int64_t *value,
646 bool *overflow, bool *underflow);
647 int (*counter_clear)(struct lib_counter *counter, const size_t *dimension_indexes);
648 };
649
650 #define LTTNG_UST_STACK_CTX_PADDING 32
651 struct lttng_stack_ctx {
652 struct lttng_event *event;
653 struct lttng_ctx *chan_ctx; /* RCU dereferenced. */
654 struct lttng_ctx *event_ctx; /* RCU dereferenced. */
655 char padding[LTTNG_UST_STACK_CTX_PADDING];
656 };
657
658 #define LTTNG_UST_EVENT_HT_BITS 12
659 #define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
660
661 struct lttng_ust_event_ht {
662 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
663 };
664
665 #define LTTNG_UST_EVENT_NOTIFIER_HT_BITS 12
666 #define LTTNG_UST_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_UST_EVENT_NOTIFIER_HT_BITS)
667 struct lttng_ust_event_notifier_ht {
668 struct cds_hlist_head table[LTTNG_UST_EVENT_NOTIFIER_HT_SIZE];
669 };
670
671 #define LTTNG_UST_ENUM_HT_BITS 12
672 #define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
673
674 struct lttng_ust_enum_ht {
675 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
676 };
677
678 /*
679 * IMPORTANT: this structure is part of the ABI between the probe and
680 * UST. Fields need to be only added at the end, never reordered, never
681 * removed.
682 */
683 struct lttng_session {
684 int active; /* Is trace session active ? */
685 int been_active; /* Been active ? */
686 int objd; /* Object associated */
687 void *_deprecated1;
688 struct cds_list_head chan_head; /* Channel list head */
689 struct cds_list_head events_head; /* list of events */
690 struct cds_list_head _deprecated2;
691 struct cds_list_head node; /* Session list */
692 int _deprecated3;
693 unsigned int _deprecated4:1;
694
695 /* New UST 2.1 */
696 /* List of enablers */
697 struct cds_list_head enablers_head;
698 struct lttng_ust_event_ht events_ht; /* ht of events */
699 void *owner; /* object owner */
700 int tstate:1; /* Transient enable state */
701
702 /* New UST 2.4 */
703 int statedump_pending:1;
704
705 /* New UST 2.8 */
706 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
707 struct cds_list_head enums_head;
708 struct lttng_ctx *ctx; /* contexts for filters. */
709 };
710
711 struct lttng_counter {
712 int objd;
713 struct lttng_event_notifier_group *event_notifier_group; /* owner */
714 struct lttng_counter_transport *transport;
715 struct lib_counter *counter;
716 struct lttng_counter_ops *ops;
717 };
718
719 struct lttng_event_notifier_group {
720 int objd;
721 void *owner;
722 int notification_fd;
723 struct cds_list_head node; /* Event notifier group handle list */
724 struct cds_list_head enablers_head;
725 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
726 struct lttng_ust_event_notifier_ht event_notifiers_ht; /* hashtable of event_notifiers */
727 struct lttng_ctx *ctx; /* contexts for filters. */
728
729 struct lttng_counter *error_counter;
730 size_t error_counter_len;
731 };
732
733 struct lttng_transport {
734 char *name;
735 struct cds_list_head node;
736 struct lttng_channel_ops ops;
737 const struct lttng_ust_lib_ring_buffer_config *client_config;
738 };
739
740 struct lttng_counter_transport {
741 char *name;
742 struct cds_list_head node;
743 struct lttng_counter_ops ops;
744 const struct lib_counter_config *client_config;
745 };
746
747 struct lttng_session *lttng_session_create(void);
748 int lttng_session_enable(struct lttng_session *session);
749 int lttng_session_disable(struct lttng_session *session);
750 int lttng_session_statedump(struct lttng_session *session);
751 void lttng_session_destroy(struct lttng_session *session);
752
753 void lttng_event_notifier_notification_send(
754 struct lttng_event_notifier *event_notifier,
755 const char *stack_data);
756
757 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
758 const char *transport_name,
759 void *buf_addr,
760 size_t subbuf_size, size_t num_subbuf,
761 unsigned int switch_timer_interval,
762 unsigned int read_timer_interval,
763 int **shm_fd, int **wait_fd,
764 uint64_t **memory_map_size,
765 struct lttng_channel *chan_priv_init);
766
767 int lttng_channel_enable(struct lttng_channel *channel);
768 int lttng_channel_disable(struct lttng_channel *channel);
769
770 int lttng_attach_context(struct lttng_ust_context *context_param,
771 union ust_args *uargs,
772 struct lttng_ctx **ctx, struct lttng_session *session);
773 void lttng_transport_register(struct lttng_transport *transport);
774 void lttng_transport_unregister(struct lttng_transport *transport);
775
776 void lttng_counter_transport_register(struct lttng_counter_transport *transport);
777 void lttng_counter_transport_unregister(struct lttng_counter_transport *transport);
778
779 struct lttng_counter *lttng_ust_counter_create(
780 const char *counter_transport_name,
781 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
782
783 void synchronize_trace(void);
784
785 int lttng_probe_register(struct lttng_probe_desc *desc);
786 void lttng_probe_unregister(struct lttng_probe_desc *desc);
787 void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc);
788 int lttng_fix_pending_events(void);
789 int lttng_probes_init(void);
790 void lttng_probes_exit(void);
791 int lttng_find_context(struct lttng_ctx *ctx, const char *name);
792 int lttng_get_context_index(struct lttng_ctx *ctx, const char *name);
793 struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p);
794 void lttng_context_update(struct lttng_ctx *ctx);
795 void lttng_remove_context_field(struct lttng_ctx **ctx_p,
796 struct lttng_ctx_field *field);
797 void lttng_destroy_context(struct lttng_ctx *ctx);
798 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx);
799 int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx);
800 int lttng_add_pthread_id_to_ctx(struct lttng_ctx **ctx);
801 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx);
802 int lttng_add_ip_to_ctx(struct lttng_ctx **ctx);
803 int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx);
804 int lttng_add_dyntest_to_ctx(struct lttng_ctx **ctx);
805 int lttng_add_cgroup_ns_to_ctx(struct lttng_ctx **ctx);
806 int lttng_add_ipc_ns_to_ctx(struct lttng_ctx **ctx);
807 int lttng_add_mnt_ns_to_ctx(struct lttng_ctx **ctx);
808 int lttng_add_net_ns_to_ctx(struct lttng_ctx **ctx);
809 int lttng_add_pid_ns_to_ctx(struct lttng_ctx **ctx);
810 int lttng_add_time_ns_to_ctx(struct lttng_ctx **ctx);
811 int lttng_add_user_ns_to_ctx(struct lttng_ctx **ctx);
812 int lttng_add_uts_ns_to_ctx(struct lttng_ctx **ctx);
813 int lttng_add_vuid_to_ctx(struct lttng_ctx **ctx);
814 int lttng_add_veuid_to_ctx(struct lttng_ctx **ctx);
815 int lttng_add_vsuid_to_ctx(struct lttng_ctx **ctx);
816 int lttng_add_vgid_to_ctx(struct lttng_ctx **ctx);
817 int lttng_add_vegid_to_ctx(struct lttng_ctx **ctx);
818 int lttng_add_vsgid_to_ctx(struct lttng_ctx **ctx);
819 void lttng_context_vtid_reset(void);
820 void lttng_context_vpid_reset(void);
821 void lttng_context_procname_reset(void);
822 void lttng_context_cgroup_ns_reset(void);
823 void lttng_context_ipc_ns_reset(void);
824 void lttng_context_mnt_ns_reset(void);
825 void lttng_context_net_ns_reset(void);
826 void lttng_context_pid_ns_reset(void);
827 void lttng_context_time_ns_reset(void);
828 void lttng_context_user_ns_reset(void);
829 void lttng_context_uts_ns_reset(void);
830 void lttng_context_vuid_reset(void);
831 void lttng_context_veuid_reset(void);
832 void lttng_context_vsuid_reset(void);
833 void lttng_context_vgid_reset(void);
834 void lttng_context_vegid_reset(void);
835 void lttng_context_vsgid_reset(void);
836
837 #ifdef LTTNG_UST_HAVE_PERF_EVENT
838 int lttng_add_perf_counter_to_ctx(uint32_t type,
839 uint64_t config,
840 const char *name,
841 struct lttng_ctx **ctx);
842 int lttng_perf_counter_init(void);
843 void lttng_perf_counter_exit(void);
844 #else /* #ifdef LTTNG_UST_HAVE_PERF_EVENT */
845 static inline
846 int lttng_add_perf_counter_to_ctx(uint32_t type,
847 uint64_t config,
848 const char *name,
849 struct lttng_ctx **ctx)
850 {
851 return -ENOSYS;
852 }
853 static inline
854 int lttng_perf_counter_init(void)
855 {
856 return 0;
857 }
858 static inline
859 void lttng_perf_counter_exit(void)
860 {
861 }
862 #endif /* #else #ifdef LTTNG_UST_HAVE_PERF_EVENT */
863
864 extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_metadata;
865 extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_discard;
866 extern const struct lttng_ust_client_lib_ring_buffer_client_cb *lttng_client_callbacks_overwrite;
867
868 struct lttng_transport *lttng_transport_find(const char *name);
869 struct lttng_counter_transport *lttng_counter_transport_find(const char *name);
870
871 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
872 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
873 struct lttng_ust_tracepoint_iter *
874 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
875 int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
876 void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
877 struct lttng_ust_field_iter *
878 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
879
880 void lttng_free_event_filter_runtime(struct lttng_event *event);
881
882 struct cds_list_head *lttng_get_probe_list_head(void);
883 int lttng_session_active(void);
884
885 typedef int (*t_statedump_func_ptr)(struct lttng_session *session);
886 void lttng_handle_pending_statedump(void *owner);
887 struct cds_list_head *_lttng_get_sessions(void);
888
889 struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
890 const struct lttng_enum_desc *enum_desc);
891
892 void lttng_ust_dl_update(void *ip);
893 void lttng_ust_fixup_fd_tracker_tls(void);
894
895 /* For backward compatibility. Leave those exported symbols in place. */
896 extern struct lttng_ctx *lttng_static_ctx;
897 struct lttng_ust_filter_bytecode_node;
898 struct lttng_ust_excluder_node;
899 void lttng_context_init(void);
900 void lttng_context_exit(void);
901 void lttng_filter_event_link_bytecode(struct lttng_event *event);
902 struct lttng_enabler *lttng_enabler_create(
903 enum lttng_enabler_format_type format_type,
904 struct lttng_ust_event *event_param,
905 struct lttng_channel *chan);
906 int lttng_enabler_enable(struct lttng_enabler *enabler);
907 int lttng_enabler_disable(struct lttng_enabler *enabler);
908 int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
909 struct lttng_ust_filter_bytecode_node *bytecode);
910 int lttng_enabler_attach_context(struct lttng_enabler *enabler,
911 struct lttng_ust_context *ctx);
912 int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
913 struct lttng_ust_excluder_node *excluder);
914 void lttng_enabler_event_link_bytecode(struct lttng_event *event,
915 struct lttng_enabler *enabler);
916 void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime);
917 int lttng_session_context_init(struct lttng_ctx **ctx);
918
919
920 #ifdef __cplusplus
921 }
922 #endif
923
924 #endif /* _LTTNG_UST_EVENTS_H */
This page took 0.048371 seconds and 4 git commands to generate.