2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
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
13 #include <urcu/list.h>
15 #include <common/defaults.h>
16 #include <common/hashtable/hashtable.h>
17 #include <common/tracker.h>
18 #include <lttng/lttng.h>
21 #include "lttng-ust-ctl.h"
25 struct ltt_ust_ht_key
{
27 const struct lttng_filter_bytecode
*filter
;
28 enum lttng_ust_loglevel_type loglevel_type
;
30 const struct lttng_event_exclusion
*exclusion
;
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
;
41 struct ltt_ust_event
{
43 struct lttng_ust_event attr
;
44 struct lttng_ht_node_str node
;
45 char *filter_expression
;
46 struct lttng_filter_bytecode
*filter
;
47 struct lttng_event_exclusion
*exclusion
;
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.
58 struct ltt_ust_channel
{
59 uint64_t id
; /* unique id per session. */
62 * A UST channel can be part of a userspace sub-domain such as JUL,
65 enum lttng_domain_type domain
;
66 char name
[LTTNG_UST_SYM_NAME_LEN
];
67 struct lttng_ust_channel_attr attr
;
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
;
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
;
85 struct ust_id_tracker_node
{
86 struct lttng_ht_node_ulong node
;
89 struct ust_id_tracker
{
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 */
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 */
123 /* Metadata channel attributes. */
124 struct lttng_ust_channel_attr metadata_attr
;
127 * Path where to keep the shared memory files.
129 char root_shm_path
[PATH_MAX
];
130 char shm_path
[PATH_MAX
];
132 /* Current trace chunk of the ltt_session. */
133 struct lttng_trace_chunk
*current_trace_chunk
;
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
;
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
;
147 * Validate that the id has reached the maximum allowed or not.
149 * Return 0 if NOT else 1.
151 static inline int trace_ust_is_max_id(uint64_t id
)
153 return (id
== UINT64_MAX
) ? 1 : 0;
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
162 * Return a unique channel ID. If max is reached, the used_channel_id counter
165 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session
*s
)
167 if (trace_ust_is_max_id(s
->used_channel_id
)) {
168 return s
->used_channel_id
;
171 s
->used_channel_id
++;
172 return s
->next_channel_id
++;
175 #ifdef HAVE_LIBLTTNG_UST_CTL
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
,
182 * Lookup functions. NULL is returned if not found.
184 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
185 char *name
, struct lttng_filter_bytecode
*filter
,
186 enum lttng_ust_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
,
190 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
191 enum lttng_domain_type domain_type
);
194 * Create functions malloc() the data structure.
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 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
200 char *filter_expression
,
201 struct lttng_filter_bytecode
*filter
,
202 struct lttng_event_exclusion
*exclusion
,
203 bool internal_event
, struct ltt_ust_event
**ust_event
);
204 struct ltt_ust_context
*trace_ust_create_context(
205 const struct lttng_event_context
*ctx
);
206 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
207 const struct lttng_event_context
*ctx
);
208 void trace_ust_delete_channel(struct lttng_ht
*ht
,
209 struct ltt_ust_channel
*channel
);
212 * Destroy functions free() the data structure and remove from linked list if
215 void trace_ust_destroy_session(struct ltt_ust_session
*session
);
216 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
);
217 void trace_ust_destroy_event(struct ltt_ust_event
*event
);
218 void trace_ust_destroy_context(struct ltt_ust_context
*ctx
);
219 void trace_ust_free_session(struct ltt_ust_session
*session
);
221 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr
,
222 struct ltt_ust_session
*session
,
224 enum lttng_error_code
trace_ust_process_attr_tracker_set_tracking_policy(
225 struct ltt_ust_session
*session
,
226 enum lttng_process_attr process_attr
,
227 enum lttng_tracking_policy policy
);
228 enum lttng_error_code
trace_ust_process_attr_tracker_inclusion_set_add_value(
229 struct ltt_ust_session
*session
,
230 enum lttng_process_attr process_attr
,
231 const struct process_attr_value
*value
);
232 enum lttng_error_code
trace_ust_process_attr_tracker_inclusion_set_remove_value(
233 struct ltt_ust_session
*session
,
234 enum lttng_process_attr process_attr
,
235 const struct process_attr_value
*value
);
236 const struct process_attr_tracker
*trace_ust_get_process_attr_tracker(
237 struct ltt_ust_session
*session
,
238 enum lttng_process_attr process_attr
);
240 #else /* HAVE_LIBLTTNG_UST_CTL */
242 static inline int trace_ust_ht_match_event(struct cds_lfht_node
*node
,
247 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
253 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
260 struct ltt_ust_session
*trace_ust_create_session(unsigned int session_id
)
265 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
266 enum lttng_domain_type domain
)
271 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
272 const char *filter_expression
,
273 struct lttng_filter_bytecode
*filter
,
274 struct lttng_event_exclusion
*exclusion
,
275 bool internal_event
, struct ltt_ust_event
**ust_event
)
277 return LTTNG_ERR_NO_UST
;
280 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
285 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
290 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
295 void trace_ust_free_session(struct ltt_ust_session
*session
)
300 struct ltt_ust_context
*trace_ust_create_context(
301 const struct lttng_event_context
*ctx
)
306 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
307 const struct lttng_event_context
*ctx
)
312 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
313 char *name
, struct lttng_filter_bytecode
*filter
,
314 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
315 struct lttng_event_exclusion
*exclusion
)
320 void trace_ust_delete_channel(struct lttng_ht
*ht
,
321 struct ltt_ust_channel
*channel
)
326 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
327 enum lttng_domain_type domain_type
)
331 static inline int trace_ust_id_tracker_lookup(
332 enum lttng_process_attr process_attr
,
333 struct ltt_ust_session
*session
,
338 static inline enum lttng_error_code
339 trace_ust_process_attr_tracker_set_tracking_policy(
340 struct ltt_ust_session
*session
,
341 enum lttng_process_attr process_attr
,
342 enum lttng_tracking_policy policy
)
346 static inline enum lttng_error_code
347 trace_ust_process_attr_tracker_inclusion_set_add_value(
348 struct ltt_ust_session
*session
,
349 enum lttng_process_attr process_attr
,
350 const struct process_attr_value
*value
)
354 static inline enum lttng_error_code
355 trace_ust_process_attr_tracker_inclusion_set_remove_value(
356 struct ltt_ust_session
*session
,
357 enum lttng_process_attr process_attr
,
358 const struct process_attr_value
*value
)
362 static inline const struct process_attr_tracker
*
363 trace_ust_get_process_attr_tracker(struct ltt_ust_session
*session
,
364 enum lttng_process_attr process_attr
)
369 #endif /* HAVE_LIBLTTNG_UST_CTL */
371 #endif /* _LTT_TRACE_UST_H */