docs: Add supported versions and fix-backport policy
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.hpp
CommitLineData
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
28f23191
JG
12#include "consumer.hpp"
13#include "lttng-ust-ctl.hpp"
bec39940 14
c9e313bc
SM
15#include <common/defaults.hpp>
16#include <common/hashtable/hashtable.hpp>
17#include <common/tracker.hpp>
28f23191 18
159b042f 19#include <lttng/lttng.h>
3bd1e081 20
28f23191
JG
21#include <limits.h>
22#include <urcu/list.h>
97ee3a89 23
7c1d2758
JG
24struct agent;
25
18eace3b
DG
26struct 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 */
35struct 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 */
42struct ltt_ust_event {
66cefebd 43 bool 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 */
59struct ltt_ust_channel {
28f23191 60 uint64_t id; /* unique id per session. */
66cefebd 61 bool 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) */
81struct 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 86struct ust_id_tracker_node {
a9ad0c8f
MD
87 struct lttng_ht_node_ulong node;
88};
89
55c9e7ca 90struct ust_id_tracker {
a9ad0c8f
MD
91 struct lttng_ht *ht;
92};
93
97ee3a89
DG
94/* UST session */
95struct ltt_ust_session {
28f23191 96 uint64_t id; /* Unique identifier of session */
f6a9efaa 97 struct ltt_ust_domain_global domain_global;
fefd409b
DG
98 /* Hash table of agent indexed by agent domain. */
99 struct lttng_ht *agents;
6df2e2c9
MD
100 /* UID/GID of the user owning the session */
101 uid_t uid;
102 gid_t gid;
14fb1ebe 103 /* Is the session active meaning has is been started or stopped. */
66cefebd 104 bool active;
00e2e675 105 struct consumer_output *consumer;
f3f0db50
DG
106 /* Sequence number for filters so the tracer knows the ordering. */
107 uint64_t filter_seq_num;
7972aab2
DG
108 /* This indicates which type of buffer this session is set for. */
109 enum lttng_buffer_type buffer_type;
110 /* If set to 1, the buffer_type can not be changed anymore. */
111 int buffer_type_changed;
112 /* For per UID buffer, every buffer reg object is kept of this session */
113 struct cds_list_head buffer_reg_uid_list;
114 /* Next channel ID available for a newly registered channel. */
dc88217e
FD
115 uint64_t next_event_container_id;
116 /* Once this value reaches UINT64_MAX, no more id can be allocated. */
117 uint64_t used_event_container_id;
2bba9e53
DG
118 /* Tell or not if the session has to output the traces. */
119 unsigned int output_traces;
27babd3a 120 unsigned int snapshot_mode;
85076754 121 unsigned int has_non_default_channel;
28f23191 122 unsigned int live_timer_interval; /* usec */
84ad93e8
DG
123
124 /* Metadata channel attributes. */
fc4b93fa 125 struct lttng_ust_abi_channel_attr metadata_attr;
d7ba1388
MD
126
127 /*
128 * Path where to keep the shared memory files.
129 */
3d071855 130 char root_shm_path[PATH_MAX];
d7ba1388 131 char shm_path[PATH_MAX];
a9ad0c8f 132
82b69413
JG
133 /* Current trace chunk of the ltt_session. */
134 struct lttng_trace_chunk *current_trace_chunk;
55c9e7ca
JR
135
136 /* Trackers used for actual lookup on app registration. */
137 struct ust_id_tracker vpid_tracker;
138 struct ust_id_tracker vuid_tracker;
139 struct ust_id_tracker vgid_tracker;
140
141 /* Tracker list of keys requested by users. */
159b042f
JG
142 struct process_attr_tracker *tracker_vpid;
143 struct process_attr_tracker *tracker_vuid;
144 struct process_attr_tracker *tracker_vgid;
97ee3a89
DG
145};
146
7972aab2
DG
147/*
148 * Validate that the id has reached the maximum allowed or not.
149 *
150 * Return 0 if NOT else 1.
151 */
152static inline int trace_ust_is_max_id(uint64_t id)
153{
154 return (id == UINT64_MAX) ? 1 : 0;
155}
156
157/*
158 * Return next available channel id and increment the used counter. The
159 * trace_ust_is_max_id function MUST be called before in order to validate if
160 * the maximum number of IDs have been reached. If not, it is safe to call this
161 * function.
162 *
dc88217e 163 * Return a unique channel ID. If max is reached, the used_event_container_id counter
7972aab2
DG
164 * is returned.
165 */
dc88217e 166static inline uint64_t trace_ust_get_next_event_container_id(struct ltt_ust_session *s)
7972aab2 167{
dc88217e
FD
168 if (trace_ust_is_max_id(s->used_event_container_id)) {
169 return s->used_event_container_id;
7972aab2
DG
170 }
171
dc88217e
FD
172 s->used_event_container_id++;
173 return s->next_event_container_id++;
7972aab2
DG
174}
175
74d0b642 176#ifdef HAVE_LIBLTTNG_UST_CTL
3bd1e081 177
18eace3b 178int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
28f23191 179int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, const void *_key);
18eace3b 180
97ee3a89
DG
181/*
182 * Lookup functions. NULL is returned if not found.
183 */
18eace3b 184struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
28f23191
JG
185 char *name,
186 struct lttng_bytecode *filter,
187 enum lttng_ust_abi_loglevel_type loglevel_type,
188 int loglevel_value,
189 struct lttng_event_exclusion *exclusion);
190struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, const char *name);
fefd409b 191struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
28f23191 192 enum lttng_domain_type domain_type);
97ee3a89
DG
193
194/*
195 * Create functions malloc() the data structure.
196 */
d9bf3ca4 197struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
51755dc8 198struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
28f23191 199 enum lttng_domain_type domain);
999af9c1 200
39687410 201enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
28f23191
JG
202 char *filter_expression,
203 struct lttng_bytecode *filter,
204 struct lttng_event_exclusion *exclusion,
205 bool internal_event,
206 struct ltt_ust_event **ust_event);
207struct ltt_ust_context *trace_ust_create_context(const struct lttng_event_context *ctx);
df4f5a87 208int trace_ust_match_context(const struct ltt_ust_context *uctx,
28f23191
JG
209 const struct lttng_event_context *ctx);
210void trace_ust_delete_channel(struct lttng_ht *ht, struct ltt_ust_channel *channel);
97ee3a89 211
d7bfb9b0
JG
212int trace_ust_regenerate_metadata(struct ltt_ust_session *usess);
213
97ee3a89
DG
214/*
215 * Destroy functions free() the data structure and remove from linked list if
216 * it's applies.
217 */
218void trace_ust_destroy_session(struct ltt_ust_session *session);
97ee3a89
DG
219void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
220void trace_ust_destroy_event(struct ltt_ust_event *event);
bdf64013 221void trace_ust_destroy_context(struct ltt_ust_context *ctx);
d070c424 222void trace_ust_free_session(struct ltt_ust_session *session);
97ee3a89 223
159b042f 224int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
28f23191
JG
225 struct ltt_ust_session *session,
226 int id);
227enum lttng_error_code
228trace_ust_process_attr_tracker_set_tracking_policy(struct ltt_ust_session *session,
229 enum lttng_process_attr process_attr,
230 enum lttng_tracking_policy policy);
231enum lttng_error_code
232trace_ust_process_attr_tracker_inclusion_set_add_value(struct ltt_ust_session *session,
233 enum lttng_process_attr process_attr,
234 const struct process_attr_value *value);
235enum lttng_error_code
236trace_ust_process_attr_tracker_inclusion_set_remove_value(struct ltt_ust_session *session,
237 enum lttng_process_attr process_attr,
238 const struct process_attr_value *value);
239const struct process_attr_tracker *
240trace_ust_get_process_attr_tracker(struct ltt_ust_session *session,
241 enum lttng_process_attr process_attr);
a5dfbb9d 242
74d0b642 243#else /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 244
28f23191
JG
245static inline int trace_ust_ht_match_event(struct cds_lfht_node *node __attribute__((unused)),
246 const void *_key __attribute__((unused)))
37a86c61
DG
247{
248 return 0;
249}
f46376a1 250
28f23191
JG
251static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node
252 __attribute__((unused)),
253 const void *_key __attribute__((unused)))
37a86c61
DG
254{
255 return 0;
256}
f46376a1 257
28f23191
JG
258static inline struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht
259 __attribute__((unused)),
260 const char *name
261 __attribute__((unused)))
3bd1e081
MD
262{
263 return NULL;
264}
f6a9efaa 265
28f23191
JG
266static inline struct ltt_ust_session *trace_ust_create_session(unsigned int session_id
267 __attribute__((unused)))
3bd1e081
MD
268{
269 return NULL;
270}
f46376a1 271
28f23191
JG
272static inline struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr
273 __attribute__((unused)),
274 enum lttng_domain_type domain
275 __attribute__((unused)))
3bd1e081
MD
276{
277 return NULL;
278}
f46376a1 279
28f23191
JG
280static inline enum lttng_error_code
281trace_ust_create_event(struct lttng_event *ev __attribute__((unused)),
282 const char *filter_expression __attribute__((unused)),
283 struct lttng_bytecode *filter __attribute__((unused)),
284 struct lttng_event_exclusion *exclusion __attribute__((unused)),
285 bool internal_event __attribute__((unused)),
286 struct ltt_ust_event **ust_event __attribute__((unused)))
3bd1e081 287{
39687410 288 return LTTNG_ERR_NO_UST;
3bd1e081 289}
f46376a1 290
28f23191
JG
291static inline void trace_ust_destroy_session(struct ltt_ust_session *session
292 __attribute__((unused)))
3bd1e081
MD
293{
294}
48842b30 295
28f23191
JG
296static inline void trace_ust_destroy_channel(struct ltt_ust_channel *channel
297 __attribute__((unused)))
3bd1e081
MD
298{
299}
48842b30 300
28f23191 301static inline void trace_ust_destroy_event(struct ltt_ust_event *event __attribute__((unused)))
3bd1e081
MD
302{
303}
d070c424 304
28f23191 305static inline void trace_ust_free_session(struct ltt_ust_session *session __attribute__((unused)))
d070c424
MD
306{
307}
308
28f23191
JG
309static inline struct ltt_ust_context *trace_ust_create_context(const struct lttng_event_context *ctx
310 __attribute__((unused)))
34378f76
DG
311{
312 return NULL;
313}
f46376a1 314
28f23191
JG
315static inline int trace_ust_match_context(const struct ltt_ust_context *uctx
316 __attribute__((unused)),
317 const struct lttng_event_context *ctx
318 __attribute__((unused)))
aa3514e9
MD
319{
320 return 0;
321}
f46376a1 322
28f23191
JG
323static inline struct ltt_ust_event *
324trace_ust_find_event(struct lttng_ht *ht __attribute__((unused)),
325 char *name __attribute__((unused)),
326 struct lttng_bytecode *filter __attribute__((unused)),
327 enum lttng_ust_abi_loglevel_type loglevel_type __attribute__((unused)),
328 int loglevel_value __attribute__((unused)),
329 struct lttng_event_exclusion *exclusion __attribute__((unused)))
37a86c61
DG
330{
331 return NULL;
332}
f46376a1 333
28f23191
JG
334static inline void trace_ust_delete_channel(struct lttng_ht *ht __attribute__((unused)),
335 struct ltt_ust_channel *channel __attribute__((unused)))
d5979e4a
DG
336{
337 return;
338}
f46376a1 339
28f23191
JG
340static inline int trace_ust_regenerate_metadata(struct ltt_ust_session *usess
341 __attribute__((unused)))
d7bfb9b0
JG
342{
343 return 0;
344}
345
28f23191
JG
346static inline struct agent *trace_ust_find_agent(struct ltt_ust_session *session
347 __attribute__((unused)),
348 enum lttng_domain_type domain_type
349 __attribute__((unused)))
fefd409b
DG
350{
351 return NULL;
352}
f46376a1 353
28f23191
JG
354static inline int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr
355 __attribute__((unused)),
356 struct ltt_ust_session *session
357 __attribute__((unused)),
358 int id __attribute__((unused)))
a9ad0c8f
MD
359{
360 return 0;
361}
f46376a1 362
28f23191
JG
363static inline enum lttng_error_code trace_ust_process_attr_tracker_set_tracking_policy(
364 struct ltt_ust_session *session __attribute__((unused)),
365 enum lttng_process_attr process_attr __attribute__((unused)),
366 enum lttng_tracking_policy policy __attribute__((unused)))
a9ad0c8f 367{
159b042f 368 return LTTNG_OK;
a9ad0c8f 369}
f46376a1 370
28f23191
JG
371static inline enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_add_value(
372 struct ltt_ust_session *session __attribute__((unused)),
373 enum lttng_process_attr process_attr __attribute__((unused)),
374 const struct process_attr_value *value __attribute__((unused)))
b4650bd0 375{
159b042f 376 return LTTNG_OK;
b4650bd0 377}
f46376a1 378
28f23191
JG
379static inline enum lttng_error_code trace_ust_process_attr_tracker_inclusion_set_remove_value(
380 struct ltt_ust_session *session __attribute__((unused)),
381 enum lttng_process_attr process_attr __attribute__((unused)),
382 const struct process_attr_value *value __attribute__((unused)))
a5dfbb9d 383{
159b042f 384 return LTTNG_OK;
a5dfbb9d 385}
f46376a1 386
159b042f 387static inline const struct process_attr_tracker *
28f23191
JG
388trace_ust_get_process_attr_tracker(struct ltt_ust_session *session __attribute__((unused)),
389 enum lttng_process_attr process_attr __attribute__((unused)))
159b042f
JG
390{
391 return NULL;
392}
393
74d0b642 394#endif /* HAVE_LIBLTTNG_UST_CTL */
3bd1e081 395
97ee3a89 396#endif /* _LTT_TRACE_UST_H */
This page took 0.114035 seconds and 4 git commands to generate.