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
{
26 uint64_t tracer_token
;
28 const struct lttng_bytecode
*filter
;
29 enum lttng_ust_loglevel_type loglevel_type
;
31 const struct lttng_event_exclusion
*exclusion
;
32 struct lttng_map_key
*key
;
35 /* Context hash table nodes */
36 struct ltt_ust_context
{
37 struct lttng_ust_context_attr ctx
;
38 struct lttng_ht_node_ulong node
;
39 struct cds_list_head list
;
43 struct ltt_ust_event
{
45 struct lttng_ust_event attr
;
46 struct lttng_ht_node_str node
;
47 char *filter_expression
;
48 struct lttng_bytecode
*filter
;
49 struct lttng_event_exclusion
*exclusion
;
52 struct lttng_map_key
*key
;
54 * An internal event is an event which was created by the session daemon
55 * through which, for example, events emitted in Agent domains are
56 * "funelled". This is used to hide internal events from external
57 * clients as they should never be modified by the external world.
63 struct ltt_ust_channel
{
64 uint64_t id
; /* unique id per session. */
67 * A UST channel can be part of a userspace sub-domain such as JUL,
70 enum lttng_domain_type domain
;
71 char name
[LTTNG_UST_SYM_NAME_LEN
];
72 struct lttng_ust_channel_attr attr
;
74 struct cds_list_head ctx_list
;
75 struct lttng_ht
*events
;
76 struct lttng_ht_node_str node
;
77 uint64_t tracefile_size
;
78 uint64_t tracefile_count
;
79 uint64_t per_pid_closed_app_discarded
;
80 uint64_t per_pid_closed_app_lost
;
81 uint64_t monitor_timer_interval
;
84 struct ltt_ust_map_dead_pid_kv_values
{
86 struct lttng_ht
*dead_app_kv_values_32bits
;
87 struct lttng_ht
*dead_app_kv_values_64bits
;
92 uint64_t id
; /* unique id per session. */
93 char name
[LTTNG_UST_SYM_NAME_LEN
];
97 enum lttng_map_bitness bitness
;
99 struct lttng_ht_node_str node
;
100 struct lttng_map
*map
;
101 struct lttng_ht
*events
;
102 struct ltt_ust_map_dead_pid_kv_values dead_app_kv_values
;
105 /* UST domain global (LTTNG_DOMAIN_UST) */
106 struct ltt_ust_domain_global
{
107 struct lttng_ht
*channels
;
108 struct lttng_ht
*maps
;
109 struct cds_list_head registry_buffer_uid_list
;
112 struct ust_id_tracker_node
{
113 struct lttng_ht_node_ulong node
;
116 struct ust_id_tracker
{
121 struct ltt_ust_session
{
122 uint64_t id
; /* Unique identifier of session */
123 struct ltt_ust_domain_global domain_global
;
124 /* Hash table of agent indexed by agent domain. */
125 struct lttng_ht
*agents
;
126 /* UID/GID of the user owning the session */
129 /* Is the session active meaning has is been started or stopped. */
130 unsigned int active
:1;
131 struct consumer_output
*consumer
;
132 /* Sequence number for filters so the tracer knows the ordering. */
133 uint64_t filter_seq_num
;
134 /* This indicates which type of buffer this session is set for. */
135 enum lttng_buffer_type buffer_type
;
136 /* If set to 1, the buffer_type can not be changed anymore. */
137 int buffer_type_changed
;
138 /* For per UID buffer, every buffer reg object is kept of this session */
139 struct cds_list_head buffer_reg_uid_list
;
140 /* Next channel ID available for a newly registered channel. */
141 uint64_t next_channel_id
;
142 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
143 uint64_t used_channel_id
;
144 /* Tell or not if the session has to output the traces. */
145 unsigned int output_traces
;
146 unsigned int snapshot_mode
;
147 unsigned int has_non_default_channel
;
148 unsigned int live_timer_interval
; /* usec */
150 /* Metadata channel attributes. */
151 struct lttng_ust_channel_attr metadata_attr
;
154 * Path where to keep the shared memory files.
156 char root_shm_path
[PATH_MAX
];
157 char shm_path
[PATH_MAX
];
159 /* Current trace chunk of the ltt_session. */
160 struct lttng_trace_chunk
*current_trace_chunk
;
162 /* Trackers used for actual lookup on app registration. */
163 struct ust_id_tracker vpid_tracker
;
164 struct ust_id_tracker vuid_tracker
;
165 struct ust_id_tracker vgid_tracker
;
167 /* Tracker list of keys requested by users. */
168 struct process_attr_tracker
*tracker_vpid
;
169 struct process_attr_tracker
*tracker_vuid
;
170 struct process_attr_tracker
*tracker_vgid
;
174 * Validate that the id has reached the maximum allowed or not.
176 * Return 0 if NOT else 1.
178 static inline int trace_ust_is_max_id(uint64_t id
)
180 return (id
== UINT64_MAX
) ? 1 : 0;
184 * Return next available channel id and increment the used counter. The
185 * trace_ust_is_max_id function MUST be called before in order to validate if
186 * the maximum number of IDs have been reached. If not, it is safe to call this
189 * Return a unique channel ID. If max is reached, the used_channel_id counter
192 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session
*s
)
194 if (trace_ust_is_max_id(s
->used_channel_id
)) {
195 return s
->used_channel_id
;
198 s
->used_channel_id
++;
199 return s
->next_channel_id
++;
202 #ifdef HAVE_LIBLTTNG_UST_CTL
204 int trace_ust_ht_match_event(struct cds_lfht_node
*node
, const void *_key
);
205 int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
209 * Lookup functions. NULL is returned if not found.
211 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
212 uint64_t tracer_token
, char *name
, struct lttng_bytecode
*filter
,
213 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
214 struct lttng_event_exclusion
*exclusion
,
215 struct lttng_map_key
*key
);
216 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
218 struct ltt_ust_map
*trace_ust_find_map_by_name(struct lttng_ht
*ht
,
220 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
221 enum lttng_domain_type domain_type
);
224 * Create functions malloc() the data structure.
226 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
);
227 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
228 enum lttng_domain_type domain
);
229 struct ltt_ust_map
*trace_ust_create_map(const struct lttng_map
*map
);
230 enum lttng_error_code
trace_ust_create_event(uint64_t tracer_token
,
232 struct lttng_map_key
*key
,
233 enum lttng_event_type ev_type
,
234 enum lttng_loglevel_type ev_loglevel_type
,
235 enum lttng_loglevel ev_loglevel
,
236 char *filter_expression
,
237 struct lttng_bytecode
*filter
,
238 struct lttng_event_exclusion
*exclusion
,
240 struct ltt_ust_event
**ust_event
);
241 struct ltt_ust_context
*trace_ust_create_context(
242 const struct lttng_event_context
*ctx
);
243 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
244 const struct lttng_event_context
*ctx
);
245 void trace_ust_delete_channel(struct lttng_ht
*ht
,
246 struct ltt_ust_channel
*channel
);
247 void trace_ust_delete_map(struct lttng_ht
*ht
,
248 struct ltt_ust_map
*map
);
251 * Destroy functions free() the data structure and remove from linked list if
254 void trace_ust_destroy_session(struct ltt_ust_session
*session
);
255 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
);
256 void trace_ust_destroy_map(struct ltt_ust_map
*map
);
257 void trace_ust_destroy_event(struct ltt_ust_event
*event
);
258 void trace_ust_destroy_context(struct ltt_ust_context
*ctx
);
259 void trace_ust_free_session(struct ltt_ust_session
*session
);
261 int trace_ust_id_tracker_lookup(enum lttng_process_attr process_attr
,
262 struct ltt_ust_session
*session
,
264 enum lttng_error_code
trace_ust_process_attr_tracker_set_tracking_policy(
265 struct ltt_ust_session
*session
,
266 enum lttng_process_attr process_attr
,
267 enum lttng_tracking_policy policy
);
268 enum lttng_error_code
trace_ust_process_attr_tracker_inclusion_set_add_value(
269 struct ltt_ust_session
*session
,
270 enum lttng_process_attr process_attr
,
271 const struct process_attr_value
*value
);
272 enum lttng_error_code
trace_ust_process_attr_tracker_inclusion_set_remove_value(
273 struct ltt_ust_session
*session
,
274 enum lttng_process_attr process_attr
,
275 const struct process_attr_value
*value
);
276 const struct process_attr_tracker
*trace_ust_get_process_attr_tracker(
277 struct ltt_ust_session
*session
,
278 enum lttng_process_attr process_attr
);
280 #else /* HAVE_LIBLTTNG_UST_CTL */
282 static inline int trace_ust_ht_match_event(struct cds_lfht_node
*node
,
287 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
293 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
299 struct ltt_ust_map
*trace_ust_find_map_by_name(struct lttng_ht
*ht
,
305 struct ltt_ust_session
*trace_ust_create_session(unsigned int session_id
)
310 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
311 enum lttng_domain_type domain
)
316 struct ltt_ust_map
*trace_ust_create_map(const struct lttng_map
*map
)
321 enum lttng_error_code
trace_ust_create_event(uint64_t tracer_token
,
323 struct lttng_map_key
*key
,
324 enum lttng_event_type ev_type
,
325 enum lttng_loglevel_type ev_loglevel_type
,
326 enum lttng_loglevel ev_loglevel
,
327 char *filter_expression
,
328 struct lttng_bytecode
*filter
,
329 struct lttng_event_exclusion
*exclusion
,
331 struct ltt_ust_event
**ust_event
)
333 return LTTNG_ERR_NO_UST
;
336 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
341 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
346 void trace_ust_destroy_map(struct ltt_ust_map
*map
)
351 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
356 void trace_ust_free_session(struct ltt_ust_session
*session
)
361 struct ltt_ust_context
*trace_ust_create_context(
362 const struct lttng_event_context
*ctx
)
367 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
368 const struct lttng_event_context
*ctx
)
373 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
374 uint64_t tracer_token
, char *name
, struct lttng_bytecode
*filter
,
375 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
376 struct lttng_event_exclusion
*exclusion
,
377 struct lttng_map_key
*key
)
382 void trace_ust_delete_channel(struct lttng_ht
*ht
,
383 struct ltt_ust_channel
*channel
)
388 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
389 enum lttng_domain_type domain_type
)
393 static inline int trace_ust_id_tracker_lookup(
394 enum lttng_process_attr process_attr
,
395 struct ltt_ust_session
*session
,
400 static inline enum lttng_error_code
401 trace_ust_process_attr_tracker_set_tracking_policy(
402 struct ltt_ust_session
*session
,
403 enum lttng_process_attr process_attr
,
404 enum lttng_tracking_policy policy
)
408 static inline enum lttng_error_code
409 trace_ust_process_attr_tracker_inclusion_set_add_value(
410 struct ltt_ust_session
*session
,
411 enum lttng_process_attr process_attr
,
412 const struct process_attr_value
*value
)
416 static inline enum lttng_error_code
417 trace_ust_process_attr_tracker_inclusion_set_remove_value(
418 struct ltt_ust_session
*session
,
419 enum lttng_process_attr process_attr
,
420 const struct process_attr_value
*value
)
424 static inline const struct process_attr_tracker
*
425 trace_ust_get_process_attr_tracker(struct ltt_ust_session
*session
,
426 enum lttng_process_attr process_attr
)
431 #endif /* HAVE_LIBLTTNG_UST_CTL */
433 #endif /* _LTT_TRACE_UST_H */