Namespace tracepoint_init and tracepoint_exit
[lttng-ust.git] / liblttng-ust / ust-events-internal.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
c0c0989a
MJ
7#ifndef _LTTNG_UST_EVENTS_INTERNAL_H
8#define _LTTNG_UST_EVENTS_INTERNAL_H
9
d871c65b
FD
10#include <stdint.h>
11
12#include <urcu/list.h>
13#include <urcu/hlist.h>
14
864a1eda 15#include <ust-helper.h>
d871c65b
FD
16#include <lttng/ust-events.h>
17
8665f6a4
MJ
18enum lttng_enabler_format_type {
19 LTTNG_ENABLER_FORMAT_STAR_GLOB,
20 LTTNG_ENABLER_FORMAT_EVENT,
21};
22
23/*
24 * Enabler field, within whatever object is enabling an event. Target of
25 * backward reference.
26 */
27struct lttng_enabler {
28 enum lttng_enabler_format_type format_type;
29
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;
34
35 struct lttng_ust_event event_param;
36 unsigned int enabled:1;
37};
38
d871c65b
FD
39struct lttng_event_enabler {
40 struct lttng_enabler base;
41 struct cds_list_head node; /* per-session list of enablers */
42 struct lttng_channel *chan;
43 /*
44 * Unused, but kept around to make it explicit that the tracer can do
45 * it.
46 */
47 struct lttng_ctx *ctx;
48};
49
d8d2416d
FD
50struct lttng_event_notifier_enabler {
51 struct lttng_enabler base;
6566528b 52 uint64_t error_counter_index;
d37ecb3f
FD
53 struct cds_list_head node; /* per-app list of event_notifier enablers */
54 struct cds_list_head capture_bytecode_head;
d8d2416d
FD
55 struct lttng_event_notifier_group *group; /* weak ref */
56 uint64_t user_token; /* User-provided token */
d37ecb3f 57 uint64_t num_captures;
d8d2416d
FD
58};
59
ab249ecf
FD
60enum lttng_ust_bytecode_node_type {
61 LTTNG_UST_BYTECODE_NODE_TYPE_FILTER,
d37ecb3f 62 LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE,
ab249ecf
FD
63};
64
65struct lttng_ust_bytecode_node {
66 enum lttng_ust_bytecode_node_type type;
92495593
FD
67 struct cds_list_head node;
68 struct lttng_enabler *enabler;
ab249ecf
FD
69 struct {
70 uint32_t len;
71 uint32_t reloc_offset;
72 uint64_t seqnum;
73 char data[];
74 } bc;
92495593
FD
75};
76
77struct lttng_ust_excluder_node {
78 struct cds_list_head node;
79 struct lttng_enabler *enabler;
80 /*
81 * struct lttng_ust_event_exclusion had variable sized array,
82 * must be last field.
83 */
84 struct lttng_ust_event_exclusion excluder;
85};
86
bb7ad29d
MJ
87/* Data structures used by the tracer. */
88
89struct tp_list_entry {
90 struct lttng_ust_tracepoint_iter tp;
91 struct cds_list_head head;
92};
93
94struct lttng_ust_tracepoint_list {
95 struct tp_list_entry *iter;
96 struct cds_list_head head;
97};
98
99struct tp_field_list_entry {
100 struct lttng_ust_field_iter field;
101 struct cds_list_head head;
102};
103
104struct lttng_ust_field_list {
105 struct tp_field_list_entry *iter;
106 struct cds_list_head head;
107};
108
109/*
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
113 * object.
114 *
115 * For example, event rules "my_app:a*" and "my_app:ab*" will both match the
116 * event with the name "my_app:abc".
117 */
118struct lttng_enabler_ref {
119 struct cds_list_head node; /* enabler ref list */
120 struct lttng_enabler *ref; /* backward ref */
121};
122
123#define LTTNG_COUNTER_DIMENSION_MAX 8
124struct lttng_counter_dimension {
125 uint64_t size;
126 uint64_t underflow_index;
127 uint64_t overflow_index;
128 uint8_t has_underflow;
129 uint8_t has_overflow;
130};
131
132struct lttng_counter {
133 int objd;
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;
138};
139
140struct lttng_event_notifier_group {
141 int objd;
142 void *owner;
143 int notification_fd;
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. */
149
150 struct lttng_counter *error_counter;
151 size_t error_counter_len;
152};
153
154struct lttng_transport {
155 char *name;
156 struct cds_list_head node;
157 struct lttng_channel_ops ops;
158 const struct lttng_ust_lib_ring_buffer_config *client_config;
159};
160
161struct lttng_counter_transport {
162 char *name;
163 struct cds_list_head node;
164 struct lttng_counter_ops ops;
165 const struct lib_counter_config *client_config;
166};
167
d871c65b
FD
168static inline
169struct lttng_enabler *lttng_event_enabler_as_enabler(
170 struct lttng_event_enabler *event_enabler)
171{
172 return &event_enabler->base;
173}
174
d8d2416d
FD
175static inline
176struct lttng_enabler *lttng_event_notifier_enabler_as_enabler(
177 struct lttng_event_notifier_enabler *event_notifier_enabler)
178{
179 return &event_notifier_enabler->base;
180}
d871c65b
FD
181
182/*
183 * Allocate and initialize a `struct lttng_event_enabler` object.
184 *
185 * On success, returns a `struct lttng_event_enabler`,
186 * On memory error, returns NULL.
187 */
188LTTNG_HIDDEN
189struct lttng_event_enabler *lttng_event_enabler_create(
190 enum lttng_enabler_format_type format_type,
191 struct lttng_ust_event *event_param,
192 struct lttng_channel *chan);
193
194/*
195 * Destroy a `struct lttng_event_enabler` object.
196 */
197LTTNG_HIDDEN
198void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler);
199
200/*
201 * Enable a `struct lttng_event_enabler` object and all events related to this
202 * enabler.
203 */
204LTTNG_HIDDEN
205int lttng_event_enabler_enable(struct lttng_event_enabler *enabler);
206
207/*
208 * Disable a `struct lttng_event_enabler` object and all events related to this
209 * enabler.
210 */
211LTTNG_HIDDEN
212int lttng_event_enabler_disable(struct lttng_event_enabler *enabler);
213
214/*
215 * Attach filter bytecode program to `struct lttng_event_enabler` and all
216 * events related to this enabler.
217 */
218LTTNG_HIDDEN
a56fd376
FD
219int lttng_event_enabler_attach_filter_bytecode(
220 struct lttng_event_enabler *enabler,
ab89263e 221 struct lttng_ust_bytecode_node **bytecode);
d871c65b
FD
222
223/*
224 * Attach an application context to an event enabler.
225 *
226 * Not implemented.
227 */
228LTTNG_HIDDEN
229int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler,
230 struct lttng_ust_context *ctx);
231
232/*
233 * Attach exclusion list to `struct lttng_event_enabler` and all
234 * events related to this enabler.
235 */
236LTTNG_HIDDEN
237int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler,
e9fe6aad 238 struct lttng_ust_excluder_node **excluder);
d871c65b
FD
239
240/*
d37ecb3f
FD
241 * Synchronize bytecodes for the enabler and the instance (event or
242 * event_notifier).
d871c65b 243 *
621c07fc 244 * This function goes over all bytecode programs of the enabler (event or
d37ecb3f 245 * event_notifier enabler) to ensure each is linked to the provided instance.
d871c65b
FD
246 */
247LTTNG_HIDDEN
53b9d7db
FD
248void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc,
249 struct lttng_ctx **ctx,
621c07fc
FD
250 struct cds_list_head *instance_bytecode_runtime_head,
251 struct cds_list_head *enabler_bytecode_runtime_head);
d871c65b 252
d8d2416d
FD
253/*
254 * Allocate and initialize a `struct lttng_event_notifier_group` object.
255 *
256 * On success, returns a `struct lttng_triggre_group`,
257 * on memory error, returns NULL.
258 */
259LTTNG_HIDDEN
260struct lttng_event_notifier_group *lttng_event_notifier_group_create(void);
261
262/*
263 * Destroy a `struct lttng_event_notifier_group` object.
264 */
265LTTNG_HIDDEN
266void lttng_event_notifier_group_destroy(
267 struct lttng_event_notifier_group *event_notifier_group);
268
269/*
270 * Allocate and initialize a `struct lttng_event_notifier_enabler` object.
271 *
272 * On success, returns a `struct lttng_event_notifier_enabler`,
273 * On memory error, returns NULL.
274 */
275LTTNG_HIDDEN
276struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create(
277 struct lttng_event_notifier_group *event_notifier_group,
278 enum lttng_enabler_format_type format_type,
279 struct lttng_ust_event_notifier *event_notifier_param);
280
281/*
282 * Destroy a `struct lttng_event_notifier_enabler` object.
283 */
284LTTNG_HIDDEN
285void lttng_event_notifier_enabler_destroy(
286 struct lttng_event_notifier_enabler *event_notifier_enabler);
287
288/*
289 * Enable a `struct lttng_event_notifier_enabler` object and all event
290 * notifiers related to this enabler.
291 */
292LTTNG_HIDDEN
293int lttng_event_notifier_enabler_enable(
294 struct lttng_event_notifier_enabler *event_notifier_enabler);
295
296/*
297 * Disable a `struct lttng_event_notifier_enabler` object and all event
298 * notifiers related to this enabler.
299 */
300LTTNG_HIDDEN
301int lttng_event_notifier_enabler_disable(
302 struct lttng_event_notifier_enabler *event_notifier_enabler);
303
304/*
305 * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and
306 * all event notifiers related to this enabler.
307 */
308LTTNG_HIDDEN
a56fd376 309int lttng_event_notifier_enabler_attach_filter_bytecode(
d8d2416d 310 struct lttng_event_notifier_enabler *event_notifier_enabler,
ab89263e 311 struct lttng_ust_bytecode_node **bytecode);
d8d2416d 312
d37ecb3f
FD
313/*
314 * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and
315 * all event_notifiers related to this enabler.
316 */
317LTTNG_HIDDEN
318int lttng_event_notifier_enabler_attach_capture_bytecode(
319 struct lttng_event_notifier_enabler *event_notifier_enabler,
49cde654 320 struct lttng_ust_bytecode_node **bytecode);
d37ecb3f 321
d8d2416d
FD
322/*
323 * Attach exclusion list to `struct lttng_event_notifier_enabler` and all
324 * event notifiers related to this enabler.
325 */
326LTTNG_HIDDEN
327int lttng_event_notifier_enabler_attach_exclusion(
328 struct lttng_event_notifier_enabler *event_notifier_enabler,
e9fe6aad 329 struct lttng_ust_excluder_node **excluder);
d8d2416d 330
7753d283
MJ
331LTTNG_HIDDEN
332void lttng_free_event_filter_runtime(struct lttng_event *event);
333
d8d2416d
FD
334LTTNG_HIDDEN
335void lttng_free_event_notifier_filter_runtime(
336 struct lttng_event_notifier *event_notifier);
337
338/*
339 * Connect the probe on all enablers matching this event description.
340 * Called on library load.
341 */
342LTTNG_HIDDEN
343int lttng_fix_pending_event_notifiers(void);
344
67d4e8f5
MJ
345LTTNG_HIDDEN
346struct lttng_counter *lttng_ust_counter_create(
347 const char *counter_transport_name,
348 size_t number_dimensions, const struct lttng_counter_dimension *dimensions);
349
bd8c1787
MJ
350#ifdef HAVE_PERF_EVENT
351
352LTTNG_HIDDEN
353int lttng_add_perf_counter_to_ctx(uint32_t type,
354 uint64_t config,
355 const char *name,
356 struct lttng_ctx **ctx);
357LTTNG_HIDDEN
358int lttng_perf_counter_init(void);
359LTTNG_HIDDEN
360void lttng_perf_counter_exit(void);
361
362#else /* #ifdef HAVE_PERF_EVENT */
363
364static inline
365int lttng_add_perf_counter_to_ctx(uint32_t type,
366 uint64_t config,
367 const char *name,
368 struct lttng_ctx **ctx)
369{
370 return -ENOSYS;
371}
372static inline
373int lttng_perf_counter_init(void)
374{
375 return 0;
376}
377static inline
378void lttng_perf_counter_exit(void)
379{
380}
381#endif /* #else #ifdef HAVE_PERF_EVENT */
382
7753d283
MJ
383LTTNG_HIDDEN
384int lttng_probes_get_event_list(struct lttng_ust_tracepoint_list *list);
385LTTNG_HIDDEN
386void lttng_probes_prune_event_list(struct lttng_ust_tracepoint_list *list);
387
388LTTNG_HIDDEN
389int lttng_probes_get_field_list(struct lttng_ust_field_list *list);
390LTTNG_HIDDEN
391void lttng_probes_prune_field_list(struct lttng_ust_field_list *list);
392
393LTTNG_HIDDEN
394struct lttng_ust_tracepoint_iter *
395 lttng_ust_tracepoint_list_get_iter_next(struct lttng_ust_tracepoint_list *list);
396LTTNG_HIDDEN
397struct lttng_ust_field_iter *
398 lttng_ust_field_list_get_iter_next(struct lttng_ust_field_list *list);
399
400LTTNG_HIDDEN
401struct lttng_session *lttng_session_create(void);
402LTTNG_HIDDEN
403int lttng_session_enable(struct lttng_session *session);
404LTTNG_HIDDEN
405int lttng_session_disable(struct lttng_session *session);
406LTTNG_HIDDEN
407int lttng_session_statedump(struct lttng_session *session);
408LTTNG_HIDDEN
409void lttng_session_destroy(struct lttng_session *session);
410
411LTTNG_HIDDEN
412struct cds_list_head *lttng_get_sessions(void);
413
414LTTNG_HIDDEN
415void lttng_handle_pending_statedump(void *owner);
416
417LTTNG_HIDDEN
418struct lttng_channel *lttng_channel_create(struct lttng_session *session,
419 const char *transport_name,
420 void *buf_addr,
421 size_t subbuf_size, size_t num_subbuf,
422 unsigned int switch_timer_interval,
423 unsigned int read_timer_interval,
424 int **shm_fd, int **wait_fd,
425 uint64_t **memory_map_size,
426 struct lttng_channel *chan_priv_init);
427
428LTTNG_HIDDEN
429int lttng_channel_enable(struct lttng_channel *channel);
430LTTNG_HIDDEN
431int lttng_channel_disable(struct lttng_channel *channel);
432
433LTTNG_HIDDEN
434void lttng_transport_register(struct lttng_transport *transport);
435LTTNG_HIDDEN
436void lttng_transport_unregister(struct lttng_transport *transport);
437
438LTTNG_HIDDEN
439void lttng_probe_provider_unregister_events(struct lttng_probe_desc *desc);
440
441LTTNG_HIDDEN
442int lttng_fix_pending_events(void);
443
444LTTNG_HIDDEN
445struct cds_list_head *lttng_get_probe_list_head(void);
446
447LTTNG_HIDDEN
448struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_session *session,
449 const struct lttng_enum_desc *enum_desc);
450
d871c65b 451#endif /* _LTTNG_UST_EVENTS_INTERNAL_H */
This page took 0.041247 seconds and 4 git commands to generate.