2 * Copyright (C) 2011 EfficiOS Inc.
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
9 #ifndef _LTT_TRACE_UST_H
10 #define _LTT_TRACE_UST_H
12 #include "consumer.hpp"
13 #include "lttng-ust-ctl.hpp"
15 #include <common/defaults.hpp>
16 #include <common/hashtable/hashtable.hpp>
17 #include <common/tracker.hpp>
19 #include <lttng/lttng.h>
22 #include <urcu/list.h>
26 struct ltt_ust_ht_key {
28 const struct lttng_bytecode *filter;
29 enum lttng_ust_abi_loglevel_type loglevel_type;
31 const struct lttng_event_exclusion *exclusion;
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;
42 struct ltt_ust_event {
44 struct lttng_ust_abi_event attr = {};
45 struct lttng_ht_node_str node = {};
46 char *filter_expression = nullptr;
47 struct lttng_bytecode *filter = nullptr;
48 struct lttng_event_exclusion *exclusion = nullptr;
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.
55 bool internal = false;
59 struct ltt_ust_channel {
60 uint64_t id; /* unique id per session. */
63 * A UST channel can be part of a userspace sub-domain such as JUL,
66 enum lttng_domain_type domain;
67 char name[LTTNG_UST_ABI_SYM_NAME_LEN];
68 struct lttng_ust_abi_channel_attr attr;
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;
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;
86 struct ust_id_tracker_node {
87 struct lttng_ht_node_ulong node;
90 struct ust_id_tracker {
95 struct ltt_ust_session {
96 uint64_t id; /* Unique identifier of session */
97 struct ltt_ust_domain_global domain_global;
98 /* Hash table of agent indexed by agent domain. */
99 struct lttng_ht *agents;
100 /* UID/GID of the user owning the session */
103 /* Is the session active meaning has is been started or stopped. */
105 struct consumer_output *consumer;
106 /* Sequence number for filters so the tracer knows the ordering. */
107 uint64_t filter_seq_num;
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. */
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;
118 /* Tell or not if the session has to output the traces. */
119 unsigned int output_traces;
120 unsigned int snapshot_mode;
121 unsigned int has_non_default_channel;
122 unsigned int live_timer_interval; /* usec */
124 /* Metadata channel attributes. */
125 struct lttng_ust_abi_channel_attr metadata_attr;
128 * Path where to keep the shared memory files.
130 char root_shm_path[PATH_MAX];
131 char shm_path[PATH_MAX];
133 /* Current trace chunk of the ltt_session. */
134 struct lttng_trace_chunk *current_trace_chunk;
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;
141 /* Tracker list of keys requested by users. */
142 struct process_attr_tracker *tracker_vpid;
143 struct process_attr_tracker *tracker_vuid;
144 struct process_attr_tracker *tracker_vgid;
148 * Validate that the id has reached the maximum allowed or not.
150 * Return 0 if NOT else 1.
152 static inline int trace_ust_is_max_id(uint64_t id)
154 return (id == UINT64_MAX) ? 1 : 0;
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
163 * Return a unique channel ID. If max is reached, the used_event_container_id counter
166 static inline uint64_t trace_ust_get_next_event_container_id(struct ltt_ust_session *s)
168 if (trace_ust_is_max_id(s->used_event_container_id)) {
169 return s->used_event_container_id;
172 s->used_event_container_id++;
173 return s->next_event_container_id++;
176 #ifdef HAVE_LIBLTTNG_UST_CTL
178 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
179 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node, const void *_key);
182 * Lookup functions. NULL is returned if not found.
184 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
186 struct lttng_bytecode *filter,
187 enum lttng_ust_abi_loglevel_type loglevel_type,
189 struct lttng_event_exclusion *exclusion);
190 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht, const char *name);
191 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
192 enum lttng_domain_type domain_type);
195 * Create functions malloc() the data structure.
197 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
198 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
199 enum lttng_domain_type domain);
201 enum lttng_error_code trace_ust_create_event(struct lttng_event *ev,
202 char *filter_expression,
203 struct lttng_bytecode *filter,
204 struct lttng_event_exclusion *exclusion,
206 struct ltt_ust_event **ust_event);
207 struct ltt_ust_context *trace_ust_create_context(const struct lttng_event_context *ctx);
208 int trace_ust_match_context(const struct ltt_ust_context *uctx,
209 const struct lttng_event_context *ctx);
210 void trace_ust_delete_channel(struct lttng_ht *ht, struct ltt_ust_channel *channel);
212 int trace_ust_regenerate_metadata(struct ltt_ust_session *usess);
215 * Destroy functions free() the data structure and remove from linked list if
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);
224 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr,
225 struct ltt_ust_session *session,
227 enum lttng_error_code
228 trace_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);
231 enum lttng_error_code
232 trace_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);
235 enum lttng_error_code
236 trace_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);
239 const struct process_attr_tracker *
240 trace_ust_get_process_attr_tracker(struct ltt_ust_session *session,
241 enum lttng_process_attr process_attr);
243 #else /* HAVE_LIBLTTNG_UST_CTL */
245 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node __attribute__((unused)),
246 const void *_key __attribute__((unused)))
251 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node
252 __attribute__((unused)),
253 const void *_key __attribute__((unused)))
258 static inline struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht
259 __attribute__((unused)),
261 __attribute__((unused)))
266 static inline struct ltt_ust_session *trace_ust_create_session(unsigned int session_id
267 __attribute__((unused)))
272 static 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)))
280 static inline enum lttng_error_code
281 trace_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)))
288 return LTTNG_ERR_NO_UST;
291 static inline void trace_ust_destroy_session(struct ltt_ust_session *session
292 __attribute__((unused)))
296 static inline void trace_ust_destroy_channel(struct ltt_ust_channel *channel
297 __attribute__((unused)))
301 static inline void trace_ust_destroy_event(struct ltt_ust_event *event __attribute__((unused)))
305 static inline void trace_ust_free_session(struct ltt_ust_session *session __attribute__((unused)))
309 static inline struct ltt_ust_context *trace_ust_create_context(const struct lttng_event_context *ctx
310 __attribute__((unused)))
315 static 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)))
323 static inline struct ltt_ust_event *
324 trace_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)))
334 static inline void trace_ust_delete_channel(struct lttng_ht *ht __attribute__((unused)),
335 struct ltt_ust_channel *channel __attribute__((unused)))
340 static inline int trace_ust_regenerate_metadata(struct ltt_ust_session *usess
341 __attribute__((unused)))
346 static 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)))
354 static 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)))
363 static 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)))
371 static 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)))
379 static 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)))
387 static inline const struct process_attr_tracker *
388 trace_ust_get_process_attr_tracker(struct ltt_ust_session *session __attribute__((unused)),
389 enum lttng_process_attr process_attr __attribute__((unused)))
394 #endif /* HAVE_LIBLTTNG_UST_CTL */
396 #endif /* _LTT_TRACE_UST_H */