2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef _LTT_TRACE_UST_H
20 #define _LTT_TRACE_UST_H
23 #include <urcu/list.h>
25 #include <lttng/lttng.h>
26 #include <common/hashtable/hashtable.h>
27 #include <common/defaults.h>
30 #include "lttng-ust-ctl.h"
34 struct ltt_ust_ht_key
{
36 const struct lttng_filter_bytecode
*filter
;
37 enum lttng_ust_loglevel_type loglevel_type
;
39 const struct lttng_event_exclusion
*exclusion
;
42 /* Context hash table nodes */
43 struct ltt_ust_context
{
44 struct lttng_ust_context_attr ctx
;
45 struct lttng_ht_node_ulong node
;
46 struct cds_list_head list
;
50 struct ltt_ust_event
{
52 struct lttng_ust_event attr
;
53 struct lttng_ht_node_str node
;
54 char *filter_expression
;
55 struct lttng_filter_bytecode
*filter
;
56 struct lttng_event_exclusion
*exclusion
;
58 * An internal event is an event which was created by the session daemon
59 * through which, for example, events emitted in Agent domains are
60 * "funelled". This is used to hide internal events from external
61 * clients as they should never be modified by the external world.
67 struct ltt_ust_channel
{
68 uint64_t id
; /* unique id per session. */
71 * A UST channel can be part of a userspace sub-domain such as JUL,
74 enum lttng_domain_type domain
;
75 char name
[LTTNG_UST_SYM_NAME_LEN
];
76 struct lttng_ust_channel_attr attr
;
78 struct cds_list_head ctx_list
;
79 struct lttng_ht
*events
;
80 struct lttng_ht_node_str node
;
81 uint64_t tracefile_size
;
82 uint64_t tracefile_count
;
83 uint64_t per_pid_closed_app_discarded
;
84 uint64_t per_pid_closed_app_lost
;
85 uint64_t monitor_timer_interval
;
88 /* UST domain global (LTTNG_DOMAIN_UST) */
89 struct ltt_ust_domain_global
{
90 struct lttng_ht
*channels
;
91 struct cds_list_head registry_buffer_uid_list
;
94 struct ust_id_tracker_node
{
95 struct lttng_ht_node_ulong node
;
98 struct ust_id_tracker
{
103 struct ltt_ust_session
{
104 uint64_t id
; /* Unique identifier of session */
105 struct ltt_ust_domain_global domain_global
;
106 /* Hash table of agent indexed by agent domain. */
107 struct lttng_ht
*agents
;
108 /* UID/GID of the user owning the session */
111 /* Is the session active meaning has is been started or stopped. */
112 unsigned int active
:1;
113 struct consumer_output
*consumer
;
114 /* Sequence number for filters so the tracer knows the ordering. */
115 uint64_t filter_seq_num
;
116 /* This indicates which type of buffer this session is set for. */
117 enum lttng_buffer_type buffer_type
;
118 /* If set to 1, the buffer_type can not be changed anymore. */
119 int buffer_type_changed
;
120 /* For per UID buffer, every buffer reg object is kept of this session */
121 struct cds_list_head buffer_reg_uid_list
;
122 /* Next channel ID available for a newly registered channel. */
123 uint64_t next_channel_id
;
124 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
125 uint64_t used_channel_id
;
126 /* Tell or not if the session has to output the traces. */
127 unsigned int output_traces
;
128 unsigned int snapshot_mode
;
129 unsigned int has_non_default_channel
;
130 unsigned int live_timer_interval
; /* usec */
132 /* Metadata channel attributes. */
133 struct lttng_ust_channel_attr metadata_attr
;
136 * Path where to keep the shared memory files.
138 char root_shm_path
[PATH_MAX
];
139 char shm_path
[PATH_MAX
];
141 /* Current trace chunk of the ltt_session. */
142 struct lttng_trace_chunk
*current_trace_chunk
;
144 /* Trackers used for actual lookup on app registration. */
145 struct ust_id_tracker vpid_tracker
;
146 struct ust_id_tracker vuid_tracker
;
147 struct ust_id_tracker vgid_tracker
;
149 /* Tracker list of keys requested by users. */
150 struct lttng_tracker_list
*tracker_list_vpid
;
151 struct lttng_tracker_list
*tracker_list_vuid
;
152 struct lttng_tracker_list
*tracker_list_vgid
;
156 * Validate that the id has reached the maximum allowed or not.
158 * Return 0 if NOT else 1.
160 static inline int trace_ust_is_max_id(uint64_t id
)
162 return (id
== UINT64_MAX
) ? 1 : 0;
166 * Return next available channel id and increment the used counter. The
167 * trace_ust_is_max_id function MUST be called before in order to validate if
168 * the maximum number of IDs have been reached. If not, it is safe to call this
171 * Return a unique channel ID. If max is reached, the used_channel_id counter
174 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session
*s
)
176 if (trace_ust_is_max_id(s
->used_channel_id
)) {
177 return s
->used_channel_id
;
180 s
->used_channel_id
++;
181 return s
->next_channel_id
++;
184 #ifdef HAVE_LIBLTTNG_UST_CTL
186 int trace_ust_ht_match_event(struct cds_lfht_node
*node
, const void *_key
);
187 int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
191 * Lookup functions. NULL is returned if not found.
193 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
194 char *name
, struct lttng_filter_bytecode
*filter
,
195 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
196 struct lttng_event_exclusion
*exclusion
);
197 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
199 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
200 enum lttng_domain_type domain_type
);
203 * Create functions malloc() the data structure.
205 struct ltt_ust_session
*trace_ust_create_session(uint64_t session_id
);
206 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
207 enum lttng_domain_type domain
);
208 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
209 char *filter_expression
,
210 struct lttng_filter_bytecode
*filter
,
211 struct lttng_event_exclusion
*exclusion
,
212 bool internal_event
, struct ltt_ust_event
**ust_event
);
213 struct ltt_ust_context
*trace_ust_create_context(
214 const struct lttng_event_context
*ctx
);
215 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
216 const struct lttng_event_context
*ctx
);
217 void trace_ust_delete_channel(struct lttng_ht
*ht
,
218 struct ltt_ust_channel
*channel
);
221 * Destroy functions free() the data structure and remove from linked list if
224 void trace_ust_destroy_session(struct ltt_ust_session
*session
);
225 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
);
226 void trace_ust_destroy_event(struct ltt_ust_event
*event
);
227 void trace_ust_destroy_context(struct ltt_ust_context
*ctx
);
228 void trace_ust_free_session(struct ltt_ust_session
*session
);
230 int trace_ust_track_id(enum lttng_tracker_type tracker_type
,
231 struct ltt_ust_session
*session
,
232 const struct lttng_tracker_id
*id
);
233 int trace_ust_untrack_id(enum lttng_tracker_type tracker_type
,
234 struct ltt_ust_session
*session
,
235 const struct lttng_tracker_id
*id
);
237 int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type
,
238 struct ltt_ust_session
*session
,
241 int trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type
,
242 struct ltt_ust_session
*session
,
243 struct lttng_tracker_ids
**_ids
);
245 #else /* HAVE_LIBLTTNG_UST_CTL */
247 static inline int trace_ust_ht_match_event(struct cds_lfht_node
*node
,
252 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node
*node
,
258 struct ltt_ust_channel
*trace_ust_find_channel_by_name(struct lttng_ht
*ht
,
265 struct ltt_ust_session
*trace_ust_create_session(unsigned int session_id
)
270 struct ltt_ust_channel
*trace_ust_create_channel(struct lttng_channel
*attr
,
271 enum lttng_domain_type domain
)
276 enum lttng_error_code
trace_ust_create_event(struct lttng_event
*ev
,
277 const char *filter_expression
,
278 struct lttng_filter_bytecode
*filter
,
279 struct lttng_event_exclusion
*exclusion
,
280 bool internal_event
, struct ltt_ust_event
**ust_event
)
282 return LTTNG_ERR_NO_UST
;
285 void trace_ust_destroy_session(struct ltt_ust_session
*session
)
290 void trace_ust_destroy_channel(struct ltt_ust_channel
*channel
)
295 void trace_ust_destroy_event(struct ltt_ust_event
*event
)
300 void trace_ust_free_session(struct ltt_ust_session
*session
)
305 struct ltt_ust_context
*trace_ust_create_context(
306 const struct lttng_event_context
*ctx
)
311 int trace_ust_match_context(const struct ltt_ust_context
*uctx
,
312 const struct lttng_event_context
*ctx
)
317 struct ltt_ust_event
*trace_ust_find_event(struct lttng_ht
*ht
,
318 char *name
, struct lttng_filter_bytecode
*filter
,
319 enum lttng_ust_loglevel_type loglevel_type
, int loglevel_value
,
320 struct lttng_event_exclusion
*exclusion
)
325 void trace_ust_delete_channel(struct lttng_ht
*ht
,
326 struct ltt_ust_channel
*channel
)
331 struct agent
*trace_ust_find_agent(struct ltt_ust_session
*session
,
332 enum lttng_domain_type domain_type
)
336 static inline int trace_ust_track_id(enum lttng_tracker_type tracker_type
,
337 struct ltt_ust_session
*session
,
338 const struct lttng_tracker_id
*id
);
342 static inline int trace_ust_untrack_id(enum lttng_tracker_type tracker_type
,
343 struct ltt_ust_session
*session
,
344 const struct lttng_tracker_id
*id
)
348 static inline int trace_ust_id_tracker_lookup(
349 enum lttng_tracker_type tracker_type
,
350 struct ltt_ust_session
*session
,
355 static inline int trace_ust_list_tracker_ids(
356 enum lttng_tracker_type tracker_type
,
357 struct ltt_ust_session
*session
,
358 struct lttng_tracker_ids
**_ids
)
362 #endif /* HAVE_LIBLTTNG_UST_CTL */
364 #endif /* _LTT_TRACE_UST_H */