Introduce extension points for trace hit counters
[lttng-ust.git] / src / common / events.h
CommitLineData
d871c65b 1/*
c0c0989a 2 * SPDX-License-Identifier: MIT
d871c65b 3 *
c0c0989a 4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
d871c65b
FD
5 */
6
36c52fff
MJ
7#ifndef _UST_COMMON_UST_EVENTS_H
8#define _UST_COMMON_UST_EVENTS_H
c0c0989a 9
9af5d97a 10#include <limits.h>
d871c65b
FD
11#include <stdint.h>
12
13#include <urcu/list.h>
14#include <urcu/hlist.h>
15
d871c65b
FD
16#include <lttng/ust-events.h>
17
9d315d6d
MJ
18#include "common/macros.h"
19#include "common/ust-context-provider.h"
fd17d7ce 20
66d0d054
MD
21/*
22 * The context procname length is part of the LTTng-UST ABI.
23 * TODO: At the next breaking protocol bump, all users of this macro
24 * should instead use LTTNG_UST_ABI_PROCNAME_LEN.
25 */
26#define LTTNG_UST_CONTEXT_PROCNAME_LEN 17
27
fd17d7ce 28struct lttng_ust_abi_obj;
06cd86a0 29struct lttng_event_notifier_group;
fd17d7ce
MD
30
31union lttng_ust_abi_args {
32 struct {
33 void *chan_data;
34 int wakeup_fd;
35 } channel;
36 struct {
37 int shm_fd;
38 int wakeup_fd;
39 } stream;
40 struct {
41 struct lttng_ust_abi_field_iter entry;
42 } field_list;
43 struct {
44 char *ctxname;
45 } app_context;
46 struct {
47 int event_notifier_notif_fd;
48 } event_notifier_handle;
49 struct {
428d8ee5
MD
50 uint32_t len;
51 } event_notifier;
52 struct {
53 uint32_t len;
fd17d7ce
MD
54 } counter;
55 struct {
428d8ee5 56 uint32_t len;
fd17d7ce
MD
57 int shm_fd;
58 } counter_shm;
2ec133be
MD
59 struct {
60 uint32_t len;
61 } counter_event;
fd17d7ce
MD
62};
63
64struct lttng_ust_abi_objd_ops {
65 long (*cmd)(int objd, unsigned int cmd, unsigned long arg,
66 union lttng_ust_abi_args *args, void *owner);
67 int (*release)(int objd);
68};
69
8665f6a4
MJ
70enum lttng_enabler_format_type {
71 LTTNG_ENABLER_FORMAT_STAR_GLOB,
72 LTTNG_ENABLER_FORMAT_EVENT,
73};
74
b187bcd5
MD
75enum lttng_key_token_type {
76 LTTNG_KEY_TOKEN_STRING = 0,
77 LTTNG_KEY_TOKEN_EVENT_NAME = 1,
78 LTTNG_KEY_TOKEN_PROVIDER_NAME = 2,
79};
80
2ec133be 81#define LTTNG_KEY_TOKEN_STRING_LEN_MAX 4096
b187bcd5
MD
82struct lttng_key_token {
83 enum lttng_key_token_type type;
84 union {
85 char string[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
86 } arg;
87};
88
24f7193c
MD
89enum lttng_key_type {
90 LTTNG_KEY_TYPE_TOKENS = 0,
91 LTTNG_KEY_TYPE_INTEGER = 1,
92};
93
2ec133be 94#define LTTNG_NR_KEY_TOKEN 8
b187bcd5 95struct lttng_counter_key_dimension {
24f7193c
MD
96 enum lttng_key_type key_type;
97
98 union {
99 struct {
100 size_t nr_key_tokens;
101 struct lttng_key_token key_tokens[LTTNG_NR_KEY_TOKEN];
102 } tokens;
103 } u;
b187bcd5
MD
104};
105
2ec133be 106#define LTTNG_COUNTER_DIMENSION_MAX 4
b187bcd5
MD
107struct lttng_counter_key {
108 size_t nr_dimensions;
109 struct lttng_counter_key_dimension key_dimensions[LTTNG_COUNTER_DIMENSION_MAX];
110};
111
112struct lttng_counter_dimension {
113 uint64_t size;
114 uint64_t underflow_index;
115 uint64_t overflow_index;
24f7193c 116 enum lttng_key_type key_type;
b187bcd5
MD
117 uint8_t has_underflow;
118 uint8_t has_overflow;
119};
120
121enum lttng_event_enabler_type {
122 LTTNG_EVENT_ENABLER_TYPE_RECORDER,
123 LTTNG_EVENT_ENABLER_TYPE_NOTIFIER,
124 LTTNG_EVENT_ENABLER_TYPE_COUNTER,
125};
126
8665f6a4
MJ
127/*
128 * Enabler field, within whatever object is enabling an event. Target of
129 * backward reference.
130 */
b187bcd5
MD
131struct lttng_event_enabler_common {
132 enum lttng_event_enabler_type enabler_type;
133
8665f6a4
MJ
134 enum lttng_enabler_format_type format_type;
135
136 /* head list of struct lttng_ust_filter_bytecode_node */
137 struct cds_list_head filter_bytecode_head;
138 /* head list of struct lttng_ust_excluder_node */
139 struct cds_list_head excluder_head;
140
fd17d7ce 141 struct lttng_ust_abi_event event_param;
8665f6a4 142 unsigned int enabled:1;
b187bcd5 143
6b081b20 144 struct cds_list_head node; /* list of enablers */
b187bcd5 145 uint64_t user_token; /* User-provided token */
8665f6a4
MJ
146};
147
b187bcd5
MD
148struct lttng_event_enabler_session_common {
149 struct lttng_event_enabler_common parent;
150 struct lttng_ust_channel_common *chan;
d871c65b
FD
151};
152
b187bcd5
MD
153struct lttng_event_recorder_enabler {
154 struct lttng_event_enabler_session_common parent;
155 struct lttng_ust_channel_buffer *chan;
156};
157
24f7193c
MD
158enum lttng_event_counter_action {
159 LTTNG_EVENT_COUNTER_ACTION_INCREMENT = 0,
160};
161
b187bcd5
MD
162struct lttng_event_counter_enabler {
163 struct lttng_event_enabler_session_common parent;
164 struct lttng_ust_channel_counter *chan;
165 struct lttng_counter_key key;
24f7193c
MD
166
167 enum lttng_event_counter_action action;
b187bcd5
MD
168};
169
d8d2416d 170struct lttng_event_notifier_enabler {
b187bcd5 171 struct lttng_event_enabler_common parent;
6566528b 172 uint64_t error_counter_index;
d37ecb3f 173 struct cds_list_head capture_bytecode_head;
d8d2416d 174 struct lttng_event_notifier_group *group; /* weak ref */
d37ecb3f 175 uint64_t num_captures;
d8d2416d
FD
176};
177
22c30e27
MD
178enum lttng_ust_bytecode_type {
179 LTTNG_UST_BYTECODE_TYPE_FILTER,
180 LTTNG_UST_BYTECODE_TYPE_CAPTURE,
ab249ecf
FD
181};
182
183struct lttng_ust_bytecode_node {
22c30e27 184 enum lttng_ust_bytecode_type type;
92495593 185 struct cds_list_head node;
b187bcd5 186 struct lttng_event_enabler_common *enabler;
ab249ecf
FD
187 struct {
188 uint32_t len;
189 uint32_t reloc_offset;
190 uint64_t seqnum;
191 char data[];
192 } bc;
92495593
FD
193};
194
a2e4d05e
MD
195/*
196 * Bytecode interpreter return value.
197 */
198enum lttng_ust_bytecode_interpreter_ret {
199 LTTNG_UST_BYTECODE_INTERPRETER_ERROR = -1,
200 LTTNG_UST_BYTECODE_INTERPRETER_OK = 0,
201};
202
203struct lttng_interpreter_output;
204struct lttng_ust_bytecode_runtime_private;
205
206enum lttng_ust_bytecode_filter_result {
207 LTTNG_UST_BYTECODE_FILTER_ACCEPT = 0,
208 LTTNG_UST_BYTECODE_FILTER_REJECT = 1,
209};
210
211struct lttng_ust_bytecode_filter_ctx {
212 enum lttng_ust_bytecode_filter_result result;
213};
214
92495593
FD
215struct lttng_ust_excluder_node {
216 struct cds_list_head node;
b187bcd5 217 struct lttng_event_enabler_common *enabler;
92495593
FD
218 /*
219 * struct lttng_ust_event_exclusion had variable sized array,
220 * must be last field.
221 */
fd17d7ce 222 struct lttng_ust_abi_event_exclusion excluder;
92495593
FD
223};
224
bb7ad29d
MJ
225/* Data structures used by the tracer. */
226
227struct tp_list_entry {
fd17d7ce 228 struct lttng_ust_abi_tracepoint_iter tp;
bb7ad29d
MJ
229 struct cds_list_head head;
230};
231
232struct lttng_ust_tracepoint_list {
233 struct tp_list_entry *iter;
234 struct cds_list_head head;
235};
236
237struct tp_field_list_entry {
fd17d7ce 238 struct lttng_ust_abi_field_iter field;
bb7ad29d
MJ
239 struct cds_list_head head;
240};
241
242struct lttng_ust_field_list {
243 struct tp_field_list_entry *iter;
244 struct cds_list_head head;
245};
246
247/*
248 * Objects in a linked-list of enablers, owned by an event or event_notifier.
249 * This is used because an event (or a event_notifier) can be enabled by more
250 * than one enabler and we want a quick way to iterate over all enablers of an
251 * object.
252 *
253 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
254 * event with the name "my_app:abc".
255 */
256struct lttng_enabler_ref {
257 struct cds_list_head node; /* enabler ref list */
b187bcd5 258 struct lttng_event_enabler_common *ref; /* backward ref */
bb7ad29d
MJ
259};
260
681f6001
MD
261#define LTTNG_UST_EVENT_HT_BITS 12
262#define LTTNG_UST_EVENT_HT_SIZE (1U << LTTNG_UST_EVENT_HT_BITS)
263
264struct lttng_ust_event_ht {
265 struct cds_hlist_head table[LTTNG_UST_EVENT_HT_SIZE];
266};
267
681f6001
MD
268#define LTTNG_UST_ENUM_HT_BITS 12
269#define LTTNG_UST_ENUM_HT_SIZE (1U << LTTNG_UST_ENUM_HT_BITS)
270
271struct lttng_ust_enum_ht {
272 struct cds_hlist_head table[LTTNG_UST_ENUM_HT_SIZE];
273};
274
bb7ad29d
MJ
275struct lttng_event_notifier_group {
276 int objd;
277 void *owner;
278 int notification_fd;
279 struct cds_list_head node; /* Event notifier group handle list */
1e8023ed
MD
280
281 /* List of non-synchronized enablers */
282 struct cds_list_head unsync_enablers_head;
283 /* List of synchronized enablers */
284 struct cds_list_head sync_enablers_head;
285
0c1264b0 286 struct cds_list_head event_notifiers_head; /* list of event_notifiers */
86eca0c9 287 struct lttng_ust_event_ht event_notifiers_ht; /* hashtable of event notifiers */
0c1264b0 288 struct lttng_ust_ctx *ctx; /* contexts for filters. */
bb7ad29d 289
b187bcd5 290 struct lttng_ust_channel_counter *error_counter;
bb7ad29d
MJ
291 size_t error_counter_len;
292};
293
294struct lttng_transport {
74c3f8e2 295 const char *name;
bb7ad29d 296 struct cds_list_head node;
14b6f891 297 struct lttng_ust_channel_buffer_ops ops;
b5457df5 298 const struct lttng_ust_ring_buffer_config *client_config;
bb7ad29d
MJ
299};
300
301struct lttng_counter_transport {
74c3f8e2 302 const char *name;
bb7ad29d 303 struct cds_list_head node;
b187bcd5 304 struct lttng_ust_channel_counter_ops ops;
bb7ad29d
MJ
305 const struct lib_counter_config *client_config;
306};
307
80333dfa 308struct lttng_ust_event_common_private {
7ee76145 309 struct lttng_ust_event_common *pub; /* Public event interface */
68bb7559 310
4e48b5d2 311 const struct lttng_ust_event_desc *desc;
68bb7559
MD
312 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
313 struct cds_list_head enablers_ref_head;
0c1264b0 314 int registered; /* has reg'd tracepoint probe */
115db533 315 uint64_t user_token;
a2e4d05e
MD
316
317 int has_enablers_without_filter_bytecode;
318 /* list of struct lttng_ust_bytecode_runtime, sorted by seqnum */
319 struct cds_list_head filter_bytecode_runtime_head;
18dd3bb0
MD
320
321 struct cds_hlist_node name_hlist_node; /* node in events-by-name hash table */
e7cab352 322 struct cds_list_head node; /* node in event list */
68bb7559
MD
323};
324
b187bcd5 325struct lttng_ust_event_session_common_private {
80333dfa
MD
326 struct lttng_ust_event_common_private parent;
327
b187bcd5 328 struct lttng_ust_channel_common *chan;
b93e147b
MD
329
330 uint64_t id; /* Event id */
b187bcd5
MD
331};
332
333struct lttng_ust_event_recorder_private {
334 struct lttng_ust_event_session_common_private parent;
335
336 struct lttng_ust_event_recorder *pub; /* Public event interface */
80333dfa
MD
337};
338
b187bcd5
MD
339struct lttng_ust_event_counter_private {
340 struct lttng_ust_event_session_common_private parent;
341
342 struct lttng_ust_event_counter *pub; /* Public event interface */
24f7193c 343 enum lttng_event_counter_action action;
b187bcd5 344 char key[LTTNG_KEY_TOKEN_STRING_LEN_MAX];
b187bcd5
MD
345};
346
115db533
MD
347struct lttng_ust_event_notifier_private {
348 struct lttng_ust_event_common_private parent;
349
d7d45c0d 350 struct lttng_ust_event_notifier *pub; /* Public event notifier interface */
115db533
MD
351 struct lttng_event_notifier_group *group; /* weak ref */
352 size_t num_captures; /* Needed to allocate the msgpack array. */
353 uint64_t error_counter_index;
a2e4d05e 354 struct cds_list_head capture_bytecode_runtime_head;
a2e4d05e 355};
362a65de 356
a2e4d05e 357struct lttng_ust_bytecode_runtime {
22c30e27 358 enum lttng_ust_bytecode_type type;
362a65de
MD
359 struct lttng_ust_bytecode_node *bc;
360 int link_failed;
a2e4d05e
MD
361 int (*interpreter_func)(struct lttng_ust_bytecode_runtime *bytecode_runtime,
362 const char *interpreter_stack_data,
b2e37d27 363 struct lttng_ust_probe_ctx *probe_ctx,
a2e4d05e 364 void *ctx);
0c1264b0 365 struct cds_list_head node; /* list of bytecode runtime in event */
362a65de
MD
366 /*
367 * Pointer to a URCU-protected pointer owned by an `struct
368 * lttng_session`or `struct lttng_event_notifier_group`.
369 */
daacdbfc 370 struct lttng_ust_ctx **pctx;
362a65de
MD
371};
372
bdb12629 373struct lttng_ust_session_private {
f69fe5fb 374 struct lttng_ust_session *pub; /* Public session interface */
bdb12629
MD
375
376 int been_active; /* Been active ? */
377 int objd; /* Object associated */
378 struct cds_list_head chan_head; /* Channel list head */
b187bcd5 379 struct cds_list_head counters_head; /* Counter list head */
bdb12629 380 struct cds_list_head events_head; /* list of events */
1e8023ed
MD
381 struct cds_list_head node; /* Session list */
382
383 /* List of non-synchronized enablers */
384 struct cds_list_head unsync_enablers_head;
385 /* List of synchronized enablers */
386 struct cds_list_head sync_enablers_head;
387
b187bcd5 388 struct cds_list_head enums_head;
bdb12629 389
b187bcd5
MD
390 struct lttng_ust_event_ht events_name_ht; /* ht of events, indexed by name */
391 struct lttng_ust_enum_ht enums_ht; /* ht of enumerations */
392
bdb12629 393 void *owner; /* object owner */
717c38f6 394 unsigned int tstate:1; /* Transient enable state */
717c38f6 395 unsigned int statedump_pending:1;
0c1264b0 396 struct lttng_ust_ctx *ctx; /* contexts for filters. */
9daacd1a
MD
397 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
398 bool uuid_set; /* Is uuid set ? */
bdb12629
MD
399};
400
036d17fb 401struct lttng_enum {
4e48b5d2 402 const struct lttng_ust_enum_desc *desc;
f69fe5fb 403 struct lttng_ust_session *session;
0c1264b0
MD
404 struct cds_list_head node; /* Enum list in session */
405 struct cds_hlist_node hlist; /* Session ht of enums */
406 uint64_t id; /* Enumeration ID in sessiond */
036d17fb
MD
407};
408
e7bc0ef6
MD
409struct lttng_ust_shm_handle;
410
14b6f891
MD
411struct lttng_ust_channel_buffer_ops_private {
412 struct lttng_ust_channel_buffer_ops *pub; /* Public channel buffer ops interface */
a880bae5 413
e7bc0ef6 414 struct lttng_ust_channel_buffer *(*channel_create)(const char *name,
a880bae5
MD
415 void *buf_addr,
416 size_t subbuf_size, size_t num_subbuf,
417 unsigned int switch_timer_interval,
418 unsigned int read_timer_interval,
419 unsigned char *uuid,
420 uint32_t chan_id,
421 const int *stream_fds, int nr_stream_fds,
422 int64_t blocking_timeout);
e7bc0ef6 423 void (*channel_destroy)(struct lttng_ust_channel_buffer *chan);
a880bae5
MD
424 /*
425 * packet_avail_size returns the available size in the current
426 * packet. Note that the size returned is only a hint, since it
427 * may change due to concurrent writes.
428 */
07539b34
MD
429 size_t (*packet_avail_size)(struct lttng_ust_channel_buffer *chan);
430 int (*is_finalized)(struct lttng_ust_channel_buffer *chan);
431 int (*is_disabled)(struct lttng_ust_channel_buffer *chan);
432 int (*flush_buffer)(struct lttng_ust_channel_buffer *chan);
a880bae5
MD
433};
434
e7bc0ef6
MD
435struct lttng_ust_channel_common_private {
436 struct lttng_ust_channel_common *pub; /* Public channel interface */
437
0c1264b0 438 int objd; /* Object associated with channel. */
717c38f6 439 unsigned int tstate:1; /* Transient enable state */
b187bcd5 440 bool coalesce_hits;
e7bc0ef6
MD
441};
442
443struct lttng_ust_channel_buffer_private {
444 struct lttng_ust_channel_common_private parent;
445
446 struct lttng_ust_channel_buffer *pub; /* Public channel buffer interface */
0c1264b0
MD
447 struct cds_list_head node; /* Channel list in session */
448 int header_type; /* 0: unset, 1: compact, 2: large */
449 unsigned int id; /* Channel ID */
e7bc0ef6 450 enum lttng_ust_abi_chan_type type;
0950190a 451 struct lttng_ust_ctx *ctx;
b5457df5 452 struct lttng_ust_ring_buffer_channel *rb_chan; /* Ring buffer channel */
e7bc0ef6
MD
453 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
454};
455
b187bcd5
MD
456struct lttng_ust_channel_counter_ops_private {
457 struct lttng_ust_channel_counter_ops *pub; /* Public channel counter ops interface */
458
459 struct lttng_ust_channel_counter *(*counter_create)(size_t nr_dimensions,
460 const struct lttng_counter_dimension *dimensions,
461 int64_t global_sum_step,
462 int global_counter_fd,
463 int nr_counter_cpu_fds,
464 const int *counter_cpu_fds,
465 bool is_daemon);
466 void (*counter_destroy)(struct lttng_ust_channel_counter *counter);
467 int (*counter_add)(struct lttng_ust_channel_counter *counter,
468 const size_t *dimension_indexes, int64_t v);
469 int (*counter_read)(struct lttng_ust_channel_counter *counter,
470 const size_t *dimension_indexes, int cpu,
471 int64_t *value, bool *overflow, bool *underflow);
472 int (*counter_aggregate)(struct lttng_ust_channel_counter *counter,
473 const size_t *dimension_indexes, int64_t *value,
474 bool *overflow, bool *underflow);
475 int (*counter_clear)(struct lttng_ust_channel_counter *counter,
476 const size_t *dimension_indexes);
477};
478
479struct lttng_ust_channel_counter_private {
480 struct lttng_ust_channel_common_private parent;
481
482 struct lttng_ust_channel_counter *pub; /* Public channel counter interface */
483 struct lib_counter *counter;
484 struct lttng_ust_channel_counter_ops *ops;
485
486 /* Event notifier group owner. */
487 struct lttng_event_notifier_group *event_notifier_group;
488
489 /* Session owner. */
490 struct lttng_session *session;
491 struct cds_list_head node; /* Counter list (in session) */
492 size_t free_index; /* Next index to allocate */
24f7193c 493 enum lttng_key_type dimension_key_types[LTTNG_COUNTER_DIMENSION_MAX];
b187bcd5
MD
494};
495
f0fde1c3
MD
496/*
497 * IMPORTANT: this structure is part of the ABI between the consumer
498 * daemon and the UST library within traced applications. Changing it
499 * breaks the UST communication protocol.
500 *
501 * TODO: remove unused fields on next UST communication protocol
502 * breaking update.
503 */
504struct lttng_ust_abi_channel_config {
505 void *unused1;
506 int unused2;
507 void *unused3;
508 void *unused4;
509 int unused5;
9a1d0634
MD
510 unsigned int _deprecated1;
511 unsigned int _deprecated2;
f0fde1c3
MD
512 struct cds_list_head unused6;
513 void *unused7;
514 int unused8;
515 void *unused9;
9a1d0634 516 unsigned int _deprecated3:1;
f0fde1c3
MD
517
518 /* Channel ID */
519 unsigned int id;
520 enum lttng_ust_abi_chan_type unused10;
521 unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */
522 int unused11:1;
523};
524
4e48b5d2
MD
525/* Global (filter), event and channel contexts. */
526struct lttng_ust_ctx {
527 struct lttng_ust_ctx_field *fields;
528 unsigned int nr_fields;
529 unsigned int allocated_fields;
530 unsigned int largest_align;
531};
532
533struct lttng_ust_registered_probe {
534 const struct lttng_ust_probe_desc *desc;
535
536 struct cds_list_head head; /* chain registered probes */
537 struct cds_list_head lazy_init_head;
538 int lazy; /* lazy registration */
539};
540
541/*
542 * Context field
543 */
544
545struct lttng_ust_ctx_field {
546 const struct lttng_ust_event_field *event_field;
b2e37d27
MD
547 size_t (*get_size)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
548 size_t offset);
549 void (*record)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
550 struct lttng_ust_ring_buffer_ctx *ctx,
551 struct lttng_ust_channel_buffer *chan);
552 void (*get_value)(void *priv, struct lttng_ust_probe_ctx *probe_ctx,
553 struct lttng_ust_ctx_value *value);
4e48b5d2
MD
554 void (*destroy)(void *priv);
555 void *priv;
556};
557
a084756d 558static inline
4e48b5d2 559const struct lttng_ust_type_integer *lttng_ust_get_type_integer(const struct lttng_ust_type_common *type)
a084756d
MD
560{
561 if (type->type != lttng_ust_type_integer)
562 return NULL;
4e48b5d2 563 return caa_container_of(type, const struct lttng_ust_type_integer, parent);
a084756d
MD
564}
565
566static inline
4e48b5d2 567const struct lttng_ust_type_float *lttng_ust_get_type_float(const struct lttng_ust_type_common *type)
a084756d
MD
568{
569 if (type->type != lttng_ust_type_float)
570 return NULL;
4e48b5d2 571 return caa_container_of(type, const struct lttng_ust_type_float, parent);
a084756d
MD
572}
573
574static inline
4e48b5d2 575const struct lttng_ust_type_string *lttng_ust_get_type_string(const struct lttng_ust_type_common *type)
a084756d
MD
576{
577 if (type->type != lttng_ust_type_string)
578 return NULL;
4e48b5d2 579 return caa_container_of(type, const struct lttng_ust_type_string, parent);
a084756d
MD
580}
581
582static inline
4e48b5d2 583const struct lttng_ust_type_enum *lttng_ust_get_type_enum(const struct lttng_ust_type_common *type)
a084756d
MD
584{
585 if (type->type != lttng_ust_type_enum)
586 return NULL;
4e48b5d2 587 return caa_container_of(type, const struct lttng_ust_type_enum, parent);
a084756d
MD
588}
589
590static inline
4e48b5d2 591const struct lttng_ust_type_array *lttng_ust_get_type_array(const struct lttng_ust_type_common *type)
a084756d
MD
592{
593 if (type->type != lttng_ust_type_array)
594 return NULL;
4e48b5d2 595 return caa_container_of(type, const struct lttng_ust_type_array, parent);
a084756d
MD
596}
597
598static inline
4e48b5d2 599const struct lttng_ust_type_sequence *lttng_ust_get_type_sequence(const struct lttng_ust_type_common *type)
a084756d
MD
600{
601 if (type->type != lttng_ust_type_sequence)
602 return NULL;
4e48b5d2 603 return caa_container_of(type, const struct lttng_ust_type_sequence, parent);
a084756d
MD
604}
605
606static inline
4e48b5d2 607const struct lttng_ust_type_struct *lttng_ust_get_type_struct(const struct lttng_ust_type_common *type)
a084756d
MD
608{
609 if (type->type != lttng_ust_type_struct)
610 return NULL;
4e48b5d2 611 return caa_container_of(type, const struct lttng_ust_type_struct, parent);
a084756d
MD
612}
613
4e48b5d2 614#define lttng_ust_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
5defa774 615 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_integer, { \
4e48b5d2
MD
616 .parent = { \
617 .type = lttng_ust_type_integer, \
618 }, \
619 .struct_size = sizeof(struct lttng_ust_type_integer), \
620 .size = (_size), \
621 .alignment = (_alignment), \
622 .signedness = (_signedness), \
baa8acf3 623 .reverse_byte_order = (_byte_order) != LTTNG_UST_BYTE_ORDER, \
4e48b5d2
MD
624 .base = (_base), \
625 }))
626
627#define lttng_ust_static_type_array_text(_length) \
5defa774 628 ((const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
4e48b5d2
MD
629 .parent = { \
630 .type = lttng_ust_type_array, \
631 }, \
632 .struct_size = sizeof(struct lttng_ust_type_array), \
633 .length = (_length), \
634 .alignment = 0, \
635 .encoding = lttng_ust_string_encoding_UTF8, \
636 .elem_type = lttng_ust_static_type_integer(sizeof(char) * CHAR_BIT, \
637 lttng_ust_rb_alignof(char) * CHAR_BIT, lttng_ust_is_signed_type(char), \
baa8acf3 638 LTTNG_UST_BYTE_ORDER, 10), \
4e48b5d2
MD
639 }))
640
641#define lttng_ust_static_event_field(_name, _type, _nowrite, _nofilter) \
5defa774 642 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
4e48b5d2
MD
643 .struct_size = sizeof(struct lttng_ust_event_field), \
644 .name = (_name), \
645 .type = (_type), \
646 .nowrite = (_nowrite), \
647 .nofilter = (_nofilter), \
648 })
649
650#define lttng_ust_static_ctx_field(_event_field, _get_size, _record, _get_value, _destroy, _priv) \
5defa774 651 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_ctx_field, { \
4e48b5d2
MD
652 .event_field = (_event_field), \
653 .get_size = (_get_size), \
654 .record = (_record), \
655 .get_value = (_get_value), \
656 .destroy = (_destroy), \
657 .priv = (_priv), \
658 })
a084756d 659
d871c65b 660static inline
b187bcd5 661struct lttng_event_enabler_common *lttng_event_notifier_enabler_as_enabler(
d8d2416d
FD
662 struct lttng_event_notifier_enabler *event_notifier_enabler)
663{
b187bcd5 664 return &event_notifier_enabler->parent;
d8d2416d 665}
d871c65b 666
1cc046d3
MD
667static inline
668struct lttng_ust_event_ht *lttng_get_event_ht_from_enabler(struct lttng_event_enabler_common *event_enabler)
669{
670 switch (event_enabler->enabler_type) {
671 case LTTNG_EVENT_ENABLER_TYPE_RECORDER: /* Fall-through */
672 case LTTNG_EVENT_ENABLER_TYPE_COUNTER:
673 {
674 struct lttng_event_enabler_session_common *event_enabler_session =
675 caa_container_of(event_enabler, struct lttng_event_enabler_session_common, parent);
676 return &event_enabler_session->chan->session->priv->events_name_ht;
677 }
678 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
679 {
680 struct lttng_event_notifier_enabler *event_notifier_enabler =
681 caa_container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
682 return &event_notifier_enabler->group->event_notifiers_ht;
683 }
684 default:
685 return NULL;
686 }
687}
d8d2416d 688
1cc046d3
MD
689static inline
690struct cds_list_head *lttng_get_event_list_head_from_enabler(struct lttng_event_enabler_common *event_enabler)
691{
692 switch (event_enabler->enabler_type) {
693 case LTTNG_EVENT_ENABLER_TYPE_RECORDER: /* Fall-through */
694 case LTTNG_EVENT_ENABLER_TYPE_COUNTER:
695 {
696 struct lttng_event_enabler_session_common *event_enabler_session =
697 caa_container_of(event_enabler, struct lttng_event_enabler_session_common, parent);
698 return &event_enabler_session->chan->session->priv->events_head;
699 }
700 case LTTNG_EVENT_ENABLER_TYPE_NOTIFIER:
701 {
702 struct lttng_event_notifier_enabler *event_notifier_enabler =
703 caa_container_of(event_enabler, struct lttng_event_notifier_enabler, parent);
704 return &event_notifier_enabler->group->event_notifiers_head;
705 }
706 default:
707 return NULL;
708 }
709}
7753d283 710
cbba5e04
MJ
711/* This is ABI between liblttng-ust and liblttng-ust-dl */
712void lttng_ust_dl_update(void *ip);
713
f69fe5fb 714struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session,
4e48b5d2 715 const struct lttng_ust_enum_desc *enum_desc)
1d18d519 716 __attribute__((visibility("hidden")));
7753d283 717
4e48b5d2 718
36c52fff 719#endif /* _UST_COMMON_UST_EVENTS_H */
This page took 0.083941 seconds and 5 git commands to generate.