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 "kernel-ctl.h"
31 * Return allocated channel attributes.
33 static struct lttng_channel
*init_default_attr(int dom
)
35 struct lttng_channel
*chan
;
37 chan
= zmalloc(sizeof(struct lttng_channel
));
39 perror("malloc channel init");
43 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
44 DEFAULT_CHANNEL_NAME
) < 0) {
45 perror("snprintf default channel name");
49 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
50 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
51 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
54 case LTTNG_DOMAIN_KERNEL
:
55 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
56 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
57 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
59 case LTTNG_DOMAIN_UST_PID
:
60 chan
->attr
.subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
61 chan
->attr
.num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
62 chan
->attr
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
65 goto error
; /* Not implemented */
77 * Copy two ltt ust channel. Dst and src must be already allocated.
79 int channel_ust_copy(struct ltt_ust_channel
*dst
,
80 struct ltt_ust_channel
*src
)
82 struct ltt_ust_event
*uevent
, *new_uevent
;
84 memcpy(dst
, src
, sizeof(struct ltt_ust_channel
));
85 CDS_INIT_LIST_HEAD(&dst
->events
.head
);
87 cds_list_for_each_entry(uevent
, &src
->events
.head
, list
) {
88 new_uevent
= malloc(sizeof(struct ltt_ust_event
));
89 if (new_uevent
== NULL
) {
90 perror("malloc ltt_ust_event");
94 memcpy(new_uevent
, uevent
, sizeof(struct ltt_ust_event
));
95 cds_list_add(&new_uevent
->list
, &dst
->events
.head
);
106 * Disable kernel channel of the kernel session.
108 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
112 struct ltt_kernel_channel
*kchan
;
114 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
116 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
118 } else if (kchan
->enabled
== 1) {
119 ret
= kernel_disable_channel(kchan
);
122 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
135 * Enable kernel channel of the kernel session.
137 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
138 struct ltt_kernel_channel
*kchan
)
142 if (kchan
->enabled
== 0) {
143 ret
= kernel_enable_channel(kchan
);
145 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
157 * Create kernel channel of the kernel session and notify kernel thread.
159 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
160 struct lttng_channel
*chan
, int kernel_pipe
)
163 struct lttng_channel
*attr
= chan
;
165 /* Creating channel attributes if needed */
167 attr
= init_default_attr(LTTNG_DOMAIN_KERNEL
);
174 /* Channel not found, creating it */
175 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
177 ret
= LTTCOMM_KERN_CHAN_FAIL
;
181 /* Notify kernel thread that there is a new channel */
182 ret
= notify_thread_pipe(kernel_pipe
);
195 * Create UST channel and enable it on the tracer.
197 int channel_ust_create(struct ltt_ust_session
*usession
,
198 struct lttng_channel
*chan
, int sock
)
201 struct lttng_channel
*attr
= chan
;
203 /* Creating channel attributes if needed */
205 attr
= init_default_attr(LTTNG_DOMAIN_UST_PID
);
212 ret
= ustctl_create_channel(sock
, usession
, attr
);
214 ret
= LTTCOMM_UST_CHAN_FAIL
;
218 DBG2("Channel %s UST create successfully for sock:%d", attr
->name
, sock
);
227 * Enable UST channel on the tracer.
229 int channel_ust_enable(struct ltt_ust_session
*usession
,
230 struct ltt_ust_channel
*uchan
, int sock
)
235 ret
= ustctl_enable_channel(sock
, usession
, uchan
);
237 ret
= LTTCOMM_UST_CHAN_FAIL
;
248 * Disable UST channel on the tracer.
250 int channel_ust_disable(struct ltt_ust_session
*usession
,
251 struct ltt_ust_channel
*uchan
, int sock
)
256 ret
= ustctl_disable_channel(sock
, usession
, uchan
);
258 ret
= LTTCOMM_UST_CHAN_FAIL
;