2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
18 #ifndef _LTT_UST_APP_H
19 #define _LTT_UST_APP_H
23 #include <common/compat/uuid.h>
24 #include "trace-ust.h"
25 #include "ust-registry.h"
27 /* lttng-ust supported version. */
28 //#define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
29 //#define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
31 #define UST_APP_EVENT_LIST_SIZE 32
33 /* Process name (short). Extra for the NULL byte. */
34 #define UST_APP_PROCNAME_LEN 17
36 struct lttng_filter_bytecode
;
37 struct lttng_ust_filter_bytecode
;
39 extern int ust_consumerd64_fd
, ust_consumerd32_fd
;
41 struct ust_app_ht_key
{
43 const struct lttng_ust_filter_bytecode
*filter
;
44 enum lttng_ust_loglevel_type loglevel
;
48 * Application registration data structure.
50 struct ust_register_msg
{
51 enum ustctl_socket_type type
;
60 uint32_t bits_per_long
;
61 uint32_t uint8_t_alignment
;
62 uint32_t uint16_t_alignment
;
63 uint32_t uint32_t_alignment
;
64 uint32_t uint64_t_alignment
;
65 uint32_t long_alignment
;
66 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
67 char name
[LTTNG_UST_ABI_PROCNAME_LEN
];
71 * Global applications HT used by the session daemon. This table is indexed by
72 * PID using the pid_n node and pid value of an ust_app.
74 struct lttng_ht
*ust_app_ht
;
77 * Global applications HT used by the session daemon. This table is indexed by
78 * socket using the sock_n node and sock value of an ust_app.
80 struct lttng_ht
*ust_app_ht_by_sock
;
83 * Global applications HT used by the session daemon. This table is indexed by
84 * socket using the notify_sock_n node and notify_sock value of an ust_app.
86 struct lttng_ht
*ust_app_ht_by_notify_sock
;
88 /* Stream list containing ust_app_stream. */
89 struct ust_app_stream_list
{
91 struct cds_list_head head
;
96 struct lttng_ust_context ctx
;
97 struct lttng_ust_object_data
*obj
;
98 struct lttng_ht_node_ulong node
;
101 struct ust_app_event
{
104 struct lttng_ust_object_data
*obj
;
105 struct lttng_ust_event attr
;
106 char name
[LTTNG_UST_SYM_NAME_LEN
];
107 struct lttng_ht_node_str node
;
108 struct lttng_ust_filter_bytecode
*filter
;
111 struct ust_app_stream
{
113 char pathname
[PATH_MAX
];
114 /* Format is %s_%d respectively channel name and CPU number. */
115 char name
[DEFAULT_STREAM_NAME_LEN
];
116 struct lttng_ust_object_data
*obj
;
117 /* Using a list of streams to keep order. */
118 struct cds_list_head list
;
121 struct ust_app_channel
{
124 /* Channel and streams were sent to the UST tracer. */
126 /* Unique key used to identify the channel on the consumer side. */
128 /* Number of stream that this channel is expected to receive. */
129 unsigned int expected_stream_count
;
130 char name
[LTTNG_UST_SYM_NAME_LEN
];
131 struct lttng_ust_object_data
*obj
;
132 struct ustctl_consumer_channel_attr attr
;
133 struct ust_app_stream_list streams
;
134 /* Session pointer that owns this object. */
135 struct ust_app_session
*session
;
136 struct lttng_ht
*ctx
;
137 struct lttng_ht
*events
;
139 * UST event registry. The ONLY writer is the application thread.
141 struct ust_registry_channel registry
;
143 * Node indexed by channel name in the channels' hash table of a session.
145 struct lttng_ht_node_str node
;
147 * Node indexed by UST channel object descriptor (handle). Stored in the
148 * ust_objd hash table in the ust_app object.
150 struct lttng_ht_node_ulong ust_objd_node
;
153 struct ust_app_session
{
155 * Lock protecting this session's ust app interaction. Held
156 * across command send/recv to/from app. Never nests within the
157 * session registry lock.
159 pthread_mutex_t lock
;
162 /* started: has the session been in started state at any time ? */
163 int started
; /* allows detection of start vs restart. */
164 int handle
; /* used has unique identifier for app session */
165 int id
; /* session unique identifier */
166 struct ust_app_channel
*metadata
;
167 struct ust_registry_session registry
;
168 struct lttng_ht
*channels
; /* Registered channels */
169 struct lttng_ht_node_ulong node
;
171 /* UID/GID of the user owning the session */
174 struct cds_list_head teardown_node
;
178 * Registered traceable applications. Libust registers to the session daemon
179 * and a linked list is kept of all running traceable app.
186 uid_t uid
; /* User ID that owns the apps */
187 gid_t gid
; /* Group ID that owns the apps */
190 uint32_t bits_per_long
;
191 uint32_t uint8_t_alignment
;
192 uint32_t uint16_t_alignment
;
193 uint32_t uint32_t_alignment
;
194 uint32_t uint64_t_alignment
;
195 uint32_t long_alignment
;
196 int byte_order
; /* BIG_ENDIAN or LITTLE_ENDIAN */
198 int compatible
; /* If the lttng-ust tracer version does not match the
199 supported version of the session daemon, this flag is
200 set to 0 (NOT compatible) else 1. */
201 struct lttng_ust_tracer_version version
;
202 uint32_t v_major
; /* Version major number */
203 uint32_t v_minor
; /* Version minor number */
204 char name
[UST_APP_PROCNAME_LEN
];
205 struct lttng_ht
*sessions
;
206 struct lttng_ht_node_ulong pid_n
;
207 struct lttng_ht_node_ulong sock_n
;
208 struct lttng_ht_node_ulong notify_sock_n
;
210 * This is a list of ust app session that, once the app is going into
211 * teardown mode, in the RCU call, each node in this list is removed and
214 * Element of the list are added when an application unregisters after each
215 * ht_del of ust_app_session associated to this app. This list is NOT used
216 * when a session is destroyed.
218 struct cds_list_head teardown_head
;
220 * Hash table containing ust_app_channel indexed by channel objd.
222 struct lttng_ht
*ust_objd
;
225 #ifdef HAVE_LIBLTTNG_UST_CTL
227 int ust_app_register(struct ust_register_msg
*msg
, int sock
);
229 int ust_app_register_done(int sock
)
231 return ustctl_register_done(sock
);
233 int ust_app_version(struct ust_app
*app
);
234 void ust_app_unregister(int sock
);
235 unsigned long ust_app_list_count(void);
236 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
);
237 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
);
238 int ust_app_start_trace_all(struct ltt_ust_session
*usess
);
239 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
);
240 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
);
241 int ust_app_list_events(struct lttng_event
**events
);
242 int ust_app_list_event_fields(struct lttng_event_field
**fields
);
243 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
244 struct ltt_ust_channel
*uchan
);
245 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
246 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
247 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
248 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
250 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
251 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
253 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
254 struct ltt_ust_channel
*uchan
);
255 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
256 struct ltt_ust_channel
*uchan
);
257 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
258 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
259 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
260 struct ltt_ust_channel
*uchan
);
261 int ust_app_enable_all_event_glb(struct ltt_ust_session
*usess
,
262 struct ltt_ust_channel
*uchan
);
263 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
264 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
265 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
266 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
);
267 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
);
269 void ust_app_clean_list(void);
270 void ust_app_ht_alloc(void);
271 struct lttng_ht
*ust_app_get_ht(void);
272 struct ust_app
*ust_app_find_by_pid(pid_t pid
);
273 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
);
274 struct ust_app_stream
*ust_app_alloc_stream(void);
275 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
);
276 int ust_app_recv_notify(int sock
);
277 void ust_app_add(struct ust_app
*app
);
278 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
);
280 #else /* HAVE_LIBLTTNG_UST_CTL */
283 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
288 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
293 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
298 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
303 int ust_app_list_events(struct lttng_event
**events
)
308 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
313 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
318 int ust_app_register_done(int sock
)
323 int ust_app_version(struct ust_app
*app
)
328 void ust_app_unregister(int sock
)
332 unsigned int ust_app_list_count(void)
337 void ust_app_lock_list(void)
341 void ust_app_unlock_list(void)
345 void ust_app_clean_list(void)
349 struct ust_app_list
*ust_app_get_list(void)
354 struct ust_app
*ust_app_get_by_pid(pid_t pid
)
359 struct lttng_ht
*ust_app_get_ht(void)
364 void ust_app_ht_alloc(void)
367 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
370 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
371 struct ltt_ust_channel
*uchan
)
376 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
377 struct ltt_ust_channel
*uchan
)
382 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
383 struct ltt_ust_channel
*uchan
)
388 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
389 struct ltt_ust_channel
*uchan
)
394 int ust_app_enable_all_event_glb(struct ltt_ust_session
*usess
,
395 struct ltt_ust_channel
*uchan
)
400 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
401 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
406 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
407 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
412 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
413 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
418 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
419 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
424 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
425 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
431 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
432 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
438 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
443 int ust_app_recv_registration(int sock
, struct ust_register_msg
*msg
)
448 int ust_app_recv_notify(int sock
)
453 struct ust_app
*ust_app_create(struct ust_register_msg
*msg
, int sock
)
458 void ust_app_add(struct ust_app
*app
)
462 #endif /* HAVE_LIBLTTNG_UST_CTL */
464 #endif /* _LTT_UST_APP_H */