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