8c23c319d6c41fd6c037f85f43674ff3752ad4af
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.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_UST_APP_H
19 #define _LTT_UST_APP_H
20
21 #include <stdint.h>
22
23 #include "trace-ust.h"
24
25 /* lttng-ust supported version. */
26 #define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
27 #define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
28
29 #define UST_APP_EVENT_LIST_SIZE 32
30
31 struct lttng_filter_bytecode;
32 struct lttng_ust_filter_bytecode;
33
34 extern int ust_consumerd64_fd, ust_consumerd32_fd;
35
36 struct ust_app_ht_key {
37 const char *name;
38 const struct lttng_ust_filter_bytecode *filter;
39 enum lttng_ust_loglevel_type loglevel;
40 };
41
42 /*
43 * Application registration data structure.
44 */
45 struct ust_register_msg {
46 uint32_t major;
47 uint32_t minor;
48 pid_t pid;
49 pid_t ppid;
50 uid_t uid;
51 gid_t gid;
52 uint32_t bits_per_long;
53 char name[16];
54 };
55
56 /*
57 * Global applications HT used by the session daemon. This table is indexed by
58 * PID using the pid_n node and pid value of an ust_app.
59 */
60 struct lttng_ht *ust_app_ht;
61
62 /*
63 * Global applications HT used by the session daemon. This table is indexed by
64 * socket using the sock_n node and sock value of an ust_app.
65 */
66 struct lttng_ht *ust_app_ht_by_sock;
67
68 struct ust_app_ctx {
69 int handle;
70 struct lttng_ust_context ctx;
71 struct lttng_ust_object_data *obj;
72 struct lttng_ht_node_ulong node;
73 };
74
75 struct ust_app_event {
76 int enabled;
77 int handle;
78 struct lttng_ust_object_data *obj;
79 struct lttng_ust_event attr;
80 char name[LTTNG_UST_SYM_NAME_LEN];
81 struct lttng_ht_node_str node;
82 struct lttng_ust_filter_bytecode *filter;
83 };
84
85 struct ust_app_channel {
86 int enabled;
87 int handle;
88 char name[LTTNG_UST_SYM_NAME_LEN];
89 struct lttng_ust_channel attr;
90 struct lttng_ust_object_data *obj;
91 struct ltt_ust_stream_list streams;
92 struct lttng_ht *ctx;
93 struct lttng_ht *events;
94 struct lttng_ht_node_str node;
95 };
96
97 struct ust_app_session {
98 int enabled;
99 /* started: has the session been in started state at any time ? */
100 int started; /* allows detection of start vs restart. */
101 int handle; /* used has unique identifier for app session */
102 int id; /* session unique identifier */
103 struct ltt_ust_metadata *metadata;
104 struct lttng_ht *channels; /* Registered channels */
105 struct lttng_ht_node_ulong node;
106 char path[PATH_MAX];
107 /* UID/GID of the user owning the session */
108 uid_t uid;
109 gid_t gid;
110 struct cds_list_head teardown_node;
111 };
112
113 /*
114 * Registered traceable applications. Libust registers to the session daemon
115 * and a linked list is kept of all running traceable app.
116 */
117 struct ust_app {
118 int sock;
119 pid_t pid;
120 pid_t ppid;
121 uid_t uid; /* User ID that owns the apps */
122 gid_t gid; /* Group ID that owns the apps */
123 int bits_per_long;
124 int compatible; /* If the lttng-ust tracer version does not match the
125 supported version of the session daemon, this flag is
126 set to 0 (NOT compatible) else 1. */
127 struct lttng_ust_tracer_version version;
128 uint32_t v_major; /* Verion major number */
129 uint32_t v_minor; /* Verion minor number */
130 char name[17]; /* Process name (short) */
131 struct lttng_ht *sessions;
132 struct lttng_ht_node_ulong pid_n;
133 struct lttng_ht_node_ulong sock_n;
134 /*
135 * This is a list of ust app session that, once the app is going into
136 * teardown mode, in the RCU call, each node in this list is removed and
137 * deleted.
138 *
139 * Element of the list are added when an application unregisters after each
140 * ht_del of ust_app_session associated to this app. This list is NOT used
141 * when a session is destroyed.
142 */
143 struct cds_list_head teardown_head;
144 };
145
146 #ifdef HAVE_LIBLTTNG_UST_CTL
147
148 int ust_app_register(struct ust_register_msg *msg, int sock);
149 static inline
150 int ust_app_register_done(int sock)
151 {
152 return ustctl_register_done(sock);
153 }
154 void ust_app_unregister(int sock);
155 unsigned long ust_app_list_count(void);
156 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
157 int ust_app_stop_trace(struct ltt_ust_session *usess, struct ust_app *app);
158 int ust_app_start_trace_all(struct ltt_ust_session *usess);
159 int ust_app_stop_trace_all(struct ltt_ust_session *usess);
160 int ust_app_destroy_trace_all(struct ltt_ust_session *usess);
161 int ust_app_list_events(struct lttng_event **events);
162 int ust_app_list_event_fields(struct lttng_event_field **fields);
163 int ust_app_create_channel_glb(struct ltt_ust_session *usess,
164 struct ltt_ust_channel *uchan);
165 int ust_app_create_event_glb(struct ltt_ust_session *usess,
166 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
167 int ust_app_disable_event_pid(struct ltt_ust_session *usess,
168 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
169 pid_t pid);
170 int ust_app_enable_event_pid(struct ltt_ust_session *usess,
171 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
172 pid_t pid);
173 int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
174 struct ltt_ust_channel *uchan);
175 int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
176 struct ltt_ust_channel *uchan);
177 int ust_app_enable_event_glb(struct ltt_ust_session *usess,
178 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
179 int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
180 struct ltt_ust_channel *uchan);
181 int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
182 struct ltt_ust_channel *uchan);
183 int ust_app_disable_event_glb(struct ltt_ust_session *usess,
184 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
185 int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
186 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx);
187 void ust_app_global_update(struct ltt_ust_session *usess, int sock);
188
189 void ust_app_clean_list(void);
190 void ust_app_ht_alloc(void);
191 struct lttng_ht *ust_app_get_ht(void);
192 struct ust_app *ust_app_find_by_pid(pid_t pid);
193 int ust_app_validate_version(int sock);
194 int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate);
195
196 #else /* HAVE_LIBLTTNG_UST_CTL */
197
198 static inline
199 int ust_app_destroy_trace_all(struct ltt_ust_session *usess)
200 {
201 return 0;
202 }
203 static inline
204 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
205 {
206 return 0;
207 }
208 static inline
209 int ust_app_start_trace_all(struct ltt_ust_session *usess)
210 {
211 return 0;
212 }
213 static inline
214 int ust_app_stop_trace_all(struct ltt_ust_session *usess)
215 {
216 return 0;
217 }
218 static inline
219 int ust_app_list_events(struct lttng_event **events)
220 {
221 return -ENOSYS;
222 }
223 static inline
224 int ust_app_list_event_fields(struct lttng_event_field **fields)
225 {
226 return -ENOSYS;
227 }
228 static inline
229 int ust_app_register(struct ust_register_msg *msg, int sock)
230 {
231 return -ENOSYS;
232 }
233 static inline
234 int ust_app_register_done(int sock)
235 {
236 return -ENOSYS;
237 }
238 static inline
239 void ust_app_unregister(int sock)
240 {
241 }
242 static inline
243 unsigned int ust_app_list_count(void)
244 {
245 return 0;
246 }
247 static inline
248 void ust_app_lock_list(void)
249 {
250 }
251 static inline
252 void ust_app_unlock_list(void)
253 {
254 }
255 static inline
256 void ust_app_clean_list(void)
257 {
258 }
259 static inline
260 struct ust_app_list *ust_app_get_list(void)
261 {
262 return NULL;
263 }
264 static inline
265 struct ust_app *ust_app_get_by_pid(pid_t pid)
266 {
267 return NULL;
268 }
269 static inline
270 struct lttng_ht *ust_app_get_ht(void)
271 {
272 return NULL;
273 }
274 static inline
275 void ust_app_ht_alloc(void)
276 {}
277 static inline
278 void ust_app_global_update(struct ltt_ust_session *usess, int sock)
279 {}
280 static inline
281 int ust_app_disable_channel_glb(struct ltt_ust_session *usess,
282 struct ltt_ust_channel *uchan)
283 {
284 return 0;
285 }
286 static inline
287 int ust_app_enable_channel_glb(struct ltt_ust_session *usess,
288 struct ltt_ust_channel *uchan)
289 {
290 return 0;
291 }
292 static inline
293 int ust_app_create_channel_glb(struct ltt_ust_session *usess,
294 struct ltt_ust_channel *uchan)
295 {
296 return 0;
297 }
298 static inline
299 int ust_app_disable_all_event_glb(struct ltt_ust_session *usess,
300 struct ltt_ust_channel *uchan)
301 {
302 return 0;
303 }
304 static inline
305 int ust_app_enable_all_event_glb(struct ltt_ust_session *usess,
306 struct ltt_ust_channel *uchan)
307 {
308 return 0;
309 }
310 static inline
311 int ust_app_create_event_glb(struct ltt_ust_session *usess,
312 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
313 {
314 return 0;
315 }
316 static inline
317 int ust_app_disable_event_glb(struct ltt_ust_session *usess,
318 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
319 {
320 return 0;
321 }
322 static inline
323 int ust_app_enable_event_glb(struct ltt_ust_session *usess,
324 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
325 {
326 return 0;
327 }
328 static inline
329 int ust_app_add_ctx_channel_glb(struct ltt_ust_session *usess,
330 struct ltt_ust_channel *uchan, struct ltt_ust_context *uctx)
331 {
332 return 0;
333 }
334 static inline
335 int ust_app_enable_event_pid(struct ltt_ust_session *usess,
336 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
337 pid_t pid)
338 {
339 return 0;
340 }
341 static inline
342 int ust_app_disable_event_pid(struct ltt_ust_session *usess,
343 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent,
344 pid_t pid)
345 {
346 return 0;
347 }
348 static inline
349 int ust_app_validate_version(int sock)
350 {
351 return 0;
352 }
353 static inline
354 int ust_app_calibrate_glb(struct lttng_ust_calibrate *calibrate)
355 {
356 return 0;
357 }
358
359 #endif /* HAVE_LIBLTTNG_UST_CTL */
360
361 #endif /* _LTT_UST_APP_H */
This page took 0.036896 seconds and 4 git commands to generate.