Fix: save: leak of configuration file fd
[lttng-tools.git] / src / bin / lttng-sessiond / trace-ust.h
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #ifndef _LTT_TRACE_UST_H
19 #define _LTT_TRACE_UST_H
20
21 #include <config.h>
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 "agent.h"
31 #include "ust-ctl.h"
32
33 struct ltt_ust_ht_key {
34 const char *name;
35 const struct lttng_filter_bytecode *filter;
36 enum lttng_ust_loglevel_type loglevel_type;
37 int loglevel_value;
38 const struct lttng_event_exclusion *exclusion;
39 };
40
41 /* Context hash table nodes */
42 struct ltt_ust_context {
43 struct lttng_ust_context ctx;
44 struct lttng_ht_node_ulong node;
45 struct cds_list_head list;
46 };
47
48 /* UST event */
49 struct ltt_ust_event {
50 unsigned int enabled;
51 struct lttng_ust_event attr;
52 struct lttng_ht_node_str node;
53 char *filter_expression;
54 struct lttng_filter_bytecode *filter;
55 struct lttng_event_exclusion *exclusion;
56 bool internal;
57 };
58
59 /* UST channel */
60 struct ltt_ust_channel {
61 uint64_t id; /* unique id per session. */
62 unsigned int enabled;
63 /*
64 * A UST channel can be part of a userspace sub-domain such as JUL,
65 * Log4j, Python.
66 */
67 enum lttng_domain_type domain;
68 char name[LTTNG_UST_SYM_NAME_LEN];
69 struct lttng_ust_channel_attr attr;
70 struct lttng_ht *ctx;
71 struct cds_list_head ctx_list;
72 struct lttng_ht *events;
73 struct lttng_ht_node_str node;
74 uint64_t tracefile_size;
75 uint64_t tracefile_count;
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_pid_tracker_node {
85 struct lttng_ht_node_ulong node;
86 };
87
88 struct ust_pid_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 struct ust_pid_tracker pid_tracker;
132 };
133
134 /*
135 * Validate that the id has reached the maximum allowed or not.
136 *
137 * Return 0 if NOT else 1.
138 */
139 static inline int trace_ust_is_max_id(uint64_t id)
140 {
141 return (id == UINT64_MAX) ? 1 : 0;
142 }
143
144 /*
145 * Return next available channel id and increment the used counter. The
146 * trace_ust_is_max_id function MUST be called before in order to validate if
147 * the maximum number of IDs have been reached. If not, it is safe to call this
148 * function.
149 *
150 * Return a unique channel ID. If max is reached, the used_channel_id counter
151 * is returned.
152 */
153 static inline uint64_t trace_ust_get_next_chan_id(struct ltt_ust_session *s)
154 {
155 if (trace_ust_is_max_id(s->used_channel_id)) {
156 return s->used_channel_id;
157 }
158
159 s->used_channel_id++;
160 return s->next_channel_id++;
161 }
162
163 #ifdef HAVE_LIBLTTNG_UST_CTL
164
165 int trace_ust_ht_match_event(struct cds_lfht_node *node, const void *_key);
166 int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
167 const void *_key);
168
169 /*
170 * Lookup functions. NULL is returned if not found.
171 */
172 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
173 char *name, struct lttng_filter_bytecode *filter,
174 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
175 struct lttng_event_exclusion *exclusion);
176 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
177 char *name);
178 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
179 enum lttng_domain_type domain_type);
180
181 /*
182 * Create functions malloc() the data structure.
183 */
184 struct ltt_ust_session *trace_ust_create_session(uint64_t session_id);
185 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
186 enum lttng_domain_type domain);
187 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
188 char *filter_expression,
189 struct lttng_filter_bytecode *filter,
190 struct lttng_event_exclusion *exclusion,
191 bool internal_event);
192 struct ltt_ust_context *trace_ust_create_context(
193 struct lttng_event_context *ctx);
194 int trace_ust_match_context(struct ltt_ust_context *uctx,
195 struct lttng_event_context *ctx);
196 void trace_ust_delete_channel(struct lttng_ht *ht,
197 struct ltt_ust_channel *channel);
198
199 /*
200 * Destroy functions free() the data structure and remove from linked list if
201 * it's applies.
202 */
203 void trace_ust_destroy_session(struct ltt_ust_session *session);
204 void trace_ust_destroy_channel(struct ltt_ust_channel *channel);
205 void trace_ust_destroy_event(struct ltt_ust_event *event);
206
207 int trace_ust_track_pid(struct ltt_ust_session *session, int pid);
208 int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid);
209
210 int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid);
211
212 ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
213 int32_t **_pids);
214
215 #else /* HAVE_LIBLTTNG_UST_CTL */
216
217 static inline int trace_ust_ht_match_event(struct cds_lfht_node *node,
218 const void *_key)
219 {
220 return 0;
221 }
222 static inline int trace_ust_ht_match_event_by_name(struct cds_lfht_node *node,
223 const void *_key)
224 {
225 return 0;
226 }
227 static inline
228 struct ltt_ust_channel *trace_ust_find_channel_by_name(struct lttng_ht *ht,
229 char *name)
230 {
231 return NULL;
232 }
233
234 static inline
235 struct ltt_ust_session *trace_ust_create_session(unsigned int session_id)
236 {
237 return NULL;
238 }
239 static inline
240 struct ltt_ust_channel *trace_ust_create_channel(struct lttng_channel *attr,
241 enum lttng_domain_type domain)
242 {
243 return NULL;
244 }
245 static inline
246 struct ltt_ust_event *trace_ust_create_event(struct lttng_event *ev,
247 const char *filter_expression,
248 struct lttng_filter_bytecode *filter,
249 struct lttng_event_exclusion *exclusion,
250 bool internal_event)
251 {
252 return NULL;
253 }
254 static inline
255 void trace_ust_destroy_session(struct ltt_ust_session *session)
256 {
257 }
258
259 static inline
260 void trace_ust_destroy_channel(struct ltt_ust_channel *channel)
261 {
262 }
263
264 static inline
265 void trace_ust_destroy_event(struct ltt_ust_event *event)
266 {
267 }
268 static inline
269 struct ltt_ust_context *trace_ust_create_context(
270 struct lttng_event_context *ctx)
271 {
272 return NULL;
273 }
274 static inline
275 int trace_ust_match_context(struct ltt_ust_context *uctx,
276 struct lttng_event_context *ctx)
277 {
278 return 0;
279 }
280 static inline
281 struct ltt_ust_event *trace_ust_find_event(struct lttng_ht *ht,
282 char *name, struct lttng_filter_bytecode *filter,
283 enum lttng_ust_loglevel_type loglevel_type, int loglevel_value,
284 struct lttng_event_exclusion *exclusion)
285 {
286 return NULL;
287 }
288 static inline
289 void trace_ust_delete_channel(struct lttng_ht *ht,
290 struct ltt_ust_channel *channel)
291 {
292 return;
293 }
294 static inline
295 struct agent *trace_ust_find_agent(struct ltt_ust_session *session,
296 enum lttng_domain_type domain_type)
297 {
298 return NULL;
299 }
300 static inline
301 int trace_ust_track_pid(struct ltt_ust_session *session, int pid)
302 {
303 return 0;
304 }
305 static inline
306 int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid)
307 {
308 return 0;
309 }
310 static inline
311 int trace_ust_pid_tracker_lookup(struct ltt_ust_session *session, int pid)
312 {
313 return 0;
314 }
315 static inline
316 ssize_t trace_ust_list_tracker_pids(struct ltt_ust_session *session,
317 int32_t **_pids)
318 {
319 return -1;
320 }
321 #endif /* HAVE_LIBLTTNG_UST_CTL */
322
323 #endif /* _LTT_TRACE_UST_H */
This page took 0.036998 seconds and 4 git commands to generate.