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>
26 #include "hashtable.h"
27 #include "kernel-ctl.h"
32 * Return allocated channel attributes.
34 struct lttng_channel
*channel_new_default_attr(int dom
)
36 struct lttng_channel
*chan
;
38 chan
= zmalloc(sizeof(struct lttng_channel
));
40 perror("malloc channel init");
44 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
45 DEFAULT_CHANNEL_NAME
) < 0) {
46 perror("snprintf default channel name");
50 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
51 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
52 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
55 case LTTNG_DOMAIN_KERNEL
:
56 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
57 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
58 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
60 case LTTNG_DOMAIN_UST
:
61 case LTTNG_DOMAIN_UST_PID
:
62 chan
->attr
.subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
63 chan
->attr
.num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
64 chan
->attr
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
67 goto error
; /* Not implemented */
79 * Copy two ltt ust channel. Dst and src must be already allocated.
81 int channel_ust_copy(struct ltt_ust_channel
*dst
,
82 struct ltt_ust_channel
*src
)
84 //struct ltt_ust_event *uevent, *new_uevent;
86 memcpy(dst
, src
, sizeof(struct ltt_ust_channel
));
87 dst
->events
= hashtable_new_str(0);
90 cds_list_for_each_entry(uevent, &src->events.head, list) {
91 new_uevent = malloc(sizeof(struct ltt_ust_event));
92 if (new_uevent == NULL) {
93 perror("malloc ltt_ust_event");
97 memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
98 cds_list_add(&new_uevent->list, &dst->events.head);
110 * Disable kernel channel of the kernel session.
112 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
116 struct ltt_kernel_channel
*kchan
;
118 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
120 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
122 } else if (kchan
->enabled
== 1) {
123 ret
= kernel_disable_channel(kchan
);
126 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
139 * Enable kernel channel of the kernel session.
141 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
142 struct ltt_kernel_channel
*kchan
)
146 if (kchan
->enabled
== 0) {
147 ret
= kernel_enable_channel(kchan
);
149 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
161 * Create kernel channel of the kernel session and notify kernel thread.
163 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
164 struct lttng_channel
*chan
, int kernel_pipe
)
167 struct lttng_channel
*attr
= chan
;
169 /* Creating channel attributes if needed */
171 /* FIXME: this appears to be a memory leak */
172 attr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
);
179 /* Channel not found, creating it */
180 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
182 ret
= LTTCOMM_KERN_CHAN_FAIL
;
186 /* Notify kernel thread that there is a new channel */
187 ret
= notify_thread_pipe(kernel_pipe
);
200 * Create UST channel and enable it on the tracer.
202 int channel_ust_create(struct ltt_ust_session
*usess
,
203 struct lttng_channel
*attr
)
206 struct ltt_ust_channel
*uchan
;
207 //struct lttng_ust_channel_attr uattr;
208 //struct object_data *obj;
210 uchan
= trace_ust_find_channel_by_name(usess
->domain_global
.channels
,
213 uchan
= trace_ust_create_channel(attr
, usess
->pathname
);
215 ret
= LTTCOMM_UST_CHAN_FAIL
;
219 hashtable_add_unique(usess
->domain_global
.channels
, &uchan
->node
);
222 ret
= LTTCOMM_UST_CHAN_EXIST
;
226 /* TODO: NOTIFY ust application to update */
228 ret = ustctl_create_channel(sock, usession->handle, &uattr, &obj);
230 ret = LTTCOMM_UST_CHAN_FAIL;
236 uchan->attr.overwrite = uattr.overwrite;
237 uchan->attr.subbuf_size = uattr.subbuf_size;
238 uchan->attr.num_subbuf = uattr.num_subbuf;
239 uchan->attr.switch_timer_interval = uattr.switch_timer_interval;
240 uchan->attr.read_timer_interval = uattr.read_timer_interval;
241 uchan->attr.output = uattr.output;
242 uchan->handle = obj->handle;
243 uchan->attr.shm_fd = obj->shm_fd;
244 uchan->attr.wait_fd = obj->wait_fd;
245 uchan->attr.memory_map_size = obj->memory_map_size;
249 /* Add channel to session */
251 //cds_list_add(&uchan->list, &usession->channels.head);
252 //usession->channels.count++;
255 //DBG2("Channel %s UST create successfully for sock:%d", uchan->name, sock);
264 * Enable UST channel on the tracer.
266 int channel_ust_enable(struct ltt_ust_session
*usession
,
267 struct ltt_ust_channel
*uchan
, int sock
)
269 int ret
= LTTCOMM_OK
;
271 struct object_data obj
;
273 obj
.shm_fd
= uchan
->attr
.shm_fd
;
274 obj
.wait_fd
= uchan
->attr
.wait_fd
;
275 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
276 ret
= ustctl_enable(sock
, &obj
);
278 ret
= LTTCOMM_UST_CHAN_FAIL
;
288 * Disable UST channel on the tracer.
290 int channel_ust_disable(struct ltt_ust_session
*usession
,
291 struct ltt_ust_channel
*uchan
, int sock
)
293 int ret
= LTTCOMM_OK
;
295 struct object_data obj
;
297 obj
.shm_fd
= uchan
->attr
.shm_fd
;
298 obj
.wait_fd
= uchan
->attr
.wait_fd
;
299 obj
.memory_map_size
= uchan
->attr
.memory_map_size
;
300 ret
= ustctl_disable(sock
, &obj
);
302 ret
= LTTCOMM_UST_CHAN_FAIL
;