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.
19 #include <urcu/list.h>
22 #include <lttng/lttng.h>
23 #include <lttng-sessiond-comm.h>
26 #ifdef CONFIG_LTTNG_TOOLS_HAVE_UST
27 #include <ust/lttng-ust-ctl.h>
29 #include "lttng-ust-ctl.h"
34 #include "hashtable.h"
35 #include "kernel-ctl.h"
38 * Setup a lttng_event used to enable *all* syscall tracing.
40 static void init_syscalls_kernel_event(struct lttng_event
*event
)
42 event
->name
[0] = '\0';
44 * We use LTTNG_EVENT* here since the trace kernel creation will make the
45 * right changes for the kernel.
47 event
->type
= LTTNG_EVENT_SYSCALL
;
51 * Disable kernel tracepoint event for a channel from the kernel session.
53 int event_kernel_disable_tracepoint(struct ltt_kernel_session
*ksession
,
54 struct ltt_kernel_channel
*kchan
, char *event_name
)
57 struct ltt_kernel_event
*kevent
;
59 kevent
= trace_kernel_get_event_by_name(event_name
, kchan
);
61 ret
= LTTCOMM_NO_EVENT
;
65 ret
= kernel_disable_event(kevent
);
67 ret
= LTTCOMM_KERN_DISABLE_FAIL
;
71 DBG("Kernel event %s disable for channel %s.",
72 kevent
->event
->name
, kchan
->channel
->name
);
81 * Disable kernel tracepoint events for a channel from the kernel session.
83 int event_kernel_disable_all_tracepoints(struct ltt_kernel_session
*ksession
,
84 struct ltt_kernel_channel
*kchan
)
87 struct ltt_kernel_event
*kevent
;
89 /* For each event in the kernel session */
90 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
91 ret
= kernel_disable_event(kevent
);
93 /* We continue disabling the rest */
102 * Disable kernel syscall events for a channel from the kernel session.
104 int event_kernel_disable_all_syscalls(struct ltt_kernel_session
*ksession
,
105 struct ltt_kernel_channel
*kchan
)
107 ERR("Cannot disable syscall tracing for existing session. Please destroy session instead.");
108 return LTTCOMM_OK
; /* Return OK so disable all succeeds */
112 * Disable all kernel event for a channel from the kernel session.
114 int event_kernel_disable_all(struct ltt_kernel_session
*ksession
,
115 struct ltt_kernel_channel
*kchan
)
119 ret
= event_kernel_disable_all_tracepoints(ksession
, kchan
);
120 if (ret
!= LTTCOMM_OK
)
122 ret
= event_kernel_disable_all_syscalls(ksession
, kchan
);
127 * Enable kernel tracepoint event for a channel from the kernel session.
129 int event_kernel_enable_tracepoint(struct ltt_kernel_session
*ksession
,
130 struct ltt_kernel_channel
*kchan
, struct lttng_event
*event
)
133 struct ltt_kernel_event
*kevent
;
135 kevent
= trace_kernel_get_event_by_name(event
->name
, kchan
);
136 if (kevent
== NULL
) {
137 ret
= kernel_create_event(event
, kchan
);
139 if (ret
== -EEXIST
) {
140 ret
= LTTCOMM_KERN_EVENT_EXIST
;
142 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
146 } else if (kevent
->enabled
== 0) {
147 ret
= kernel_enable_event(kevent
);
149 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
159 * Enable all kernel tracepoint events of a channel of the kernel session.
161 int event_kernel_enable_all_tracepoints(struct ltt_kernel_session
*ksession
,
162 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
165 struct ltt_kernel_event
*kevent
;
166 struct lttng_event
*event_list
;
168 /* For each event in the kernel session */
169 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
170 ret
= kernel_enable_event(kevent
);
172 /* Enable failed but still continue */
177 size
= kernel_list_events(kernel_tracer_fd
, &event_list
);
179 ret
= LTTCOMM_KERN_LIST_FAIL
;
183 for (i
= 0; i
< size
; i
++) {
184 kevent
= trace_kernel_get_event_by_name(event_list
[i
].name
, kchan
);
185 if (kevent
== NULL
) {
186 /* Default event type for enable all */
187 event_list
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
188 /* Enable each single tracepoint event */
189 ret
= kernel_create_event(&event_list
[i
], kchan
);
191 /* Ignore error here and continue */
203 * Enable all kernel tracepoint events of a channel of the kernel session.
205 int event_kernel_enable_all_syscalls(struct ltt_kernel_session
*ksession
,
206 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
209 struct lttng_event event
;
211 init_syscalls_kernel_event(&event
);
213 DBG("Enabling all syscall tracing");
215 ret
= kernel_create_event(&event
, kchan
);
225 * Enable all kernel events of a channel of the kernel session.
227 int event_kernel_enable_all(struct ltt_kernel_session
*ksession
,
228 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
232 ret
= event_kernel_enable_all_tracepoints(ksession
, kchan
, kernel_tracer_fd
);
233 if (ret
!= LTTCOMM_OK
) {
236 ret
= event_kernel_enable_all_syscalls(ksession
, kchan
, kernel_tracer_fd
);
242 * Enable UST tracepoint event for a channel from a UST session.
245 int event_ust_enable_tracepoint(struct ltt_ust_session
*usess
,
246 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
249 struct lttng_ust_event ltt_uevent
;
250 struct object_data
*obj_event
;
252 strncpy(ltt_uevent
.name
, uevent
->attr
.name
, sizeof(ltt_uevent
.name
));
253 ltt_uevent
.name
[sizeof(ltt_uevent
.name
) - 1] = '\0';
254 /* TODO: adjust to other instrumentation types */
255 ltt_uevent
.instrumentation
= LTTNG_UST_TRACEPOINT
;
257 ret
= ustctl_create_event(app
->key
.sock
, <t_uevent
,
258 uchan
->obj
, &obj_event
);
260 DBG("Error ustctl create event %s for app pid: %d, sock: %d ret %d",
261 uevent
->attr
.name
, app
->key
.pid
, app
->key
.sock
, ret
);
265 uevent
->obj
= obj_event
;
266 uevent
->handle
= obj_event
->handle
;
275 int event_ust_disable_tracepoint(struct ltt_ust_session
*ustsession
,
276 struct ltt_ust_channel
*ustchan
, char *event_name
)
279 struct ltt_ust_event
*ustevent
;
281 ustevent
= trace_ust_find_event_by_name(ustchan
->events
, event_name
);
282 if (ustevent
== NULL
) {
283 ret
= LTTCOMM_NO_EVENT
;
286 //ret = ustctl_disable(ustsession->sock, ustevent->obj);
288 ret
= LTTCOMM_UST_ENABLE_FAIL
;
291 ustevent
->enabled
= 0;