Notify java agent of enabled application contexts
[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 };
84
85 /* UST domain global (LTTNG_DOMAIN_UST) */
86 struct ltt_ust_domain_global {
87 struct lttng_ht *channels;
88 struct cds_list_head registry_buffer_uid_list;
89 };
90
91 struct ust_pid_tracker_node {
92 struct lttng_ht_node_ulong node;
93 };
94
95 struct ust_pid_tracker {
96 struct lttng_ht *ht;
97 };
98
99 /* UST session */
100 struct ltt_ust_session {
101 uint64_t id; /* Unique identifier of session */
102 struct ltt_ust_domain_global domain_global;
103 /* Hash table of agent indexed by agent domain. */
104 struct lttng_ht *agents;
105 /* UID/GID of the user owning the session */
106 uid_t uid;
107 gid_t gid;
108 /* Is the session active meaning has is been started or stopped. */
109 unsigned int active:1;
110 struct consumer_output *consumer;
111 /* Sequence number for filters so the tracer knows the ordering. */
112 uint64_t filter_seq_num;
113 /* This indicates which type of buffer this session is set for. */
114 enum lttng_buffer_type buffer_type;
115 /* If set to 1, the buffer_type can not be changed anymore. */
116 int buffer_type_changed;
117 /* For per UID buffer, every buffer reg object is kept of this session */
118 struct cds_list_head buffer_reg_uid_list;
119 /* Next channel ID available for a newly registered channel. */
120 uint64_t next_channel_id;
121 /* Once this value reaches UINT32_MAX, no more id can be allocated. */
122 uint64_t used_channel_id;
123 /* Tell or not if the session has to output the traces. */
124 unsigned int output_traces;
125 unsigned int snapshot_mode;
126 unsigned int has_non_default_channel;
127 unsigned int live_timer_interval; /* usec */
128
129 /* Metadata channel attributes. */
130 struct lttng_ust_channel_attr metadata_attr;
131
132 /*
133 * Path where to keep the shared memory files.
134 */
135 char root_shm_path[PATH_MAX];
136 char shm_path[PATH_MAX];
137
138 struct ust_pid_tracker pid_tracker;
139 };
140
141 /*
142 * Validate that the id has reached the maximum allowed or not.
143 *
144 * Return 0 if NOT else 1.
145 */
146 static inline int trace_ust_is_max_id(uint64_t id)
147 {
148 return (id == UINT64_MAX) ? 1 : 0;
149 }
150
151 /*
152 * Return next available channel id and increment the used counter. The
153 * trace_ust_is_max_id function MUST be called before in order to validate if
154 * the maximum number of IDs have been reached. If not, it is safe to call this
155 * function.
156 *
157 * Return a unique channel ID. If max is reached, the used_channel_id counter
158 * is returned.
159 */
160 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
161 {
162 if (trace_ust_is_max_id(s->used_channel_id)) {
163 return s->used_channel_id;
164 }
165
166 s->used_channel_id++;
167 return s->next_channel_id++;
168 }
169
170 #ifdef HAVE_LIBLTTNG_UST_CTL
171
172 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
173 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
174 const void *_key);
175
176 /*
177 * Lookup functions. NULL is returned if not found.
178 */
179 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
180 char *name, struct lttng_filter_bytecode *filter,
181 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
182 struct lttng_event_exclusion *exclusion);
183 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
184 char *name);
185 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
186 enum lttng_domain_type domain_type);
187
188 /*
189 * Create functions malloc() the data structure.
190 */
191 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
192 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
193 enum lttng_domain_type domain);
194 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
195 char *filter_expression,
196 struct lttng_filter_bytecode *filter,
197 struct lttng_event_exclusion *exclusion,
198 bool internal_event);
199 struct ltt_ust_context *trace_ust_create_context(
200 struct lttng_event_context *ctx);
201 int trace_ust_match_context(struct ltt_ust_context *uctx,
202 struct lttng_event_context *ctx);
203 void trace_ust_delete_channel(struct lttng_ht *ht,
204 struct ltt_ust_channel *channel);
205
206 /*
207 * Destroy functions free() the data structure and remove from linked list if
208 * it's applies.
209 */
210 void trace_ust_destroy_session(struct ltt_ust_session *session);
211 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
212 void trace_ust_destroy_event(struct ltt_ust_event *event);
213 void trace_ust_destroy_context(struct ltt_ust_context *ctx);
214
215 int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
216 int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
217
218 int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid);
219
220 ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
221 int32_t **_pids);
222
223 #else /* HAVE_LIBLTTNG_UST_CTL */
224
225 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
226 const void *_key)
227 {
228 return 0;
229 }
230 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
231 const void *_key)
232 {
233 return 0;
234 }
235 static inline
236 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
237 char *name)
238 {
239 return NULL;
240 }
241
242 static inline
243 struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
244 {
245 return NULL;
246 }
247 static inline
248 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
249 enum lttng_domain_type domain)
250 {
251 return NULL;
252 }
253 static inline
254 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
255 const char *filter_expression,
256 struct lttng_filter_bytecode *filter,
257 struct lttng_event_exclusion *exclusion,
258 bool internal_event)
259 {
260 return NULL;
261 }
262 static inline
263 void trace_ust_destroy_session(struct ltt_ust_session *session)
264 {
265 }
266
267 static inline
268 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
269 {
270 }
271
272 static inline
273 void trace_ust_destroy_event(struct ltt_ust_event *event)
274 {
275 }
276 static inline
277 struct ltt_ust_context *trace_ust_create_context(
278 struct lttng_event_context *ctx)
279 {
280 return NULL;
281 }
282 static inline
283 int trace_ust_match_context(struct ltt_ust_context *uctx,
284 struct lttng_event_context *ctx)
285 {
286 return 0;
287 }
288 static inline
289 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
290 char *name, struct lttng_filter_bytecode *filter,
291 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
292 struct lttng_event_exclusion *exclusion)
293 {
294 return NULL;
295 }
296 static inline
297 void trace_ust_delete_channel(struct lttng_ht *ht,
298 struct ltt_ust_channel *channel)
299 {
300 return;
301 }
302 static inline
303 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
304 enum lttng_domain_type domain_type)
305 {
306 return NULL;
307 }
308 static inline
309 int trace_ust_track_pid(struct ltt_ust_session *session, int pid)
310 {
311 return 0;
312 }
313 static inline
314 int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid)
315 {
316 return 0;
317 }
318 static inline
319 int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid)
320 {
321 return 0;
322 }
323 static inline
324 ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
325 int32_t **_pids)
326 {
327 return -1;
328 }
329 #endif /* HAVE_LIBLTTNG_UST_CTL */
330
331 #endif /* _LTT_TRACE_UST_H */
This page took 0.037617 seconds and 4 git commands to generate.