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 <lttng/lttng.h>
16 #include <common/hashtable/hashtable.h>
17 #include <common/defaults.h>
20 #include "lttng-ust-ctl.h"
24 struct ltt_ust_ht_key
{
26 const struct lttng_filter_bytecode
*filter
;
27 enum lttng_ust_loglevel_type loglevel_type
;
29 const struct lttng_event_exclusion
*exclusion
;
32 /* Context hash table nodes */
33 struct ltt_ust_context
{
34 struct lttng_ust_context_attr ctx
;
35 struct lttng_ht_node_ulong node
;
36 struct cds_list_head list
;
40 struct ltt_ust_event
{
42 struct lttng_ust_event attr
;
43 struct lttng_ht_node_str node
;
44 char *filter_expression
;
45 struct lttng_filter_bytecode
*filter
;
46 struct lttng_event_exclusion
*exclusion
;
48 * An internal event is an event which was created by the session daemon
49 * through which, for example, events emitted in Agent domains are
50 * "funelled". This is used to hide internal events from external
51 * clients as they should never be modified by the external world.
57 struct ltt_ust_channel
{
58 uint64_t id
; /* unique id per session. */
61 * A UST channel can be part of a userspace sub-domain such as JUL,
64 enum lttng_domain_type domain
;
65 char name
[LTTNG_UST_SYM_NAME_LEN
];
66 struct lttng_ust_channel_attr attr
;
68 struct cds_list_head ctx_list
;
69 struct lttng_ht
*events
;
70 struct lttng_ht_node_str node
;
71 uint64_t tracefile_size
;
72 uint64_t tracefile_count
;
73 uint64_t per_pid_closed_app_discarded
;
74 uint64_t per_pid_closed_app_lost
;
75 uint64_t monitor_timer_interval
;
78 /* UST domain global (LTTNG_DOMAIN_UST) */
79 struct ltt_ust_domain_global
{
80 struct lttng_ht
*channels
;
81 struct cds_list_head registry_buffer_uid_list
;
84 struct ust_id_tracker_node
{
85 struct lttng_ht_node_ulong node
;
88 struct ust_id_tracker
{
93 struct ltt_ust_session
{
94 uint64_t id
; /* Unique identifier of session */
95 struct ltt_ust_domain_global domain_global
;
96 /* Hash table of agent indexed by agent domain. */
97 struct lttng_ht
*agents
;
98 /* UID/GID of the user owning the session */
101 /* Is the session active meaning has is been started or stopped. */
102 unsigned int active
:1;
103 struct consumer_output
*consumer
;
104 /* Sequence number for filters so the tracer knows the ordering. */
105 uint64_t filter_seq_num
;
106 /* This indicates which type of buffer this session is set for. */
107 enum lttng_buffer_type buffer_type
;
108 /* If set to 1, the buffer_type can not be changed anymore. */
109 int buffer_type_changed
;
110 /* For per UID buffer, every buffer reg object is kept of this session */
111 struct cds_list_head buffer_reg_uid_list
;
112 /* Next channel ID available for a newly registered channel. */
113 uint64_t next_channel_id
;
114 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
115 uint64_t used_channel_id
;
116 /* Tell or not if the session has to output the traces. */
117 unsigned int output_traces
;
118 unsigned int snapshot_mode
;
119 unsigned int has_non_default_channel
;
120 unsigned int live_timer_interval
; /* usec */
122 /* Metadata channel attributes. */
123 struct lttng_ust_channel_attr metadata_attr
;
126 * Path where to keep the shared memory files.
128 char root_shm_path
[PATH_MAX
];
129 char shm_path
[PATH_MAX
];
131 /* Current trace chunk of the ltt_session. */
132 struct lttng_trace_chunk
*current_trace_chunk
;
134 /* Trackers used for actual lookup on app registration. */
135 struct ust_id_tracker vpid_tracker
;
136 struct ust_id_tracker vuid_tracker
;
137 struct ust_id_tracker vgid_tracker
;
139 /* Tracker list of keys requested by users. */
140 struct lttng_tracker_list
*tracker_list_vpid
;
141 struct lttng_tracker_list
*tracker_list_vuid
;
142 struct lttng_tracker_list
*tracker_list_vgid
;
146 * Validate that the id has reached the maximum allowed or not.
148 * Return 0 if NOT else 1.
150 static inline int trace_ust_is_max_id(uint64_t id
)
152 return (id
== UINT64_MAX
) ? 1 : 0;
156 * Return next available channel id and increment the used counter. The
157 * trace_ust_is_max_id function MUST be called before in order to validate if
158 * the maximum number of IDs have been reached. If not, it is safe to call this
161 * Return a unique channel ID. If max is reached, the used_channel_id counter
164 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session
*s
)
166 if (trace_ust_is_max_id(s
->used_channel_id
)) {
167 return s
->used_channel_id
;
170 s
->used_channel_id
++;
171 return s
->next_channel_id
++;
174 #ifdef HAVE_LIBLTTNG_UST_CTL
176 int trace_ust_ht_match_event(struct cds_lfht_node
*node
, const void *_key
);
177 int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
181 * Lookup functions. NULL is returned if not found.
183 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
184 char *name
, struct lttng_filter_bytecode
*filter
,
185 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
186 struct lttng_event_exclusion
*exclusion
);
187 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
189 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
190 enum lttng_domain_type domain_type
);
193 * Create functions malloc() the data structure.
195 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
);
196 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
197 enum lttng_domain_type domain
);
198 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
199 char *filter_expression
,
200 struct lttng_filter_bytecode
*filter
,
201 struct lttng_event_exclusion
*exclusion
,
202 bool internal_event
, struct ltt_ust_event
**ust_event
);
203 struct ltt_ust_context
*trace_ust_create_context(
204 const struct lttng_event_context
*ctx
);
205 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
206 const struct lttng_event_context
*ctx
);
207 void trace_ust_delete_channel(struct lttng_ht
*ht
,
208 struct ltt_ust_channel
*channel
);
211 * Destroy functions free() the data structure and remove from linked list if
214 void trace_ust_destroy_session(struct ltt_ust_session
*session
);
215 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
);
216 void trace_ust_destroy_event(struct ltt_ust_event
*event
);
217 void trace_ust_destroy_context(struct ltt_ust_context
*ctx
);
218 void trace_ust_free_session(struct ltt_ust_session
*session
);
220 int trace_ust_track_id(enum lttng_tracker_type tracker_type
,
221 struct ltt_ust_session
*session
,
222 const struct lttng_tracker_id
*id
);
223 int trace_ust_untrack_id(enum lttng_tracker_type tracker_type
,
224 struct ltt_ust_session
*session
,
225 const struct lttng_tracker_id
*id
);
227 int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type
,
228 struct ltt_ust_session
*session
,
231 int trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type
,
232 struct ltt_ust_session
*session
,
233 struct lttng_tracker_ids
**_ids
);
235 #else /* HAVE_LIBLTTNG_UST_CTL */
237 static inline int trace_ust_ht_match_event(struct cds_lfht_node
*node
,
242 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
248 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
255 struct ltt_ust_session
*trace_ust_create_session(unsigned int session_id
)
260 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
261 enum lttng_domain_type domain
)
266 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
267 const char *filter_expression
,
268 struct lttng_filter_bytecode
*filter
,
269 struct lttng_event_exclusion
*exclusion
,
270 bool internal_event
, struct ltt_ust_event
**ust_event
)
272 return LTTNG_ERR_NO_UST
;
275 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
280 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
285 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
290 void trace_ust_free_session(struct ltt_ust_session
*session
)
295 struct ltt_ust_context
*trace_ust_create_context(
296 const struct lttng_event_context
*ctx
)
301 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
302 const struct lttng_event_context
*ctx
)
307 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
308 char *name
, struct lttng_filter_bytecode
*filter
,
309 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
310 struct lttng_event_exclusion
*exclusion
)
315 void trace_ust_delete_channel(struct lttng_ht
*ht
,
316 struct ltt_ust_channel
*channel
)
321 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
322 enum lttng_domain_type domain_type
)
326 static inline int trace_ust_track_id(enum lttng_tracker_type tracker_type
,
327 struct ltt_ust_session
*session
,
328 const struct lttng_tracker_id
*id
)
332 static inline int trace_ust_untrack_id(enum lttng_tracker_type tracker_type
,
333 struct ltt_ust_session
*session
,
334 const struct lttng_tracker_id
*id
)
338 static inline int trace_ust_id_tracker_lookup(
339 enum lttng_tracker_type tracker_type
,
340 struct ltt_ust_session
*session
,
345 static inline int trace_ust_list_tracker_ids(
346 enum lttng_tracker_type tracker_type
,
347 struct ltt_ust_session
*session
,
348 struct lttng_tracker_ids
**_ids
)
352 #endif /* HAVE_LIBLTTNG_UST_CTL */
354 #endif /* _LTT_TRACE_UST_H */