2 * SPDX-License-Identifier: MIT
4 * Copyright 2019 (c) Francis Deslauriers <francis.deslauriers@efficios.com>
7 #ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8 #define _LTTNG_UST_EVENTS_INTERNAL_H
12 #include <urcu/list.h>
13 #include <urcu/hlist.h>
15 #include <ust-helper.h>
16 #include <lttng/ust-events.h>
18 enum lttng_enabler_format_type
{
19 LTTNG_ENABLER_FORMAT_STAR_GLOB
,
20 LTTNG_ENABLER_FORMAT_EVENT
,
24 * Enabler field, within whatever object is enabling an event. Target of
27 struct lttng_enabler
{
28 enum lttng_enabler_format_type format_type
;
30 /* head list of struct lttng_ust_filter_bytecode_node */
31 struct cds_list_head filter_bytecode_head
;
32 /* head list of struct lttng_ust_excluder_node */
33 struct cds_list_head excluder_head
;
35 struct lttng_ust_event event_param
;
36 unsigned int enabled
:1;
39 struct lttng_event_enabler
{
40 struct lttng_enabler base
;
41 struct cds_list_head node
; /* per-session list of enablers */
42 struct lttng_channel
*chan
;
44 * Unused, but kept around to make it explicit that the tracer can do
47 struct lttng_ctx
*ctx
;
50 struct lttng_event_notifier_enabler
{
51 struct lttng_enabler base
;
52 uint64_t error_counter_index
;
53 struct cds_list_head node
; /* per-app list of event_notifier enablers */
54 struct cds_list_head capture_bytecode_head
;
55 struct lttng_event_notifier_group
*group
; /* weak ref */
56 uint64_t user_token
; /* User-provided token */
57 uint64_t num_captures
;
60 enum lttng_ust_bytecode_node_type
{
61 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER
,
62 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE
,
65 struct lttng_ust_bytecode_node
{
66 enum lttng_ust_bytecode_node_type type
;
67 struct cds_list_head node
;
68 struct lttng_enabler
*enabler
;
71 uint32_t reloc_offset
;
77 struct lttng_ust_excluder_node
{
78 struct cds_list_head node
;
79 struct lttng_enabler
*enabler
;
81 * struct lttng_ust_event_exclusion had variable sized array,
84 struct lttng_ust_event_exclusion excluder
;
87 /* Data structures used by the tracer. */
89 struct tp_list_entry
{
90 struct lttng_ust_tracepoint_iter tp
;
91 struct cds_list_head head
;
94 struct lttng_ust_tracepoint_list
{
95 struct tp_list_entry
*iter
;
96 struct cds_list_head head
;
99 struct tp_field_list_entry
{
100 struct lttng_ust_field_iter field
;
101 struct cds_list_head head
;
104 struct lttng_ust_field_list
{
105 struct tp_field_list_entry
*iter
;
106 struct cds_list_head head
;
110 * Objects in a linked-list of enablers, owned by an event or event_notifier.
111 * This is used because an event (or a event_notifier) can be enabled by more
112 * than one enabler and we want a quick way to iterate over all enablers of an
115 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
116 * event with the name "my_app:abc".
118 struct lttng_enabler_ref
{
119 struct cds_list_head node
; /* enabler ref list */
120 struct lttng_enabler
*ref
; /* backward ref */
123 #define LTTNG_COUNTER_DIMENSION_MAX 8
124 struct lttng_counter_dimension
{
126 uint64_t underflow_index
;
127 uint64_t overflow_index
;
128 uint8_t has_underflow
;
129 uint8_t has_overflow
;
132 struct lttng_counter
{
134 struct lttng_event_notifier_group
*event_notifier_group
; /* owner */
135 struct lttng_counter_transport
*transport
;
136 struct lib_counter
*counter
;
137 struct lttng_counter_ops
*ops
;
140 struct lttng_event_notifier_group
{
144 struct cds_list_head node
; /* Event notifier group handle list */
145 struct cds_list_head enablers_head
;
146 struct cds_list_head event_notifiers_head
; /* list of event_notifiers */
147 struct lttng_ust_event_notifier_ht event_notifiers_ht
; /* hashtable of event_notifiers */
148 struct lttng_ctx
*ctx
; /* contexts for filters. */
150 struct lttng_counter
*error_counter
;
151 size_t error_counter_len
;
154 struct lttng_transport
{
156 struct cds_list_head node
;
157 struct lttng_channel_ops ops
;
158 const struct lttng_ust_lib_ring_buffer_config
*client_config
;
161 struct lttng_counter_transport
{
163 struct cds_list_head node
;
164 struct lttng_counter_ops ops
;
165 const struct lib_counter_config
*client_config
;
168 struct lttng_ust_event_common_private
{
169 struct lttng_event_common
*pub
; /* Public event interface */
171 const struct lttng_event_desc
*desc
;
172 /* Backward references: list of lttng_enabler_ref (ref to enablers) */
173 struct cds_list_head enablers_ref_head
;
174 int registered
; /* has reg'd tracepoint probe */
177 struct lttng_ust_event_recorder_private
{
178 struct lttng_ust_event_common_private parent
;
180 struct lttng_ust_event_recorder
*pub
; /* Public event interface */
181 struct cds_list_head node
; /* Event list in session */
182 struct cds_hlist_node hlist
; /* session ht of events */
185 struct lttng_ust_bytecode_runtime_private
{
186 struct bytecode_runtime
*pub
; /* Public bytecode runtime interface */
188 struct lttng_ust_bytecode_node
*bc
;
191 * Pointer to a URCU-protected pointer owned by an `struct
192 * lttng_session`or `struct lttng_event_notifier_group`.
194 struct lttng_ctx
**pctx
;
197 struct lttng_ust_session_private
{
198 struct lttng_session
*pub
; /* Public session interface */
200 int been_active
; /* Been active ? */
201 int objd
; /* Object associated */
202 struct cds_list_head chan_head
; /* Channel list head */
203 struct cds_list_head events_head
; /* list of events */
204 struct cds_list_head node
; /* Session list */
207 /* List of enablers */
208 struct cds_list_head enablers_head
;
209 struct lttng_ust_event_ht events_ht
; /* ht of events */
210 void *owner
; /* object owner */
211 int tstate
:1; /* Transient enable state */
214 int statedump_pending
:1;
217 struct lttng_ust_enum_ht enums_ht
; /* ht of enumerations */
218 struct cds_list_head enums_head
;
219 struct lttng_ctx
*ctx
; /* contexts for filters. */
223 struct lttng_enabler
*lttng_event_enabler_as_enabler(
224 struct lttng_event_enabler
*event_enabler
)
226 return &event_enabler
->base
;
230 struct lttng_enabler
*lttng_event_notifier_enabler_as_enabler(
231 struct lttng_event_notifier_enabler
*event_notifier_enabler
)
233 return &event_notifier_enabler
->base
;
237 * Allocate and initialize a `struct lttng_event_enabler` object.
239 * On success, returns a `struct lttng_event_enabler`,
240 * On memory error, returns NULL.
243 struct lttng_event_enabler
*lttng_event_enabler_create(
244 enum lttng_enabler_format_type format_type
,
245 struct lttng_ust_event
*event_param
,
246 struct lttng_channel
*chan
);
249 * Destroy a `struct lttng_event_enabler` object.
252 void lttng_event_enabler_destroy(struct lttng_event_enabler
*enabler
);
255 * Enable a `struct lttng_event_enabler` object and all events related to this
259 int lttng_event_enabler_enable(struct lttng_event_enabler
*enabler
);
262 * Disable a `struct lttng_event_enabler` object and all events related to this
266 int lttng_event_enabler_disable(struct lttng_event_enabler
*enabler
);
269 * Attach filter bytecode program to `struct lttng_event_enabler` and all
270 * events related to this enabler.
273 int lttng_event_enabler_attach_filter_bytecode(
274 struct lttng_event_enabler
*enabler
,
275 struct lttng_ust_bytecode_node
**bytecode
);
278 * Attach an application context to an event enabler.
283 int lttng_event_enabler_attach_context(struct lttng_event_enabler
*enabler
,
284 struct lttng_ust_context
*ctx
);
287 * Attach exclusion list to `struct lttng_event_enabler` and all
288 * events related to this enabler.
291 int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler
*enabler
,
292 struct lttng_ust_excluder_node
**excluder
);
295 * Synchronize bytecodes for the enabler and the instance (event or
298 * This function goes over all bytecode programs of the enabler (event or
299 * event_notifier enabler) to ensure each is linked to the provided instance.
302 void lttng_enabler_link_bytecode(const struct lttng_event_desc
*event_desc
,
303 struct lttng_ctx
**ctx
,
304 struct cds_list_head
*instance_bytecode_runtime_head
,
305 struct cds_list_head
*enabler_bytecode_runtime_head
);
308 * Allocate and initialize a `struct lttng_event_notifier_group` object.
310 * On success, returns a `struct lttng_triggre_group`,
311 * on memory error, returns NULL.
314 struct lttng_event_notifier_group
*lttng_event_notifier_group_create(void);
317 * Destroy a `struct lttng_event_notifier_group` object.
320 void lttng_event_notifier_group_destroy(
321 struct lttng_event_notifier_group
*event_notifier_group
);
324 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
326 * On success, returns a `struct lttng_event_notifier_enabler`,
327 * On memory error, returns NULL.
330 struct lttng_event_notifier_enabler
*lttng_event_notifier_enabler_create(
331 struct lttng_event_notifier_group
*event_notifier_group
,
332 enum lttng_enabler_format_type format_type
,
333 struct lttng_ust_event_notifier
*event_notifier_param
);
336 * Destroy a `struct lttng_event_notifier_enabler` object.
339 void lttng_event_notifier_enabler_destroy(
340 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
343 * Enable a `struct lttng_event_notifier_enabler` object and all event
344 * notifiers related to this enabler.
347 int lttng_event_notifier_enabler_enable(
348 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
351 * Disable a `struct lttng_event_notifier_enabler` object and all event
352 * notifiers related to this enabler.
355 int lttng_event_notifier_enabler_disable(
356 struct lttng_event_notifier_enabler
*event_notifier_enabler
);
359 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
360 * all event notifiers related to this enabler.
363 int lttng_event_notifier_enabler_attach_filter_bytecode(
364 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
365 struct lttng_ust_bytecode_node
**bytecode
);
368 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
369 * all event_notifiers related to this enabler.
372 int lttng_event_notifier_enabler_attach_capture_bytecode(
373 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
374 struct lttng_ust_bytecode_node
**bytecode
);
377 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
378 * event notifiers related to this enabler.
381 int lttng_event_notifier_enabler_attach_exclusion(
382 struct lttng_event_notifier_enabler
*event_notifier_enabler
,
383 struct lttng_ust_excluder_node
**excluder
);
386 void lttng_free_event_recorder_filter_runtime(struct lttng_ust_event_recorder
*event_recorder
);
389 void lttng_free_event_notifier_filter_runtime(
390 struct lttng_event_notifier
*event_notifier
);
393 * Connect the probe on all enablers matching this event description.
394 * Called on library load.
397 int lttng_fix_pending_event_notifiers(void);
400 struct lttng_counter
*lttng_ust_counter_create(
401 const char *counter_transport_name
,
402 size_t number_dimensions
, const struct lttng_counter_dimension
*dimensions
);
404 #ifdef HAVE_PERF_EVENT
407 int lttng_add_perf_counter_to_ctx(uint32_t type
,
410 struct lttng_ctx
**ctx
);
412 int lttng_perf_counter_init(void);
414 void lttng_perf_counter_exit(void);
416 #else /* #ifdef HAVE_PERF_EVENT */
419 int lttng_add_perf_counter_to_ctx(uint32_t type
,
422 struct lttng_ctx
**ctx
)
427 int lttng_perf_counter_init(void)
432 void lttng_perf_counter_exit(void)
435 #endif /* #else #ifdef HAVE_PERF_EVENT */
438 int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list
*list
);
440 void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list
*list
);
443 int lttng_probes_get_field_list(struct lttng_ust_field_list
*list
);
445 void lttng_probes_prune_field_list(struct lttng_ust_field_list
*list
);
448 struct lttng_ust_tracepoint_iter
*
449 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list
*list
);
451 struct lttng_ust_field_iter
*
452 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list
*list
);
455 struct lttng_session
*lttng_session_create(void);
457 int lttng_session_enable(struct lttng_session
*session
);
459 int lttng_session_disable(struct lttng_session
*session
);
461 int lttng_session_statedump(struct lttng_session
*session
);
463 void lttng_session_destroy(struct lttng_session
*session
);
466 struct cds_list_head
*lttng_get_sessions(void);
469 void lttng_handle_pending_statedump(void *owner
);
472 struct lttng_channel
*lttng_channel_create(struct lttng_session
*session
,
473 const char *transport_name
,
475 size_t subbuf_size
, size_t num_subbuf
,
476 unsigned int switch_timer_interval
,
477 unsigned int read_timer_interval
,
478 int **shm_fd
, int **wait_fd
,
479 uint64_t **memory_map_size
,
480 struct lttng_channel
*chan_priv_init
);
483 int lttng_channel_enable(struct lttng_channel
*channel
);
485 int lttng_channel_disable(struct lttng_channel
*channel
);
488 void lttng_transport_register(struct lttng_transport
*transport
);
490 void lttng_transport_unregister(struct lttng_transport
*transport
);
493 void lttng_probe_provider_unregister_events(struct lttng_probe_desc
*desc
);
496 int lttng_fix_pending_events(void);
499 struct cds_list_head
*lttng_get_probe_list_head(void);
502 struct lttng_enum
*lttng_ust_enum_get_from_desc(struct lttng_session
*session
,
503 const struct lttng_enum_desc
*enum_desc
);
505 #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */