Propagate trace format to ltt_ust_session
[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 #include <lttng/trace-format-descriptor-internal.hpp>
20
21 #include "consumer.hpp"
22 #include "lttng-ust-ctl.hpp"
23
24 struct agent;
25
26 struct ltt_ust_ht_key {
27 const char *name;
28 const struct lttng_bytecode *filter;
29 enum lttng_ust_abi_loglevel_type loglevel_type;
30 int loglevel_value;
31 const struct lttng_event_exclusion *exclusion;
32 };
33
34 /* Context hash table nodes */
35 struct ltt_ust_context {
36 struct lttng_ust_context_attr ctx;
37 struct lttng_ht_node_ulong node;
38 struct cds_list_head list;
39 };
40
41 /* UST event */
42 struct ltt_ust_event {
43 unsigned int enabled;
44 struct lttng_ust_abi_event attr;
45 struct lttng_ht_node_str node;
46 char *filter_expression;
47 struct lttng_bytecode *filter;
48 struct lttng_event_exclusion *exclusion;
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 */
55 bool internal;
56 };
57
58 /* UST channel */
59 struct ltt_ust_channel {
60 uint64_t id; /* unique id per session. */
61 unsigned int enabled;
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;
67 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
68 struct lttng_ust_abi_channel_attr attr;
69 struct lttng_ht *ctx;
70 struct cds_list_head ctx_list;
71 struct lttng_ht *events;
72 struct lttng_ht_node_str node;
73 uint64_t tracefile_size;
74 uint64_t tracefile_count;
75 uint64_t per_pid_closed_app_discarded;
76 uint64_t per_pid_closed_app_lost;
77 uint64_t monitor_timer_interval;
78 };
79
80 /* UST domain global (LTTNG_DOMAIN_UST) */
81 struct ltt_ust_domain_global {
82 struct lttng_ht *channels;
83 struct cds_list_head registry_buffer_uid_list;
84 };
85
86 struct ust_id_tracker_node {
87 struct lttng_ht_node_ulong node;
88 };
89
90 struct ust_id_tracker {
91 struct lttng_ht *ht;
92 };
93
94 /* UST session */
95 struct ltt_ust_session {
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 {};
101 /* Hash table of agent indexed by agent domain. */
102 struct lttng_ht *agents{};
103 /* UID/GID of the user owning the session */
104 uid_t uid{};
105 gid_t gid{};
106 /* Is the session active meaning has is been started or stopped. */
107 bool active{false};
108 struct consumer_output *consumer{};
109 /* Sequence number for filters so the tracer knows the ordering. */
110 uint64_t filter_seq_num{};
111 /* This indicates which type of buffer this session is set for. */
112 enum lttng_buffer_type buffer_type {};
113 /* If set to 1, the buffer_type can not be changed anymore. */
114 int buffer_type_changed{};
115 /* For per UID buffer, every buffer reg object is kept of this session */
116 struct cds_list_head buffer_reg_uid_list {};
117 /* Next channel ID available for a newly registered channel. */
118 uint64_t next_channel_id{};
119 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
120 uint64_t used_channel_id{};
121 /* Tell or not if the session has to output the traces. */
122 unsigned int output_traces{};
123 unsigned int snapshot_mode{};
124 unsigned int has_non_default_channel{};
125 unsigned int live_timer_interval{}; /* usec */
126
127 /* Metadata channel attributes. */
128 struct lttng_ust_abi_channel_attr metadata_attr {};
129
130 /*
131 * Path where to keep the shared memory files.
132 */
133 char root_shm_path[PATH_MAX]{};
134 char shm_path[PATH_MAX]{};
135
136 /* Current trace chunk of the ltt_session. */
137 struct lttng_trace_chunk *current_trace_chunk{};
138
139 /* Trackers used for actual lookup on app registration. */
140 struct ust_id_tracker vpid_tracker {};
141 struct ust_id_tracker vuid_tracker {};
142 struct ust_id_tracker vgid_tracker {};
143
144 /* Tracker list of keys requested by users. */
145 struct process_attr_tracker *tracker_vpid{};
146 struct process_attr_tracker *tracker_vuid{};
147 struct process_attr_tracker *tracker_vgid{};
148
149 lttng::trace_format_descriptor::sptr trace_format;
150 };
151
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
181 #ifdef HAVE_LIBLTTNG_UST_CTL
182
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
187 /*
188 * Lookup functions. NULL is returned if not found.
189 */
190 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
191 char *name, struct lttng_bytecode *filter,
192 enum lttng_ust_abi_loglevel_type loglevel_type, int loglevel_value,
193 struct lttng_event_exclusion *exclusion);
194 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
195 const char *name);
196 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
197 enum lttng_domain_type domain_type);
198
199 /*
200 * Create functions malloc() the data structure.
201 */
202 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
203 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
204 enum lttng_domain_type domain);
205
206 enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
207 char *filter_expression,
208 struct lttng_bytecode *filter,
209 struct lttng_event_exclusion *exclusion,
210 bool internal_event, struct ltt_ust_event **ust_event);
211 struct ltt_ust_context *trace_ust_create_context(
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);
215 void trace_ust_delete_channel(struct lttng_ht *ht,
216 struct ltt_ust_channel *channel);
217
218 int trace_ust_regenerate_metadata(struct ltt_ust_session *usess);
219
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);
225 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
226 void trace_ust_destroy_event(struct ltt_ust_event *event);
227 void trace_ust_destroy_context(struct ltt_ust_context *ctx);
228 void trace_ust_free_session(struct ltt_ust_session *session);
229
230 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
231 struct ltt_ust_session *session,
232 int id);
233 enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
234 struct ltt_ust_session *session,
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(
238 struct ltt_ust_session *session,
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(
246 struct ltt_ust_session *session,
247 enum lttng_process_attr process_attr);
248
249 #else /* HAVE_LIBLTTNG_UST_CTL */
250
251 static inline int trace_ust_ht_match_event(
252 struct cds_lfht_node *node __attribute__((unused)),
253 const void *_key __attribute__((unused)))
254 {
255 return 0;
256 }
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)))
261 {
262 return 0;
263 }
264
265 static inline
266 struct ltt_ust_channel *trace_ust_find_channel_by_name(
267 struct lttng_ht *ht __attribute__((unused)),
268 const char *name __attribute__((unused)))
269 {
270 return NULL;
271 }
272
273 static inline
274 struct ltt_ust_session *trace_ust_create_session(
275 unsigned int session_id __attribute__((unused)))
276 {
277 return NULL;
278 }
279
280 static inline
281 struct ltt_ust_channel *trace_ust_create_channel(
282 struct lttng_channel *attr __attribute__((unused)),
283 enum lttng_domain_type domain __attribute__((unused)))
284 {
285 return NULL;
286 }
287
288 static inline
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)))
296 {
297 return LTTNG_ERR_NO_UST;
298 }
299
300 static inline
301 void trace_ust_destroy_session(
302 struct ltt_ust_session *session __attribute__((unused)))
303 {
304 }
305
306 static inline
307 void trace_ust_destroy_channel(
308 struct ltt_ust_channel *channel __attribute__((unused)))
309 {
310 }
311
312 static inline
313 void trace_ust_destroy_event(
314 struct ltt_ust_event *event __attribute__((unused)))
315 {
316 }
317
318 static inline
319 void trace_ust_free_session(
320 struct ltt_ust_session *session __attribute__((unused)))
321 {
322 }
323
324 static inline
325 struct ltt_ust_context *trace_ust_create_context(
326 const struct lttng_event_context *ctx __attribute__((unused)))
327 {
328 return NULL;
329 }
330
331 static inline
332 int trace_ust_match_context(
333 const struct ltt_ust_context *uctx __attribute__((unused)),
334 const struct lttng_event_context *ctx __attribute__((unused)))
335 {
336 return 0;
337 }
338
339 static inline
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)))
347 {
348 return NULL;
349 }
350
351 static inline
352 void trace_ust_delete_channel(
353 struct lttng_ht *ht __attribute__((unused)),
354 struct ltt_ust_channel *channel __attribute__((unused)))
355 {
356 return;
357 }
358
359 static inline int trace_ust_regenerate_metadata(
360 struct ltt_ust_session *usess __attribute__((unused)))
361 {
362 return 0;
363 }
364
365 static inline
366 struct agent *trace_ust_find_agent(
367 struct ltt_ust_session *session __attribute__((unused)),
368 enum lttng_domain_type domain_type __attribute__((unused)))
369 {
370 return NULL;
371 }
372
373 static inline int trace_ust_id_tracker_lookup(
374 enum lttng_process_attr process_attr __attribute__((unused)),
375 struct ltt_ust_session *session __attribute__((unused)),
376 int id __attribute__((unused)))
377 {
378 return 0;
379 }
380
381 static inline enum lttng_error_code
382 trace_ust_process_attr_tracker_set_tracking_policy(
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)))
386 {
387 return LTTNG_OK;
388 }
389
390 static inline enum lttng_error_code
391 trace_ust_process_attr_tracker_inclusion_set_add_value(
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)))
395 {
396 return LTTNG_OK;
397 }
398
399 static inline enum lttng_error_code
400 trace_ust_process_attr_tracker_inclusion_set_remove_value(
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)))
404 {
405 return LTTNG_OK;
406 }
407
408 static inline const struct process_attr_tracker *
409 trace_ust_get_process_attr_tracker(
410 struct ltt_ust_session *session __attribute__((unused)),
411 enum lttng_process_attr process_attr __attribute__((unused)))
412 {
413 return NULL;
414 }
415
416 #endif /* HAVE_LIBLTTNG_UST_CTL */
417
418 #endif /* _LTT_TRACE_UST_H */
This page took 0.041342 seconds and 5 git commands to generate.