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 "hashtable.h"
34 #include "kernel-ctl.h"
39 * Return allocated channel attributes.
41 struct lttng_channel
*channel_new_default_attr(int dom
)
43 struct lttng_channel
*chan
;
45 chan
= zmalloc(sizeof(struct lttng_channel
));
47 perror("malloc channel init");
51 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
52 DEFAULT_CHANNEL_NAME
) < 0) {
53 perror("snprintf default channel name");
57 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
58 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
59 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
62 case LTTNG_DOMAIN_KERNEL
:
63 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
64 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
65 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
67 case LTTNG_DOMAIN_UST
:
68 case LTTNG_DOMAIN_UST_PID
:
69 chan
->attr
.subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
70 chan
->attr
.num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
71 chan
->attr
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
74 goto error
; /* Not implemented */
86 * Copy two ltt ust channel. Dst and src must be already allocated.
88 int channel_ust_copy(struct ltt_ust_channel
*dst
,
89 struct ltt_ust_channel
*src
)
91 //struct ltt_ust_event *uevent, *new_uevent;
93 memcpy(dst
, src
, sizeof(struct ltt_ust_channel
));
94 dst
->events
= hashtable_new_str(0);
97 cds_list_for_each_entry(uevent, &src->events.head, list) {
98 new_uevent = malloc(sizeof(struct ltt_ust_event));
99 if (new_uevent == NULL) {
100 perror("malloc ltt_ust_event");
104 memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
105 cds_list_add(&new_uevent->list, &dst->events.head);
117 * Disable kernel channel of the kernel session.
119 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
123 struct ltt_kernel_channel
*kchan
;
125 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
127 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
129 } else if (kchan
->enabled
== 1) {
130 ret
= kernel_disable_channel(kchan
);
133 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
146 * Enable kernel channel of the kernel session.
148 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
149 struct ltt_kernel_channel
*kchan
)
153 if (kchan
->enabled
== 0) {
154 ret
= kernel_enable_channel(kchan
);
156 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
168 * Create kernel channel of the kernel session and notify kernel thread.
170 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
171 struct lttng_channel
*chan
, int kernel_pipe
)
174 struct lttng_channel
*attr
= chan
;
176 /* Creating channel attributes if needed */
178 /* FIXME: this appears to be a memory leak */
179 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
);
186 /* Channel not found, creating it */
187 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
189 ret
= LTTCOMM_KERN_CHAN_FAIL
;
193 /* Notify kernel thread that there is a new channel */
194 ret
= notify_thread_pipe(kernel_pipe
);
207 * Create UST channel and enable it on the tracer.
209 int channel_ust_create(struct ltt_ust_session
*usess
,
210 struct lttng_channel
*attr
)
213 struct ltt_ust_channel
*uchan
;
214 //struct lttng_ust_channel_attr uattr;
215 //struct object_data *obj;
217 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
220 uchan
= trace_ust_create_channel(attr
, usess
->pathname
);
222 ret
= LTTCOMM_UST_CHAN_FAIL
;
226 hashtable_add_unique(usess
->domain_global
.channels
, &uchan
->node
);
229 ret
= LTTCOMM_UST_CHAN_EXIST
;
233 /* TODO: NOTIFY ust application to update */
235 ret = ustctl_create_channel(sock, usession->handle, &uattr, &obj);
237 ret = LTTCOMM_UST_CHAN_FAIL;
243 uchan->attr.overwrite = uattr.overwrite;
244 uchan->attr.subbuf_size = uattr.subbuf_size;
245 uchan->attr.num_subbuf = uattr.num_subbuf;
246 uchan->attr.switch_timer_interval = uattr.switch_timer_interval;
247 uchan->attr.read_timer_interval = uattr.read_timer_interval;
248 uchan->attr.output = uattr.output;
249 uchan->handle = obj->handle;
250 uchan->attr.shm_fd = obj->shm_fd;
251 uchan->attr.wait_fd = obj->wait_fd;
252 uchan->attr.memory_map_size = obj->memory_map_size;
256 /* Add channel to session */
258 //cds_list_add(&uchan->list, &usession->channels.head);
259 //usession->channels.count++;
262 //DBG2("Channel %s UST create successfully for sock:%d", uchan->name, sock);
271 * Enable UST channel on the tracer.
273 int channel_ust_enable(struct ltt_ust_session
*usession
,
274 struct ltt_ust_channel
*uchan
, int sock
)
276 int ret
= LTTCOMM_OK
;
278 struct object_data obj
;
280 obj
.shm_fd
= uchan
->attr
.shm_fd
;
281 obj
.wait_fd
= uchan
->attr
.wait_fd
;
282 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
283 ret
= ustctl_enable(sock
, &obj
);
285 ret
= LTTCOMM_UST_CHAN_FAIL
;
295 * Disable UST channel on the tracer.
297 int channel_ust_disable(struct ltt_ust_session
*usession
,
298 struct ltt_ust_channel
*uchan
, int sock
)
300 int ret
= LTTCOMM_OK
;
302 struct object_data obj
;
304 obj
.shm_fd
= uchan
->attr
.shm_fd
;
305 obj
.wait_fd
= uchan
->attr
.wait_fd
;
306 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
307 ret
= ustctl_disable(sock
, &obj
);
309 ret
= LTTCOMM_UST_CHAN_FAIL
;