Commit | Line | Data |
---|---|---|
97ee3a89 | 1 | /* |
21cf9b6b | 2 | * Copyright (C) 2011 EfficiOS Inc. |
ab5be9fa | 3 | * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
97ee3a89 | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
97ee3a89 | 6 | * |
97ee3a89 DG |
7 | */ |
8 | ||
9 | #ifndef _LTT_TRACE_UST_H | |
10 | #define _LTT_TRACE_UST_H | |
11 | ||
12 | #include <limits.h> | |
13 | #include <urcu/list.h> | |
bec39940 | 14 | |
c9e313bc SM |
15 | #include <common/defaults.hpp> |
16 | #include <common/hashtable/hashtable.hpp> | |
17 | #include <common/tracker.hpp> | |
159b042f | 18 | #include <lttng/lttng.h> |
153d4c0e | 19 | #include <lttng/trace-format-descriptor-internal.hpp> |
3bd1e081 | 20 | |
c9e313bc SM |
21 | #include "consumer.hpp" |
22 | #include "lttng-ust-ctl.hpp" | |
97ee3a89 | 23 | |
7c1d2758 JG |
24 | struct agent; |
25 | ||
18eace3b DG |
26 | struct ltt_ust_ht_key { |
27 | const char *name; | |
2b00d462 | 28 | const struct lttng_bytecode *filter; |
fc4b93fa | 29 | enum lttng_ust_abi_loglevel_type loglevel_type; |
b953b8cd | 30 | int loglevel_value; |
7724731b | 31 | const struct lttng_event_exclusion *exclusion; |
18eace3b DG |
32 | }; |
33 | ||
f6a9efaa DG |
34 | /* Context hash table nodes */ |
35 | struct ltt_ust_context { | |
bdf64013 | 36 | struct lttng_ust_context_attr ctx; |
bec39940 | 37 | struct lttng_ht_node_ulong node; |
31746f93 | 38 | struct cds_list_head list; |
97ee3a89 DG |
39 | }; |
40 | ||
41 | /* UST event */ | |
42 | struct ltt_ust_event { | |
37357452 | 43 | unsigned int enabled; |
fc4b93fa | 44 | struct lttng_ust_abi_event attr; |
bec39940 | 45 | struct lttng_ht_node_str node; |
6b453b5e | 46 | char *filter_expression; |
2b00d462 | 47 | struct lttng_bytecode *filter; |
40024f8a | 48 | struct lttng_event_exclusion *exclusion; |
5b37cc51 JG |
49 | /* |
50 | * An internal event is an event which was created by the session daemon | |
51 | * through which, for example, events emitted in Agent domains are | |
52 | * "funelled". This is used to hide internal events from external | |
53 | * clients as they should never be modified by the external world. | |
54 | */ | |
88f06f15 | 55 | bool internal; |
2bdd86d4 MD |
56 | }; |
57 | ||
97ee3a89 DG |
58 | /* UST channel */ |
59 | struct ltt_ust_channel { | |
7972aab2 | 60 | uint64_t id; /* unique id per session. */ |
37357452 | 61 | unsigned int enabled; |
51755dc8 JG |
62 | /* |
63 | * A UST channel can be part of a userspace sub-domain such as JUL, | |
64 | * Log4j, Python. | |
65 | */ | |
66 | enum lttng_domain_type domain; | |
fc4b93fa MD |
67 | char name[LTTNG_UST_ABI_SYM_NAME_LEN]; |
68 | struct lttng_ust_abi_channel_attr attr; | |
bec39940 | 69 | struct lttng_ht *ctx; |
31746f93 | 70 | struct cds_list_head ctx_list; |
bec39940 DG |
71 | struct lttng_ht *events; |
72 | struct lttng_ht_node_str node; | |
1624d5b7 JD |
73 | uint64_t tracefile_size; |
74 | uint64_t tracefile_count; | |
fb83fe64 JD |
75 | uint64_t per_pid_closed_app_discarded; |
76 | uint64_t per_pid_closed_app_lost; | |
e9404c27 | 77 | uint64_t monitor_timer_interval; |
97ee3a89 DG |
78 | }; |
79 | ||
f6a9efaa DG |
80 | /* UST domain global (LTTNG_DOMAIN_UST) */ |
81 | struct ltt_ust_domain_global { | |
bec39940 | 82 | struct lttng_ht *channels; |
7972aab2 | 83 | struct cds_list_head registry_buffer_uid_list; |
f6a9efaa DG |
84 | }; |
85 | ||
55c9e7ca | 86 | struct ust_id_tracker_node { |
a9ad0c8f MD |
87 | struct lttng_ht_node_ulong node; |
88 | }; | |
89 | ||
55c9e7ca | 90 | struct ust_id_tracker { |
a9ad0c8f MD |
91 | struct lttng_ht *ht; |
92 | }; | |
93 | ||
97ee3a89 DG |
94 | /* UST session */ |
95 | struct ltt_ust_session { | |
63dcd955 JR |
96 | ltt_ust_session() = default; |
97 | ~ltt_ust_session() = default; | |
98 | ||
99 | uint64_t id{}; /* Unique identifier of session */ | |
100 | struct ltt_ust_domain_global domain_global {}; | |
fefd409b | 101 | /* Hash table of agent indexed by agent domain. */ |
63dcd955 | 102 | struct lttng_ht *agents{}; |
6df2e2c9 | 103 | /* UID/GID of the user owning the session */ |
63dcd955 JR |
104 | uid_t uid{}; |
105 | gid_t gid{}; | |
14fb1ebe | 106 | /* Is the session active meaning has is been started or stopped. */ |
63dcd955 JR |
107 | bool active{false}; |
108 | struct consumer_output *consumer{}; | |
f3f0db50 | 109 | /* Sequence number for filters so the tracer knows the ordering. */ |
63dcd955 | 110 | uint64_t filter_seq_num{}; |
7972aab2 | 111 | /* This indicates which type of buffer this session is set for. */ |
63dcd955 | 112 | enum lttng_buffer_type buffer_type {}; |
7972aab2 | 113 | /* If set to 1, the buffer_type can not be changed anymore. */ |
63dcd955 | 114 | int buffer_type_changed{}; |
7972aab2 | 115 | /* For per UID buffer, every buffer reg object is kept of this session */ |
63dcd955 | 116 | struct cds_list_head buffer_reg_uid_list {}; |
7972aab2 | 117 | /* Next channel ID available for a newly registered channel. */ |
63dcd955 | 118 | uint64_t next_channel_id{}; |
7972aab2 | 119 | /* Once this value reaches UINT32_MAX, no more id can be allocated. */ |
63dcd955 | 120 | uint64_t used_channel_id{}; |
2bba9e53 | 121 | /* Tell or not if the session has to output the traces. */ |
63dcd955 JR |
122 | unsigned int output_traces{}; |
123 | unsigned int snapshot_mode{}; | |
124 | unsigned int has_non_default_channel{}; | |
125 | unsigned int live_timer_interval{}; /* usec */ | |
84ad93e8 DG |
126 | |
127 | /* Metadata channel attributes. */ | |
63dcd955 | 128 | struct lttng_ust_abi_channel_attr metadata_attr {}; |
d7ba1388 MD |
129 | |
130 | /* | |
131 | * Path where to keep the shared memory files. | |
132 | */ | |
63dcd955 JR |
133 | char root_shm_path[PATH_MAX]{}; |
134 | char shm_path[PATH_MAX]{}; | |
a9ad0c8f | 135 | |
82b69413 | 136 | /* Current trace chunk of the ltt_session. */ |
63dcd955 | 137 | struct lttng_trace_chunk *current_trace_chunk{}; |
55c9e7ca JR |
138 | |
139 | /* Trackers used for actual lookup on app registration. */ | |
63dcd955 JR |
140 | struct ust_id_tracker vpid_tracker {}; |
141 | struct ust_id_tracker vuid_tracker {}; | |
142 | struct ust_id_tracker vgid_tracker {}; | |
55c9e7ca JR |
143 | |
144 | /* Tracker list of keys requested by users. */ | |
63dcd955 JR |
145 | struct process_attr_tracker *tracker_vpid{}; |
146 | struct process_attr_tracker *tracker_vuid{}; | |
147 | struct process_attr_tracker *tracker_vgid{}; | |
153d4c0e JR |
148 | |
149 | lttng::trace_format_descriptor::sptr trace_format; | |
97ee3a89 DG |
150 | }; |
151 | ||
7972aab2 DG |
152 | /* |
153 | * Validate that the id has reached the maximum allowed or not. | |
154 | * | |
155 | * Return 0 if NOT else 1. | |
156 | */ | |
157 | static inline int trace_ust_is_max_id(uint64_t id) | |
158 | { | |
159 | return (id == UINT64_MAX) ? 1 : 0; | |
160 | } | |
161 | ||
162 | /* | |
163 | * Return next available channel id and increment the used counter. The | |
164 | * trace_ust_is_max_id function MUST be called before in order to validate if | |
165 | * the maximum number of IDs have been reached. If not, it is safe to call this | |
166 | * function. | |
167 | * | |
168 | * Return a unique channel ID. If max is reached, the used_channel_id counter | |
169 | * is returned. | |
170 | */ | |
171 | static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s) | |
172 | { | |
173 | if (trace_ust_is_max_id(s->used_channel_id)) { | |
174 | return s->used_channel_id; | |
175 | } | |
176 | ||
177 | s->used_channel_id++; | |
178 | return s->next_channel_id++; | |
179 | } | |
180 | ||
74d0b642 | 181 | #ifdef HAVE_LIBLTTNG_UST_CTL |
3bd1e081 | 182 | |
18eace3b DG |
183 | int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key); |
184 | int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, | |
185 | const void *_key); | |
186 | ||
97ee3a89 DG |
187 | /* |
188 | * Lookup functions. NULL is returned if not found. | |
189 | */ | |
18eace3b | 190 | struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht, |
2b00d462 | 191 | char *name, struct lttng_bytecode *filter, |
fc4b93fa | 192 | enum lttng_ust_abi_loglevel_type loglevel_type, int loglevel_value, |
b953b8cd | 193 | struct lttng_event_exclusion *exclusion); |
bec39940 | 194 | struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, |
df4f5a87 | 195 | const char *name); |
fefd409b DG |
196 | struct agent *trace_ust_find_agent(struct ltt_ust_session *session, |
197 | enum lttng_domain_type domain_type); | |
97ee3a89 DG |
198 | |
199 | /* | |
200 | * Create functions malloc() the data structure. | |
201 | */ | |
d9bf3ca4 | 202 | struct ltt_ust_session *trace_ust_create_session(uint64_t session_id); |
51755dc8 JG |
203 | struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr, |
204 | enum lttng_domain_type domain); | |
999af9c1 | 205 | |
39687410 | 206 | enum lttng_error_code trace_ust_create_event(struct lttng_event *ev, |
6b453b5e | 207 | char *filter_expression, |
2b00d462 | 208 | struct lttng_bytecode *filter, |
88f06f15 | 209 | struct lttng_event_exclusion *exclusion, |
39687410 | 210 | bool internal_event, struct ltt_ust_event **ust_event); |
55cc08a6 | 211 | struct ltt_ust_context *trace_ust_create_context( |
df4f5a87 JG |
212 | const struct lttng_event_context *ctx); |
213 | int trace_ust_match_context(const struct ltt_ust_context *uctx, | |
214 | const struct lttng_event_context *ctx); | |
d5979e4a DG |
215 | void trace_ust_delete_channel(struct lttng_ht *ht, |
216 | struct ltt_ust_channel *channel); | |
97ee3a89 | 217 | |
d7bfb9b0 JG |
218 | int trace_ust_regenerate_metadata(struct ltt_ust_session *usess); |
219 | ||
97ee3a89 DG |
220 | /* |
221 | * Destroy functions free() the data structure and remove from linked list if | |
222 | * it's applies. | |
223 | */ | |
224 | void trace_ust_destroy_session(struct ltt_ust_session *session); | |
97ee3a89 DG |
225 | void trace_ust_destroy_channel(struct ltt_ust_channel *channel); |
226 | void trace_ust_destroy_event(struct ltt_ust_event *event); | |
bdf64013 | 227 | void trace_ust_destroy_context(struct ltt_ust_context *ctx); |
d070c424 | 228 | void trace_ust_free_session(struct ltt_ust_session *session); |
97ee3a89 | 229 | |
159b042f | 230 | int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr, |
55c9e7ca | 231 | struct ltt_ust_session *session, |
159b042f JG |
232 | int id); |
233 | enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy( | |
55c9e7ca | 234 | struct ltt_ust_session *session, |
159b042f JG |
235 | enum lttng_process_attr process_attr, |
236 | enum lttng_tracking_policy policy); | |
237 | enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value( | |
55c9e7ca | 238 | struct ltt_ust_session *session, |
159b042f JG |
239 | enum lttng_process_attr process_attr, |
240 | const struct process_attr_value *value); | |
241 | enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value( | |
242 | struct ltt_ust_session *session, | |
243 | enum lttng_process_attr process_attr, | |
244 | const struct process_attr_value *value); | |
245 | const struct process_attr_tracker *trace_ust_get_process_attr_tracker( | |
55c9e7ca | 246 | struct ltt_ust_session *session, |
159b042f | 247 | enum lttng_process_attr process_attr); |
a5dfbb9d | 248 | |
74d0b642 | 249 | #else /* HAVE_LIBLTTNG_UST_CTL */ |
3bd1e081 | 250 | |
f46376a1 MJ |
251 | static inline int trace_ust_ht_match_event( |
252 | struct cds_lfht_node *node __attribute__((unused)), | |
253 | const void *_key __attribute__((unused))) | |
37a86c61 DG |
254 | { |
255 | return 0; | |
256 | } | |
f46376a1 MJ |
257 | |
258 | static inline int trace_ust_ht_match_event_by_name( | |
259 | struct cds_lfht_node *node __attribute__((unused)), | |
260 | const void *_key __attribute__((unused))) | |
37a86c61 DG |
261 | { |
262 | return 0; | |
263 | } | |
f46376a1 | 264 | |
3bd1e081 | 265 | static inline |
f46376a1 MJ |
266 | struct ltt_ust_channel *trace_ust_find_channel_by_name( |
267 | struct lttng_ht *ht __attribute__((unused)), | |
268 | const char *name __attribute__((unused))) | |
3bd1e081 MD |
269 | { |
270 | return NULL; | |
271 | } | |
f6a9efaa | 272 | |
3bd1e081 | 273 | static inline |
f46376a1 MJ |
274 | struct ltt_ust_session *trace_ust_create_session( |
275 | unsigned int session_id __attribute__((unused))) | |
3bd1e081 MD |
276 | { |
277 | return NULL; | |
278 | } | |
f46376a1 | 279 | |
3bd1e081 | 280 | static inline |
f46376a1 MJ |
281 | struct ltt_ust_channel *trace_ust_create_channel( |
282 | struct lttng_channel *attr __attribute__((unused)), | |
283 | enum lttng_domain_type domain __attribute__((unused))) | |
3bd1e081 MD |
284 | { |
285 | return NULL; | |
286 | } | |
f46376a1 | 287 | |
3bd1e081 | 288 | static inline |
f46376a1 MJ |
289 | enum lttng_error_code trace_ust_create_event( |
290 | struct lttng_event *ev __attribute__((unused)), | |
291 | const char *filter_expression __attribute__((unused)), | |
292 | struct lttng_bytecode *filter __attribute__((unused)), | |
293 | struct lttng_event_exclusion *exclusion __attribute__((unused)), | |
294 | bool internal_event __attribute__((unused)), | |
295 | struct ltt_ust_event **ust_event __attribute__((unused))) | |
3bd1e081 | 296 | { |
39687410 | 297 | return LTTNG_ERR_NO_UST; |
3bd1e081 | 298 | } |
f46376a1 | 299 | |
3bd1e081 | 300 | static inline |
f46376a1 MJ |
301 | void trace_ust_destroy_session( |
302 | struct ltt_ust_session *session __attribute__((unused))) | |
3bd1e081 MD |
303 | { |
304 | } | |
48842b30 | 305 | |
3bd1e081 | 306 | static inline |
f46376a1 MJ |
307 | void trace_ust_destroy_channel( |
308 | struct ltt_ust_channel *channel __attribute__((unused))) | |
3bd1e081 MD |
309 | { |
310 | } | |
48842b30 | 311 | |
3bd1e081 | 312 | static inline |
f46376a1 MJ |
313 | void trace_ust_destroy_event( |
314 | struct ltt_ust_event *event __attribute__((unused))) | |
3bd1e081 MD |
315 | { |
316 | } | |
d070c424 MD |
317 | |
318 | static inline | |
f46376a1 MJ |
319 | void trace_ust_free_session( |
320 | struct ltt_ust_session *session __attribute__((unused))) | |
d070c424 MD |
321 | { |
322 | } | |
323 | ||
34378f76 DG |
324 | static inline |
325 | struct ltt_ust_context *trace_ust_create_context( | |
f46376a1 | 326 | const struct lttng_event_context *ctx __attribute__((unused))) |
34378f76 DG |
327 | { |
328 | return NULL; | |
329 | } | |
f46376a1 | 330 | |
aa3514e9 | 331 | static inline |
f46376a1 MJ |
332 | int trace_ust_match_context( |
333 | const struct ltt_ust_context *uctx __attribute__((unused)), | |
334 | const struct lttng_event_context *ctx __attribute__((unused))) | |
aa3514e9 MD |
335 | { |
336 | return 0; | |
337 | } | |
f46376a1 | 338 | |
b953b8cd | 339 | static inline |
f46376a1 MJ |
340 | struct ltt_ust_event *trace_ust_find_event( |
341 | struct lttng_ht *ht __attribute__((unused)), | |
342 | char *name __attribute__((unused)), | |
343 | struct lttng_bytecode *filter __attribute__((unused)), | |
344 | enum lttng_ust_abi_loglevel_type loglevel_type __attribute__((unused)), | |
345 | int loglevel_value __attribute__((unused)), | |
346 | struct lttng_event_exclusion *exclusion __attribute__((unused))) | |
37a86c61 DG |
347 | { |
348 | return NULL; | |
349 | } | |
f46376a1 | 350 | |
d5979e4a | 351 | static inline |
f46376a1 MJ |
352 | void trace_ust_delete_channel( |
353 | struct lttng_ht *ht __attribute__((unused)), | |
354 | struct ltt_ust_channel *channel __attribute__((unused))) | |
d5979e4a DG |
355 | { |
356 | return; | |
357 | } | |
f46376a1 | 358 | |
d7bfb9b0 JG |
359 | static inline int trace_ust_regenerate_metadata( |
360 | struct ltt_ust_session *usess __attribute__((unused))) | |
361 | { | |
362 | return 0; | |
363 | } | |
364 | ||
fefd409b | 365 | static inline |
f46376a1 MJ |
366 | struct agent *trace_ust_find_agent( |
367 | struct ltt_ust_session *session __attribute__((unused)), | |
368 | enum lttng_domain_type domain_type __attribute__((unused))) | |
fefd409b DG |
369 | { |
370 | return NULL; | |
371 | } | |
f46376a1 | 372 | |
159b042f | 373 | static inline int trace_ust_id_tracker_lookup( |
f46376a1 MJ |
374 | enum lttng_process_attr process_attr __attribute__((unused)), |
375 | struct ltt_ust_session *session __attribute__((unused)), | |
376 | int id __attribute__((unused))) | |
a9ad0c8f MD |
377 | { |
378 | return 0; | |
379 | } | |
f46376a1 | 380 | |
159b042f JG |
381 | static inline enum lttng_error_code |
382 | trace_ust_process_attr_tracker_set_tracking_policy( | |
f46376a1 MJ |
383 | struct ltt_ust_session *session __attribute__((unused)), |
384 | enum lttng_process_attr process_attr __attribute__((unused)), | |
385 | enum lttng_tracking_policy policy __attribute__((unused))) | |
a9ad0c8f | 386 | { |
159b042f | 387 | return LTTNG_OK; |
a9ad0c8f | 388 | } |
f46376a1 | 389 | |
159b042f JG |
390 | static inline enum lttng_error_code |
391 | trace_ust_process_attr_tracker_inclusion_set_add_value( | |
f46376a1 MJ |
392 | struct ltt_ust_session *session __attribute__((unused)), |
393 | enum lttng_process_attr process_attr __attribute__((unused)), | |
394 | const struct process_attr_value *value __attribute__((unused))) | |
b4650bd0 | 395 | { |
159b042f | 396 | return LTTNG_OK; |
b4650bd0 | 397 | } |
f46376a1 | 398 | |
159b042f JG |
399 | static inline enum lttng_error_code |
400 | trace_ust_process_attr_tracker_inclusion_set_remove_value( | |
f46376a1 MJ |
401 | struct ltt_ust_session *session __attribute__((unused)), |
402 | enum lttng_process_attr process_attr __attribute__((unused)), | |
403 | const struct process_attr_value *value __attribute__((unused))) | |
a5dfbb9d | 404 | { |
159b042f | 405 | return LTTNG_OK; |
a5dfbb9d | 406 | } |
f46376a1 | 407 | |
159b042f | 408 | static inline const struct process_attr_tracker * |
f46376a1 MJ |
409 | trace_ust_get_process_attr_tracker( |
410 | struct ltt_ust_session *session __attribute__((unused)), | |
411 | enum lttng_process_attr process_attr __attribute__((unused))) | |
159b042f JG |
412 | { |
413 | return NULL; | |
414 | } | |
415 | ||
74d0b642 | 416 | #endif /* HAVE_LIBLTTNG_UST_CTL */ |
3bd1e081 | 417 | |
97ee3a89 | 418 | #endif /* _LTT_TRACE_UST_H */ |