Commit | Line | Data |
---|---|---|
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 | ||
18 | struct lttng_event_enabler { | |
19 | struct lttng_enabler base; | |
20 | struct cds_list_head node; /* per-session list of enablers */ | |
21 | struct lttng_channel *chan; | |
22 | /* | |
23 | * Unused, but kept around to make it explicit that the tracer can do | |
24 | * it. | |
25 | */ | |
26 | struct lttng_ctx *ctx; | |
27 | }; | |
28 | ||
d8d2416d FD |
29 | struct lttng_event_notifier_enabler { |
30 | struct lttng_enabler base; | |
6566528b | 31 | uint64_t error_counter_index; |
d37ecb3f FD |
32 | struct cds_list_head node; /* per-app list of event_notifier enablers */ |
33 | struct cds_list_head capture_bytecode_head; | |
d8d2416d FD |
34 | struct lttng_event_notifier_group *group; /* weak ref */ |
35 | uint64_t user_token; /* User-provided token */ | |
d37ecb3f | 36 | uint64_t num_captures; |
d8d2416d FD |
37 | }; |
38 | ||
ab249ecf FD |
39 | enum lttng_ust_bytecode_node_type { |
40 | LTTNG_UST_BYTECODE_NODE_TYPE_FILTER, | |
d37ecb3f | 41 | LTTNG_UST_BYTECODE_NODE_TYPE_CAPTURE, |
ab249ecf FD |
42 | }; |
43 | ||
44 | struct lttng_ust_bytecode_node { | |
45 | enum lttng_ust_bytecode_node_type type; | |
92495593 FD |
46 | struct cds_list_head node; |
47 | struct lttng_enabler *enabler; | |
ab249ecf FD |
48 | struct { |
49 | uint32_t len; | |
50 | uint32_t reloc_offset; | |
51 | uint64_t seqnum; | |
52 | char data[]; | |
53 | } bc; | |
92495593 FD |
54 | }; |
55 | ||
56 | struct lttng_ust_excluder_node { | |
57 | struct cds_list_head node; | |
58 | struct lttng_enabler *enabler; | |
59 | /* | |
60 | * struct lttng_ust_event_exclusion had variable sized array, | |
61 | * must be last field. | |
62 | */ | |
63 | struct lttng_ust_event_exclusion excluder; | |
64 | }; | |
65 | ||
d871c65b FD |
66 | static inline |
67 | struct lttng_enabler *lttng_event_enabler_as_enabler( | |
68 | struct lttng_event_enabler *event_enabler) | |
69 | { | |
70 | return &event_enabler->base; | |
71 | } | |
72 | ||
d8d2416d FD |
73 | static inline |
74 | struct lttng_enabler *lttng_event_notifier_enabler_as_enabler( | |
75 | struct lttng_event_notifier_enabler *event_notifier_enabler) | |
76 | { | |
77 | return &event_notifier_enabler->base; | |
78 | } | |
d871c65b FD |
79 | |
80 | /* | |
81 | * Allocate and initialize a `struct lttng_event_enabler` object. | |
82 | * | |
83 | * On success, returns a `struct lttng_event_enabler`, | |
84 | * On memory error, returns NULL. | |
85 | */ | |
86 | LTTNG_HIDDEN | |
87 | struct lttng_event_enabler *lttng_event_enabler_create( | |
88 | enum lttng_enabler_format_type format_type, | |
89 | struct lttng_ust_event *event_param, | |
90 | struct lttng_channel *chan); | |
91 | ||
92 | /* | |
93 | * Destroy a `struct lttng_event_enabler` object. | |
94 | */ | |
95 | LTTNG_HIDDEN | |
96 | void lttng_event_enabler_destroy(struct lttng_event_enabler *enabler); | |
97 | ||
98 | /* | |
99 | * Enable a `struct lttng_event_enabler` object and all events related to this | |
100 | * enabler. | |
101 | */ | |
102 | LTTNG_HIDDEN | |
103 | int lttng_event_enabler_enable(struct lttng_event_enabler *enabler); | |
104 | ||
105 | /* | |
106 | * Disable a `struct lttng_event_enabler` object and all events related to this | |
107 | * enabler. | |
108 | */ | |
109 | LTTNG_HIDDEN | |
110 | int lttng_event_enabler_disable(struct lttng_event_enabler *enabler); | |
111 | ||
112 | /* | |
113 | * Attach filter bytecode program to `struct lttng_event_enabler` and all | |
114 | * events related to this enabler. | |
115 | */ | |
116 | LTTNG_HIDDEN | |
a56fd376 FD |
117 | int lttng_event_enabler_attach_filter_bytecode( |
118 | struct lttng_event_enabler *enabler, | |
ab89263e | 119 | struct lttng_ust_bytecode_node **bytecode); |
d871c65b FD |
120 | |
121 | /* | |
122 | * Attach an application context to an event enabler. | |
123 | * | |
124 | * Not implemented. | |
125 | */ | |
126 | LTTNG_HIDDEN | |
127 | int lttng_event_enabler_attach_context(struct lttng_event_enabler *enabler, | |
128 | struct lttng_ust_context *ctx); | |
129 | ||
130 | /* | |
131 | * Attach exclusion list to `struct lttng_event_enabler` and all | |
132 | * events related to this enabler. | |
133 | */ | |
134 | LTTNG_HIDDEN | |
135 | int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, | |
e9fe6aad | 136 | struct lttng_ust_excluder_node **excluder); |
d871c65b FD |
137 | |
138 | /* | |
d37ecb3f FD |
139 | * Synchronize bytecodes for the enabler and the instance (event or |
140 | * event_notifier). | |
d871c65b | 141 | * |
621c07fc | 142 | * This function goes over all bytecode programs of the enabler (event or |
d37ecb3f | 143 | * event_notifier enabler) to ensure each is linked to the provided instance. |
d871c65b FD |
144 | */ |
145 | LTTNG_HIDDEN | |
53b9d7db FD |
146 | void lttng_enabler_link_bytecode(const struct lttng_event_desc *event_desc, |
147 | struct lttng_ctx **ctx, | |
621c07fc FD |
148 | struct cds_list_head *instance_bytecode_runtime_head, |
149 | struct cds_list_head *enabler_bytecode_runtime_head); | |
d871c65b | 150 | |
d8d2416d FD |
151 | /* |
152 | * Allocate and initialize a `struct lttng_event_notifier_group` object. | |
153 | * | |
154 | * On success, returns a `struct lttng_triggre_group`, | |
155 | * on memory error, returns NULL. | |
156 | */ | |
157 | LTTNG_HIDDEN | |
158 | struct lttng_event_notifier_group *lttng_event_notifier_group_create(void); | |
159 | ||
160 | /* | |
161 | * Destroy a `struct lttng_event_notifier_group` object. | |
162 | */ | |
163 | LTTNG_HIDDEN | |
164 | void lttng_event_notifier_group_destroy( | |
165 | struct lttng_event_notifier_group *event_notifier_group); | |
166 | ||
167 | /* | |
168 | * Allocate and initialize a `struct lttng_event_notifier_enabler` object. | |
169 | * | |
170 | * On success, returns a `struct lttng_event_notifier_enabler`, | |
171 | * On memory error, returns NULL. | |
172 | */ | |
173 | LTTNG_HIDDEN | |
174 | struct lttng_event_notifier_enabler *lttng_event_notifier_enabler_create( | |
175 | struct lttng_event_notifier_group *event_notifier_group, | |
176 | enum lttng_enabler_format_type format_type, | |
177 | struct lttng_ust_event_notifier *event_notifier_param); | |
178 | ||
179 | /* | |
180 | * Destroy a `struct lttng_event_notifier_enabler` object. | |
181 | */ | |
182 | LTTNG_HIDDEN | |
183 | void lttng_event_notifier_enabler_destroy( | |
184 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
185 | ||
186 | /* | |
187 | * Enable a `struct lttng_event_notifier_enabler` object and all event | |
188 | * notifiers related to this enabler. | |
189 | */ | |
190 | LTTNG_HIDDEN | |
191 | int lttng_event_notifier_enabler_enable( | |
192 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
193 | ||
194 | /* | |
195 | * Disable a `struct lttng_event_notifier_enabler` object and all event | |
196 | * notifiers related to this enabler. | |
197 | */ | |
198 | LTTNG_HIDDEN | |
199 | int lttng_event_notifier_enabler_disable( | |
200 | struct lttng_event_notifier_enabler *event_notifier_enabler); | |
201 | ||
202 | /* | |
203 | * Attach filter bytecode program to `struct lttng_event_notifier_enabler` and | |
204 | * all event notifiers related to this enabler. | |
205 | */ | |
206 | LTTNG_HIDDEN | |
a56fd376 | 207 | int lttng_event_notifier_enabler_attach_filter_bytecode( |
d8d2416d | 208 | struct lttng_event_notifier_enabler *event_notifier_enabler, |
ab89263e | 209 | struct lttng_ust_bytecode_node **bytecode); |
d8d2416d | 210 | |
d37ecb3f FD |
211 | /* |
212 | * Attach capture bytecode program to `struct lttng_event_notifier_enabler` and | |
213 | * all event_notifiers related to this enabler. | |
214 | */ | |
215 | LTTNG_HIDDEN | |
216 | int lttng_event_notifier_enabler_attach_capture_bytecode( | |
217 | struct lttng_event_notifier_enabler *event_notifier_enabler, | |
49cde654 | 218 | struct lttng_ust_bytecode_node **bytecode); |
d37ecb3f | 219 | |
d8d2416d FD |
220 | /* |
221 | * Attach exclusion list to `struct lttng_event_notifier_enabler` and all | |
222 | * event notifiers related to this enabler. | |
223 | */ | |
224 | LTTNG_HIDDEN | |
225 | int lttng_event_notifier_enabler_attach_exclusion( | |
226 | struct lttng_event_notifier_enabler *event_notifier_enabler, | |
e9fe6aad | 227 | struct lttng_ust_excluder_node **excluder); |
d8d2416d FD |
228 | |
229 | LTTNG_HIDDEN | |
230 | void lttng_free_event_notifier_filter_runtime( | |
231 | struct lttng_event_notifier *event_notifier); | |
232 | ||
233 | /* | |
234 | * Connect the probe on all enablers matching this event description. | |
235 | * Called on library load. | |
236 | */ | |
237 | LTTNG_HIDDEN | |
238 | int lttng_fix_pending_event_notifiers(void); | |
239 | ||
67d4e8f5 MJ |
240 | LTTNG_HIDDEN |
241 | struct lttng_counter *lttng_ust_counter_create( | |
242 | const char *counter_transport_name, | |
243 | size_t number_dimensions, const struct lttng_counter_dimension *dimensions); | |
244 | ||
bd8c1787 MJ |
245 | #ifdef HAVE_PERF_EVENT |
246 | ||
247 | LTTNG_HIDDEN | |
248 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
249 | uint64_t config, | |
250 | const char *name, | |
251 | struct lttng_ctx **ctx); | |
252 | LTTNG_HIDDEN | |
253 | int lttng_perf_counter_init(void); | |
254 | LTTNG_HIDDEN | |
255 | void lttng_perf_counter_exit(void); | |
256 | ||
257 | #else /* #ifdef HAVE_PERF_EVENT */ | |
258 | ||
259 | static inline | |
260 | int lttng_add_perf_counter_to_ctx(uint32_t type, | |
261 | uint64_t config, | |
262 | const char *name, | |
263 | struct lttng_ctx **ctx) | |
264 | { | |
265 | return -ENOSYS; | |
266 | } | |
267 | static inline | |
268 | int lttng_perf_counter_init(void) | |
269 | { | |
270 | return 0; | |
271 | } | |
272 | static inline | |
273 | void lttng_perf_counter_exit(void) | |
274 | { | |
275 | } | |
276 | #endif /* #else #ifdef HAVE_PERF_EVENT */ | |
277 | ||
d871c65b | 278 | #endif /* _LTTNG_UST_EVENTS_INTERNAL_H */ |