Backport: trackers: update lttng-sessiond
[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 * 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.
8 *
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.
13 *
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.
17 */
18
19 #ifndef _LTT_TRACE_UST_H
20 #define _LTT_TRACE_UST_H
21
22 #include <limits.h>
23 #include <urcu/list.h>
24
25 #include <lttng/lttng.h>
26 #include <common/hashtable/hashtable.h>
27 #include <common/defaults.h>
28
29 #include "consumer.h"
30 #include "ust-ctl.h"
31
32 struct agent;
33
34 struct ltt_ust_ht_key {
35 const char *name;
36 const struct lttng_filter_bytecode *filter;
37 enum lttng_ust_loglevel_type loglevel_type;
38 int loglevel_value;
39 const struct lttng_event_exclusion *exclusion;
40 };
41
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;
47 };
48
49 /* UST event */
50 struct ltt_ust_event {
51 unsigned int enabled;
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;
57 /*
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.
62 */
63 bool internal;
64 };
65
66 /* UST channel */
67 struct ltt_ust_channel {
68 uint64_t id; /* unique id per session. */
69 unsigned int enabled;
70 /*
71 * A UST channel can be part of a userspace sub-domain such as JUL,
72 * Log4j, Python.
73 */
74 enum lttng_domain_type domain;
75 char name[LTTNG_UST_SYM_NAME_LEN];
76 struct lttng_ust_channel_attr attr;
77 struct lttng_ht *ctx;
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 };
86
87 /* UST domain global (LTTNG_DOMAIN_UST) */
88 struct ltt_ust_domain_global {
89 struct lttng_ht *channels;
90 struct cds_list_head registry_buffer_uid_list;
91 };
92
93 struct ust_id_tracker_node {
94 struct lttng_ht_node_ulong node;
95 };
96
97 struct ust_id_tracker {
98 struct lttng_ht *ht;
99 };
100
101 /* UST session */
102 struct ltt_ust_session {
103 uint64_t id; /* Unique identifier of session */
104 struct ltt_ust_domain_global domain_global;
105 /* Hash table of agent indexed by agent domain. */
106 struct lttng_ht *agents;
107 /* UID/GID of the user owning the session */
108 uid_t uid;
109 gid_t gid;
110 /* Is the session active meaning has is been started or stopped. */
111 unsigned int active:1;
112 struct consumer_output *consumer;
113 /* Sequence number for filters so the tracer knows the ordering. */
114 uint64_t filter_seq_num;
115 /* This indicates which type of buffer this session is set for. */
116 enum lttng_buffer_type buffer_type;
117 /* If set to 1, the buffer_type can not be changed anymore. */
118 int buffer_type_changed;
119 /* For per UID buffer, every buffer reg object is kept of this session */
120 struct cds_list_head buffer_reg_uid_list;
121 /* Next channel ID available for a newly registered channel. */
122 uint64_t next_channel_id;
123 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
124 uint64_t used_channel_id;
125 /* Tell or not if the session has to output the traces. */
126 unsigned int output_traces;
127 unsigned int snapshot_mode;
128 unsigned int has_non_default_channel;
129 unsigned int live_timer_interval; /* usec */
130
131 /* Metadata channel attributes. */
132 struct lttng_ust_channel_attr metadata_attr;
133
134 /*
135 * Path where to keep the shared memory files.
136 */
137 char root_shm_path[PATH_MAX];
138 char shm_path[PATH_MAX];
139
140 /* Trackers used for actual lookup on app registration. */
141 struct ust_id_tracker vpid_tracker;
142 struct ust_id_tracker vuid_tracker;
143 struct ust_id_tracker vgid_tracker;
144
145 /* Tracker list of keys requested by users. */
146 struct lttng_tracker_list *tracker_list_vpid;
147 struct lttng_tracker_list *tracker_list_vuid;
148 struct lttng_tracker_list *tracker_list_vgid;
149 };
150
151 /*
152 * Validate that the id has reached the maximum allowed or not.
153 *
154 * Return 0 if NOT else 1.
155 */
156 static inline int trace_ust_is_max_id(uint64_t id)
157 {
158 return (id == UINT64_MAX) ? 1 : 0;
159 }
160
161 /*
162 * Return next available channel id and increment the used counter. The
163 * trace_ust_is_max_id function MUST be called before in order to validate if
164 * the maximum number of IDs have been reached. If not, it is safe to call this
165 * function.
166 *
167 * Return a unique channel ID. If max is reached, the used_channel_id counter
168 * is returned.
169 */
170 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
171 {
172 if (trace_ust_is_max_id(s->used_channel_id)) {
173 return s->used_channel_id;
174 }
175
176 s->used_channel_id++;
177 return s->next_channel_id++;
178 }
179
180 #ifdef HAVE_LIBLTTNG_UST_CTL
181
182 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
183 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
184 const void *_key);
185
186 /*
187 * Lookup functions. NULL is returned if not found.
188 */
189 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
190 char *name, struct lttng_filter_bytecode *filter,
191 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
192 struct lttng_event_exclusion *exclusion);
193 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
194 char *name);
195 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
196 enum lttng_domain_type domain_type);
197
198 /*
199 * Create functions malloc() the data structure.
200 */
201 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
202 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
203 enum lttng_domain_type domain);
204 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
205 char *filter_expression,
206 struct lttng_filter_bytecode *filter,
207 struct lttng_event_exclusion *exclusion,
208 bool internal_event);
209 struct ltt_ust_context *trace_ust_create_context(
210 struct lttng_event_context *ctx);
211 int trace_ust_match_context(struct ltt_ust_context *uctx,
212 struct lttng_event_context *ctx);
213 void trace_ust_delete_channel(struct lttng_ht *ht,
214 struct ltt_ust_channel *channel);
215
216 /*
217 * Destroy functions free() the data structure and remove from linked list if
218 * it's applies.
219 */
220 void trace_ust_destroy_session(struct ltt_ust_session *session);
221 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
222 void trace_ust_destroy_event(struct ltt_ust_event *event);
223 void trace_ust_destroy_context(struct ltt_ust_context *ctx);
224
225 int trace_ust_track_id(enum lttng_tracker_type tracker_type,
226 struct ltt_ust_session *session,
227 struct lttng_tracker_id *id);
228 int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
229 struct ltt_ust_session *session,
230 struct lttng_tracker_id *id);
231
232 int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type,
233 struct ltt_ust_session *session, int id);
234
235 ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
236 struct ltt_ust_session *session,
237 struct lttng_tracker_id **_ids);
238
239 #else /* HAVE_LIBLTTNG_UST_CTL */
240
241 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
242 const void *_key)
243 {
244 return 0;
245 }
246 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
247 const void *_key)
248 {
249 return 0;
250 }
251 static inline
252 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
253 char *name)
254 {
255 return NULL;
256 }
257
258 static inline
259 struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
260 {
261 return NULL;
262 }
263 static inline
264 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
265 enum lttng_domain_type domain)
266 {
267 return NULL;
268 }
269 static inline
270 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
271 const char *filter_expression,
272 struct lttng_filter_bytecode *filter,
273 struct lttng_event_exclusion *exclusion,
274 bool internal_event)
275 {
276 return NULL;
277 }
278 static inline
279 void trace_ust_destroy_session(struct ltt_ust_session *session)
280 {
281 }
282
283 static inline
284 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
285 {
286 }
287
288 static inline
289 void trace_ust_destroy_event(struct ltt_ust_event *event)
290 {
291 }
292 static inline
293 struct ltt_ust_context *trace_ust_create_context(
294 struct lttng_event_context *ctx)
295 {
296 return NULL;
297 }
298 static inline
299 int trace_ust_match_context(struct ltt_ust_context *uctx,
300 struct lttng_event_context *ctx)
301 {
302 return 0;
303 }
304 static inline
305 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
306 char *name, struct lttng_filter_bytecode *filter,
307 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
308 struct lttng_event_exclusion *exclusion)
309 {
310 return NULL;
311 }
312 static inline
313 void trace_ust_delete_channel(struct lttng_ht *ht,
314 struct ltt_ust_channel *channel)
315 {
316 return;
317 }
318 static inline
319 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
320 enum lttng_domain_type domain_type)
321 {
322 return NULL;
323 }
324 static inline
325 int trace_ust_track_id(enum lttng_tracker_type tracker_type,
326 struct ltt_ust_session *session, int id)
327 {
328 return 0;
329 }
330 static inline
331 int trace_ust_untrack_id(enum lttng_tracker_type tracker_type,
332 struct ltt_ust_session *session, int id)
333 {
334 return 0;
335 }
336 static inline
337 int trace_ust_id_tracker_lookup(enum lttng_tracker_type tracker_type,
338 struct ltt_ust_session *session, int pid)
339 {
340 return 0;
341 }
342 static inline
343 ssize_t trace_ust_list_tracker_ids(enum lttng_tracker_type tracker_type,
344 struct ltt_ust_session *session,
345 struct lttng_tracker_id **_ids)
346 {
347 return -1;
348 }
349 #endif /* HAVE_LIBLTTNG_UST_CTL */
350
351 #endif /* _LTT_TRACE_UST_H */
This page took 0.043686 seconds and 5 git commands to generate.