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"
26 /* lttng-ust supported version. */
27 #define LTTNG_UST_COMM_MAJOR 2 /* comm protocol major version */
28 #define UST_APP_MAJOR_VERSION 3 /* Internal UST version supported */
30 #define UST_APP_EVENT_LIST_SIZE 32
32 struct lttng_filter_bytecode
;
33 struct lttng_ust_filter_bytecode
;
35 extern int ust_consumerd64_fd
, ust_consumerd32_fd
;
37 struct ust_app_ht_key
{
39 const struct lttng_ust_filter_bytecode
*filter
;
40 enum lttng_ust_loglevel_type loglevel
;
44 * Application registration data structure.
46 struct ust_register_msg
{
53 uint32_t bits_per_long
;
58 * Global applications HT used by the session daemon. This table is indexed by
59 * PID using the pid_n node and pid value of an ust_app.
61 struct lttng_ht
*ust_app_ht
;
64 * Global applications HT used by the session daemon. This table is indexed by
65 * socket using the sock_n node and sock value of an ust_app.
67 struct lttng_ht
*ust_app_ht_by_sock
;
69 /* Stream list containing ust_app_stream. */
70 struct ust_app_stream_list
{
72 struct cds_list_head head
;
77 struct lttng_ust_context ctx
;
78 struct lttng_ust_object_data
*obj
;
79 struct lttng_ht_node_ulong node
;
82 struct ust_app_event
{
85 struct lttng_ust_object_data
*obj
;
86 struct lttng_ust_event attr
;
87 char name
[LTTNG_UST_SYM_NAME_LEN
];
88 struct lttng_ht_node_str node
;
89 struct lttng_ust_filter_bytecode
*filter
;
92 struct ust_app_stream
{
94 char pathname
[PATH_MAX
];
95 /* Format is %s_%d respectively channel name and CPU number. */
96 char name
[DEFAULT_STREAM_NAME_LEN
];
97 struct lttng_ust_object_data
*obj
;
98 /* Using a list of streams to keep order. */
99 struct cds_list_head list
;
100 struct ustctl_consumer_stream
*ustream
;
103 struct ust_app_channel
{
106 /* Channel and streams were sent to the UST tracer. */
108 /* Unique key used to identify the channel on the consumer side. */
110 /* Number of stream that this channel is expected to receive. */
111 unsigned int expected_stream_count
;
112 char name
[LTTNG_UST_SYM_NAME_LEN
];
113 struct lttng_ust_object_data
*obj
;
114 struct ustctl_consumer_channel_attr attr
;
115 struct ustctl_consumer_channel
*channel
;
116 struct ust_app_stream_list streams
;
117 struct lttng_ht
*ctx
;
118 struct lttng_ht
*events
;
119 struct lttng_ht_node_str node
;
122 struct ust_app_session
{
124 /* started: has the session been in started state at any time ? */
125 int started
; /* allows detection of start vs restart. */
126 int handle
; /* used has unique identifier for app session */
127 int id
; /* session unique identifier */
128 struct ust_app_channel
*metadata
;
129 struct lttng_ht
*channels
; /* Registered channels */
130 struct lttng_ht_node_ulong node
;
132 /* UID/GID of the user owning the session */
135 struct cds_list_head teardown_node
;
136 /* Universal unique identifier used by the tracer. */
137 unsigned char uuid
[UUID_STR_LEN
];
141 * Registered traceable applications. Libust registers to the session daemon
142 * and a linked list is kept of all running traceable app.
148 uid_t uid
; /* User ID that owns the apps */
149 gid_t gid
; /* Group ID that owns the apps */
151 int compatible
; /* If the lttng-ust tracer version does not match the
152 supported version of the session daemon, this flag is
153 set to 0 (NOT compatible) else 1. */
154 struct lttng_ust_tracer_version version
;
155 uint32_t v_major
; /* Verion major number */
156 uint32_t v_minor
; /* Verion minor number */
157 char name
[17]; /* Process name (short) */
158 struct lttng_ht
*sessions
;
159 struct lttng_ht_node_ulong pid_n
;
160 struct lttng_ht_node_ulong sock_n
;
162 * This is a list of ust app session that, once the app is going into
163 * teardown mode, in the RCU call, each node in this list is removed and
166 * Element of the list are added when an application unregisters after each
167 * ht_del of ust_app_session associated to this app. This list is NOT used
168 * when a session is destroyed.
170 struct cds_list_head teardown_head
;
173 #ifdef HAVE_LIBLTTNG_UST_CTL
175 int ust_app_register(struct ust_register_msg
*msg
, int sock
);
177 int ust_app_register_done(int sock
)
179 return ustctl_register_done(sock
);
181 void ust_app_unregister(int sock
);
182 unsigned long ust_app_list_count(void);
183 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
);
184 int ust_app_stop_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
);
185 int ust_app_start_trace_all(struct ltt_ust_session
*usess
);
186 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
);
187 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
);
188 int ust_app_list_events(struct lttng_event
**events
);
189 int ust_app_list_event_fields(struct lttng_event_field
**fields
);
190 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
191 struct ltt_ust_channel
*uchan
);
192 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
193 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
194 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
195 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
197 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
198 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
200 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
201 struct ltt_ust_channel
*uchan
);
202 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
203 struct ltt_ust_channel
*uchan
);
204 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
205 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
206 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
207 struct ltt_ust_channel
*uchan
);
208 int ust_app_enable_all_event_glb(struct ltt_ust_session
*usess
,
209 struct ltt_ust_channel
*uchan
);
210 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
211 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
);
212 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
213 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
);
214 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
);
216 void ust_app_clean_list(void);
217 void ust_app_ht_alloc(void);
218 struct lttng_ht
*ust_app_get_ht(void);
219 struct ust_app
*ust_app_find_by_pid(pid_t pid
);
220 int ust_app_validate_version(int sock
);
221 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
);
222 struct ust_app_stream
*ust_app_alloc_stream(void);
224 #else /* HAVE_LIBLTTNG_UST_CTL */
227 int ust_app_destroy_trace_all(struct ltt_ust_session
*usess
)
232 int ust_app_start_trace(struct ltt_ust_session
*usess
, struct ust_app
*app
)
237 int ust_app_start_trace_all(struct ltt_ust_session
*usess
)
242 int ust_app_stop_trace_all(struct ltt_ust_session
*usess
)
247 int ust_app_list_events(struct lttng_event
**events
)
252 int ust_app_list_event_fields(struct lttng_event_field
**fields
)
257 int ust_app_register(struct ust_register_msg
*msg
, int sock
)
262 int ust_app_register_done(int sock
)
267 void ust_app_unregister(int sock
)
271 unsigned int ust_app_list_count(void)
276 void ust_app_lock_list(void)
280 void ust_app_unlock_list(void)
284 void ust_app_clean_list(void)
288 struct ust_app_list
*ust_app_get_list(void)
293 struct ust_app
*ust_app_get_by_pid(pid_t pid
)
298 struct lttng_ht
*ust_app_get_ht(void)
303 void ust_app_ht_alloc(void)
306 void ust_app_global_update(struct ltt_ust_session
*usess
, int sock
)
309 int ust_app_disable_channel_glb(struct ltt_ust_session
*usess
,
310 struct ltt_ust_channel
*uchan
)
315 int ust_app_enable_channel_glb(struct ltt_ust_session
*usess
,
316 struct ltt_ust_channel
*uchan
)
321 int ust_app_create_channel_glb(struct ltt_ust_session
*usess
,
322 struct ltt_ust_channel
*uchan
)
327 int ust_app_disable_all_event_glb(struct ltt_ust_session
*usess
,
328 struct ltt_ust_channel
*uchan
)
333 int ust_app_enable_all_event_glb(struct ltt_ust_session
*usess
,
334 struct ltt_ust_channel
*uchan
)
339 int ust_app_create_event_glb(struct ltt_ust_session
*usess
,
340 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
345 int ust_app_disable_event_glb(struct ltt_ust_session
*usess
,
346 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
351 int ust_app_enable_event_glb(struct ltt_ust_session
*usess
,
352 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
357 int ust_app_add_ctx_channel_glb(struct ltt_ust_session
*usess
,
358 struct ltt_ust_channel
*uchan
, struct ltt_ust_context
*uctx
)
363 int ust_app_enable_event_pid(struct ltt_ust_session
*usess
,
364 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
370 int ust_app_disable_event_pid(struct ltt_ust_session
*usess
,
371 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
377 int ust_app_validate_version(int sock
)
382 int ust_app_calibrate_glb(struct lttng_ust_calibrate
*calibrate
)
387 #endif /* HAVE_LIBLTTNG_UST_CTL */
389 #endif /* _LTT_UST_APP_H */