2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <lttng/lttng.h>
22 #include <lttng-sessiond-comm.h>
24 #ifdef CONFIG_LTTNG_TOOLS_HAVE_UST
25 #include <ust/lttng-ust-ctl.h>
26 #include <ust/lttng-ust-abi.h>
28 #include "lttng-ust-ctl.h"
29 #include "lttng-ust-abi.h"
33 #include "kernel-ctl.h"
38 * Return allocated channel attributes.
40 struct lttng_channel
*channel_new_default_attr(int dom
)
42 struct lttng_channel
*chan
;
44 chan
= zmalloc(sizeof(struct lttng_channel
));
46 perror("malloc channel init");
50 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
51 DEFAULT_CHANNEL_NAME
) < 0) {
52 perror("snprintf default channel name");
56 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
57 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
58 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
61 case LTTNG_DOMAIN_KERNEL
:
62 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
63 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
64 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
66 case LTTNG_DOMAIN_UST
:
67 case LTTNG_DOMAIN_UST_PID
:
68 chan
->attr
.subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
69 chan
->attr
.num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
70 chan
->attr
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
73 goto error
; /* Not implemented */
85 * Copy two ltt ust channel. Dst and src must be already allocated.
87 int channel_ust_copy(struct ltt_ust_channel
*dst
,
88 struct ltt_ust_channel
*src
)
90 struct ltt_ust_event
*uevent
, *new_uevent
;
92 memcpy(dst
, src
, sizeof(struct ltt_ust_channel
));
93 CDS_INIT_LIST_HEAD(&dst
->events
.head
);
95 cds_list_for_each_entry(uevent
, &src
->events
.head
, list
) {
96 new_uevent
= malloc(sizeof(struct ltt_ust_event
));
97 if (new_uevent
== NULL
) {
98 perror("malloc ltt_ust_event");
102 memcpy(new_uevent
, uevent
, sizeof(struct ltt_ust_event
));
103 cds_list_add(&new_uevent
->list
, &dst
->events
.head
);
114 * Disable kernel channel of the kernel session.
116 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
120 struct ltt_kernel_channel
*kchan
;
122 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
124 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
126 } else if (kchan
->enabled
== 1) {
127 ret
= kernel_disable_channel(kchan
);
130 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
143 * Enable kernel channel of the kernel session.
145 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
146 struct ltt_kernel_channel
*kchan
)
150 if (kchan
->enabled
== 0) {
151 ret
= kernel_enable_channel(kchan
);
153 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
165 * Create kernel channel of the kernel session and notify kernel thread.
167 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
168 struct lttng_channel
*chan
, int kernel_pipe
)
171 struct lttng_channel
*attr
= chan
;
173 /* Creating channel attributes if needed */
175 /* FIXME: this appears to be a memory leak */
176 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
);
183 /* Channel not found, creating it */
184 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
186 ret
= LTTCOMM_KERN_CHAN_FAIL
;
190 /* Notify kernel thread that there is a new channel */
191 ret
= notify_thread_pipe(kernel_pipe
);
204 * Create UST channel and enable it on the tracer.
206 int channel_ust_create(struct ltt_ust_session
*usession
,
207 struct lttng_channel
*chan
, int sock
)
210 struct lttng_channel
*attr
= chan
;
211 struct ltt_ust_channel
*suchan
;
212 struct lttng_ust_channel_attr uattr
;
213 struct object_data
*obj
;
215 /* Creating channel attributes if needed */
217 /* FIXME: this appears to be a memory leak */
218 /* TODO: get default for other UST domains */
219 attr
= channel_new_default_attr(LTTNG_DOMAIN_UST
);
226 suchan
= trace_ust_create_channel(attr
, usession
->path
);
227 if (suchan
== NULL
) {
231 uattr
.overwrite
= attr
->attr
.overwrite
;
232 uattr
.subbuf_size
= attr
->attr
.subbuf_size
;
233 uattr
.num_subbuf
= attr
->attr
.num_subbuf
;
234 uattr
.switch_timer_interval
= attr
->attr
.switch_timer_interval
;
235 uattr
.read_timer_interval
= attr
->attr
.read_timer_interval
;
236 uattr
.output
= attr
->attr
.output
;
237 ret
= ustctl_create_channel(sock
, usession
->handle
,
240 ret
= LTTCOMM_UST_CHAN_FAIL
;
243 suchan
->attr
.overwrite
= uattr
.overwrite
;
244 suchan
->attr
.subbuf_size
= uattr
.subbuf_size
;
245 suchan
->attr
.num_subbuf
= uattr
.num_subbuf
;
246 suchan
->attr
.switch_timer_interval
= uattr
.switch_timer_interval
;
247 suchan
->attr
.read_timer_interval
= uattr
.read_timer_interval
;
248 suchan
->attr
.output
= uattr
.output
;
249 suchan
->handle
= obj
->handle
;
250 suchan
->attr
.shm_fd
= obj
->shm_fd
;
251 suchan
->attr
.wait_fd
= obj
->wait_fd
;
252 suchan
->attr
.memory_map_size
= obj
->memory_map_size
;
255 /* Add channel to session */
256 cds_list_add(&suchan
->list
, &usession
->channels
.head
);
257 usession
->channels
.count
++;
259 DBG2("Channel %s UST create successfully for sock:%d", suchan
->name
, sock
);
268 * Enable UST channel on the tracer.
270 int channel_ust_enable(struct ltt_ust_session
*usession
,
271 struct ltt_ust_channel
*uchan
, int sock
)
273 int ret
= LTTCOMM_OK
;
274 struct object_data obj
;
276 obj
.handle
= uchan
->handle
;
277 obj
.shm_fd
= uchan
->attr
.shm_fd
;
278 obj
.wait_fd
= uchan
->attr
.wait_fd
;
279 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
280 ret
= ustctl_enable(sock
, &obj
);
282 ret
= LTTCOMM_UST_CHAN_FAIL
;
291 * Disable UST channel on the tracer.
293 int channel_ust_disable(struct ltt_ust_session
*usession
,
294 struct ltt_ust_channel
*uchan
, int sock
)
296 int ret
= LTTCOMM_OK
;
297 struct object_data obj
;
299 obj
.handle
= uchan
->handle
;
300 obj
.shm_fd
= uchan
->attr
.shm_fd
;
301 obj
.wait_fd
= uchan
->attr
.wait_fd
;
302 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
303 ret
= ustctl_disable(sock
, &obj
);
305 ret
= LTTCOMM_UST_CHAN_FAIL
;