Build fix: rpath of test libraries results in non-reproducible build
[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 uint64_t id; /* Unique identifier of session */
96 struct ltt_ust_domain_global domain_global;
97 /* Hash table of agent indexed by agent domain. */
98 struct lttng_ht *agents;
99 /* UID/GID of the user owning the session */
100 uid_t uid;
101 gid_t gid;
102 /* Is the session active meaning has is been started or stopped. */
103 unsigned int active:1;
104 struct consumer_output *consumer;
105 /* Sequence number for filters so the tracer knows the ordering. */
106 uint64_t filter_seq_num;
107 /* This indicates which type of buffer this session is set for. */
108 enum lttng_buffer_type buffer_type;
109 /* If set to 1, the buffer_type can not be changed anymore. */
110 int buffer_type_changed;
111 /* For per UID buffer, every buffer reg object is kept of this session */
112 struct cds_list_head buffer_reg_uid_list;
113 /* Next channel ID available for a newly registered channel. */
114 uint64_t next_channel_id;
115 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
116 uint64_t used_channel_id;
117 /* Tell or not if the session has to output the traces. */
118 unsigned int output_traces;
119 unsigned int snapshot_mode;
120 unsigned int has_non_default_channel;
121 unsigned int live_timer_interval; /* usec */
122
123 /* Metadata channel attributes. */
124 struct lttng_ust_abi_channel_attr metadata_attr;
125
126 /*
127 * Path where to keep the shared memory files.
128 */
129 char root_shm_path[PATH_MAX];
130 char shm_path[PATH_MAX];
131
132 /* Current trace chunk of the ltt_session. */
133 struct lttng_trace_chunk *current_trace_chunk;
134
135 /* Trackers used for actual lookup on app registration. */
136 struct ust_id_tracker vpid_tracker;
137 struct ust_id_tracker vuid_tracker;
138 struct ust_id_tracker vgid_tracker;
139
140 /* Tracker list of keys requested by users. */
141 struct process_attr_tracker *tracker_vpid;
142 struct process_attr_tracker *tracker_vuid;
143 struct process_attr_tracker *tracker_vgid;
144 };
145
146 /*
147 * Validate that the id has reached the maximum allowed or not.
148 *
149 * Return 0 if NOT else 1.
150 */
151 static inline int trace_ust_is_max_id(uint64_t id)
152 {
153 return (id == UINT64_MAX) ? 1 : 0;
154 }
155
156 /*
157 * Return next available channel id and increment the used counter. The
158 * trace_ust_is_max_id function MUST be called before in order to validate if
159 * the maximum number of IDs have been reached. If not, it is safe to call this
160 * function.
161 *
162 * Return a unique channel ID. If max is reached, the used_channel_id counter
163 * is returned.
164 */
165 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
166 {
167 if (trace_ust_is_max_id(s->used_channel_id)) {
168 return s->used_channel_id;
169 }
170
171 s->used_channel_id++;
172 return s->next_channel_id++;
173 }
174
175 #ifdef HAVE_LIBLTTNG_UST_CTL
176
177 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
178 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
179 const void *_key);
180
181 /*
182 * Lookup functions. NULL is returned if not found.
183 */
184 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
185 char *name, struct lttng_bytecode *filter,
186 enum lttng_ust_abi_loglevel_type loglevel_type, int loglevel_value,
187 struct lttng_event_exclusion *exclusion);
188 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
189 const char *name);
190 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
191 enum lttng_domain_type domain_type);
192
193 /*
194 * Create functions malloc() the data structure.
195 */
196 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
197 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
198 enum lttng_domain_type domain);
199
200 enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
201 char *filter_expression,
202 struct lttng_bytecode *filter,
203 struct lttng_event_exclusion *exclusion,
204 bool internal_event, struct ltt_ust_event **ust_event);
205 struct ltt_ust_context *trace_ust_create_context(
206 const struct lttng_event_context *ctx);
207 int trace_ust_match_context(const struct ltt_ust_context *uctx,
208 const struct lttng_event_context *ctx);
209 void trace_ust_delete_channel(struct lttng_ht *ht,
210 struct ltt_ust_channel *channel);
211
212 int trace_ust_regenerate_metadata(struct ltt_ust_session *usess);
213
214 /*
215 * Destroy functions free() the data structure and remove from linked list if
216 * it's applies.
217 */
218 void trace_ust_destroy_session(struct ltt_ust_session *session);
219 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
220 void trace_ust_destroy_event(struct ltt_ust_event *event);
221 void trace_ust_destroy_context(struct ltt_ust_context *ctx);
222 void trace_ust_free_session(struct ltt_ust_session *session);
223
224 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
225 struct ltt_ust_session *session,
226 int id);
227 enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
228 struct ltt_ust_session *session,
229 enum lttng_process_attr process_attr,
230 enum lttng_tracking_policy policy);
231 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value(
232 struct ltt_ust_session *session,
233 enum lttng_process_attr process_attr,
234 const struct process_attr_value *value);
235 enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value(
236 struct ltt_ust_session *session,
237 enum lttng_process_attr process_attr,
238 const struct process_attr_value *value);
239 const struct process_attr_tracker *trace_ust_get_process_attr_tracker(
240 struct ltt_ust_session *session,
241 enum lttng_process_attr process_attr);
242
243 #else /* HAVE_LIBLTTNG_UST_CTL */
244
245 static inline int trace_ust_ht_match_event(
246 struct cds_lfht_node *node __attribute__((unused)),
247 const void *_key __attribute__((unused)))
248 {
249 return 0;
250 }
251
252 static inline int trace_ust_ht_match_event_by_name(
253 struct cds_lfht_node *node __attribute__((unused)),
254 const void *_key __attribute__((unused)))
255 {
256 return 0;
257 }
258
259 static inline
260 struct ltt_ust_channel *trace_ust_find_channel_by_name(
261 struct lttng_ht *ht __attribute__((unused)),
262 const char *name __attribute__((unused)))
263 {
264 return NULL;
265 }
266
267 static inline
268 struct ltt_ust_session *trace_ust_create_session(
269 unsigned int session_id __attribute__((unused)))
270 {
271 return NULL;
272 }
273
274 static inline
275 struct ltt_ust_channel *trace_ust_create_channel(
276 struct lttng_channel *attr __attribute__((unused)),
277 enum lttng_domain_type domain __attribute__((unused)))
278 {
279 return NULL;
280 }
281
282 static inline
283 enum lttng_error_code trace_ust_create_event(
284 struct lttng_event *ev __attribute__((unused)),
285 const char *filter_expression __attribute__((unused)),
286 struct lttng_bytecode *filter __attribute__((unused)),
287 struct lttng_event_exclusion *exclusion __attribute__((unused)),
288 bool internal_event __attribute__((unused)),
289 struct ltt_ust_event **ust_event __attribute__((unused)))
290 {
291 return LTTNG_ERR_NO_UST;
292 }
293
294 static inline
295 void trace_ust_destroy_session(
296 struct ltt_ust_session *session __attribute__((unused)))
297 {
298 }
299
300 static inline
301 void trace_ust_destroy_channel(
302 struct ltt_ust_channel *channel __attribute__((unused)))
303 {
304 }
305
306 static inline
307 void trace_ust_destroy_event(
308 struct ltt_ust_event *event __attribute__((unused)))
309 {
310 }
311
312 static inline
313 void trace_ust_free_session(
314 struct ltt_ust_session *session __attribute__((unused)))
315 {
316 }
317
318 static inline
319 struct ltt_ust_context *trace_ust_create_context(
320 const struct lttng_event_context *ctx __attribute__((unused)))
321 {
322 return NULL;
323 }
324
325 static inline
326 int trace_ust_match_context(
327 const struct ltt_ust_context *uctx __attribute__((unused)),
328 const struct lttng_event_context *ctx __attribute__((unused)))
329 {
330 return 0;
331 }
332
333 static inline
334 struct ltt_ust_event *trace_ust_find_event(
335 struct lttng_ht *ht __attribute__((unused)),
336 char *name __attribute__((unused)),
337 struct lttng_bytecode *filter __attribute__((unused)),
338 enum lttng_ust_abi_loglevel_type loglevel_type __attribute__((unused)),
339 int loglevel_value __attribute__((unused)),
340 struct lttng_event_exclusion *exclusion __attribute__((unused)))
341 {
342 return NULL;
343 }
344
345 static inline
346 void trace_ust_delete_channel(
347 struct lttng_ht *ht __attribute__((unused)),
348 struct ltt_ust_channel *channel __attribute__((unused)))
349 {
350 return;
351 }
352
353 static inline int trace_ust_regenerate_metadata(
354 struct ltt_ust_session *usess __attribute__((unused)))
355 {
356 return 0;
357 }
358
359 static inline
360 struct agent *trace_ust_find_agent(
361 struct ltt_ust_session *session __attribute__((unused)),
362 enum lttng_domain_type domain_type __attribute__((unused)))
363 {
364 return NULL;
365 }
366
367 static inline int trace_ust_id_tracker_lookup(
368 enum lttng_process_attr process_attr __attribute__((unused)),
369 struct ltt_ust_session *session __attribute__((unused)),
370 int id __attribute__((unused)))
371 {
372 return 0;
373 }
374
375 static inline enum lttng_error_code
376 trace_ust_process_attr_tracker_set_tracking_policy(
377 struct ltt_ust_session *session __attribute__((unused)),
378 enum lttng_process_attr process_attr __attribute__((unused)),
379 enum lttng_tracking_policy policy __attribute__((unused)))
380 {
381 return LTTNG_OK;
382 }
383
384 static inline enum lttng_error_code
385 trace_ust_process_attr_tracker_inclusion_set_add_value(
386 struct ltt_ust_session *session __attribute__((unused)),
387 enum lttng_process_attr process_attr __attribute__((unused)),
388 const struct process_attr_value *value __attribute__((unused)))
389 {
390 return LTTNG_OK;
391 }
392
393 static inline enum lttng_error_code
394 trace_ust_process_attr_tracker_inclusion_set_remove_value(
395 struct ltt_ust_session *session __attribute__((unused)),
396 enum lttng_process_attr process_attr __attribute__((unused)),
397 const struct process_attr_value *value __attribute__((unused)))
398 {
399 return LTTNG_OK;
400 }
401
402 static inline const struct process_attr_tracker *
403 trace_ust_get_process_attr_tracker(
404 struct ltt_ust_session *session __attribute__((unused)),
405 enum lttng_process_attr process_attr __attribute__((unused)))
406 {
407 return NULL;
408 }
409
410 #endif /* HAVE_LIBLTTNG_UST_CTL */
411
412 #endif /* _LTT_TRACE_UST_H */
This page took 0.041525 seconds and 4 git commands to generate.