a06c471cce9a6c10a7673f10e86ab1d55da31eb7
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
1 /*
2 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 */
8
9 #ifndef _LTT_TRACE_UST_H
10 #define _LTT_TRACE_UST_H
11
12 #include <limits.h>
13 #include <urcu/list.h>
14
15 #include <lttng/lttng.h>
16 #include <common/hashtable/hashtable.h>
17 #include <common/defaults.h>
18
19 #include "consumer.h"
20 #include "lttng-ust-ctl.h"
21
22 struct agent;
23
24 struct ltt_ust_ht_key {
25 const char *name;
26 const struct lttng_filter_bytecode *filter;
27 enum lttng_ust_loglevel_type loglevel_type;
28 int loglevel_value;
29 const struct lttng_event_exclusion *exclusion;
30 };
31
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;
37 };
38
39 /* UST event */
40 struct ltt_ust_event {
41 unsigned int enabled;
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;
47 /*
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.
52 */
53 bool internal;
54 };
55
56 /* UST channel */
57 struct ltt_ust_channel {
58 uint64_t id; /* unique id per session. */
59 unsigned int enabled;
60 /*
61 * A UST channel can be part of a userspace sub-domain such as JUL,
62 * Log4j, Python.
63 */
64 enum lttng_domain_type domain;
65 char name[LTTNG_UST_SYM_NAME_LEN];
66 struct lttng_ust_channel_attr attr;
67 struct lttng_ht *ctx;
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;
76 };
77
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;
82 };
83
84 struct ust_id_tracker_node {
85 struct lttng_ht_node_ulong node;
86 };
87
88 struct ust_id_tracker {
89 struct lttng_ht *ht;
90 };
91
92 /* UST session */
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 */
99 uid_t uid;
100 gid_t gid;
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 */
121
122 /* Metadata channel attributes. */
123 struct lttng_ust_channel_attr metadata_attr;
124
125 /*
126 * Path where to keep the shared memory files.
127 */
128 char root_shm_path[PATH_MAX];
129 char shm_path[PATH_MAX];
130
131 /* Current trace chunk of the ltt_session. */
132 struct lttng_trace_chunk *current_trace_chunk;
133
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;
138
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;
143 };
144
145 /*
146 * Validate that the id has reached the maximum allowed or not.
147 *
148 * Return 0 if NOT else 1.
149 */
150 static inline int trace_ust_is_max_id(uint64_t id)
151 {
152 return (id == UINT64_MAX) ? 1 : 0;
153 }
154
155 /*
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
159 * function.
160 *
161 * Return a unique channel ID. If max is reached, the used_channel_id counter
162 * is returned.
163 */
164 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
165 {
166 if (trace_ust_is_max_id(s->used_channel_id)) {
167 return s->used_channel_id;
168 }
169
170 s->used_channel_id++;
171 return s->next_channel_id++;
172 }
173
174 #ifdef HAVE_LIBLTTNG_UST_CTL
175
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,
178 const void *_key);
179
180 /*
181 * Lookup functions. NULL is returned if not found.
182 */
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,
188 const char *name);
189 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
190 enum lttng_domain_type domain_type);
191
192 /*
193 * Create functions malloc() the data structure.
194 */
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);
209
210 /*
211 * Destroy functions free() the data structure and remove from linked list if
212 * it's applies.
213 */
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);
219
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);
226
227 int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type,
228 struct ltt_ust_session *session,
229 int id);
230
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);
234
235 #else /* HAVE_LIBLTTNG_UST_CTL */
236
237 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
238 const void *_key)
239 {
240 return 0;
241 }
242 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
243 const void *_key)
244 {
245 return 0;
246 }
247 static inline
248 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
249 const char *name)
250 {
251 return NULL;
252 }
253
254 static inline
255 struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
256 {
257 return NULL;
258 }
259 static inline
260 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
261 enum lttng_domain_type domain)
262 {
263 return NULL;
264 }
265 static inline
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)
271 {
272 return LTTNG_ERR_NO_UST;
273 }
274 static inline
275 void trace_ust_destroy_session(struct ltt_ust_session *session)
276 {
277 }
278
279 static inline
280 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
281 {
282 }
283
284 static inline
285 void trace_ust_destroy_event(struct ltt_ust_event *event)
286 {
287 }
288
289 static inline
290 void trace_ust_free_session(struct ltt_ust_session *session)
291 {
292 }
293
294 static inline
295 struct ltt_ust_context *trace_ust_create_context(
296 const struct lttng_event_context *ctx)
297 {
298 return NULL;
299 }
300 static inline
301 int trace_ust_match_context(const struct ltt_ust_context *uctx,
302 const struct lttng_event_context *ctx)
303 {
304 return 0;
305 }
306 static inline
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)
311 {
312 return NULL;
313 }
314 static inline
315 void trace_ust_delete_channel(struct lttng_ht *ht,
316 struct ltt_ust_channel *channel)
317 {
318 return;
319 }
320 static inline
321 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
322 enum lttng_domain_type domain_type)
323 {
324 return NULL;
325 }
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)
329 {
330 return 0;
331 }
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)
335 {
336 return 0;
337 }
338 static inline int trace_ust_id_tracker_lookup(
339 enum lttng_tracker_type tracker_type,
340 struct ltt_ust_session *session,
341 int pid)
342 {
343 return 0;
344 }
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)
349 {
350 return -1;
351 }
352 #endif /* HAVE_LIBLTTNG_UST_CTL */
353
354 #endif /* _LTT_TRACE_UST_H */
This page took 0.053417 seconds and 3 git commands to generate.