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>
28 #include "hashtable.h"
29 #include "kernel-ctl.h"
33 * Setup a lttng_event used to enable *all* syscall tracing.
35 static void init_syscalls_kernel_event(struct lttng_event
*event
)
37 event
->name
[0] = '\0';
39 * We use LTTNG_EVENT* here since the trace kernel creation will make the
40 * right changes for the kernel.
42 event
->type
= LTTNG_EVENT_SYSCALL
;
46 * Disable kernel tracepoint event for a channel from the kernel session.
48 int event_kernel_disable_tracepoint(struct ltt_kernel_session
*ksession
,
49 struct ltt_kernel_channel
*kchan
, char *event_name
)
52 struct ltt_kernel_event
*kevent
;
54 kevent
= trace_kernel_get_event_by_name(event_name
, kchan
);
56 ret
= LTTCOMM_NO_EVENT
;
60 ret
= kernel_disable_event(kevent
);
62 ret
= LTTCOMM_KERN_DISABLE_FAIL
;
66 DBG("Kernel event %s disable for channel %s.",
67 kevent
->event
->name
, kchan
->channel
->name
);
76 * Disable kernel tracepoint events for a channel from the kernel session.
78 int event_kernel_disable_all_tracepoints(struct ltt_kernel_session
*ksession
,
79 struct ltt_kernel_channel
*kchan
)
82 struct ltt_kernel_event
*kevent
;
84 /* For each event in the kernel session */
85 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
86 ret
= kernel_disable_event(kevent
);
88 /* We continue disabling the rest */
97 * Disable kernel syscall events for a channel from the kernel session.
99 int event_kernel_disable_all_syscalls(struct ltt_kernel_session
*ksession
,
100 struct ltt_kernel_channel
*kchan
)
102 ERR("Cannot disable syscall tracing for existing session. Please destroy session instead.");
103 return LTTCOMM_OK
; /* Return OK so disable all succeeds */
107 * Disable all kernel event for a channel from the kernel session.
109 int event_kernel_disable_all(struct ltt_kernel_session
*ksession
,
110 struct ltt_kernel_channel
*kchan
)
114 ret
= event_kernel_disable_all_tracepoints(ksession
, kchan
);
115 if (ret
!= LTTCOMM_OK
)
117 ret
= event_kernel_disable_all_syscalls(ksession
, kchan
);
122 * Enable kernel tracepoint event for a channel from the kernel session.
124 int event_kernel_enable_tracepoint(struct ltt_kernel_session
*ksession
,
125 struct ltt_kernel_channel
*kchan
, struct lttng_event
*event
)
128 struct ltt_kernel_event
*kevent
;
130 kevent
= trace_kernel_get_event_by_name(event
->name
, kchan
);
131 if (kevent
== NULL
) {
132 ret
= kernel_create_event(event
, kchan
);
134 if (ret
== -EEXIST
) {
135 ret
= LTTCOMM_KERN_EVENT_EXIST
;
137 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
141 } else if (kevent
->enabled
== 0) {
142 ret
= kernel_enable_event(kevent
);
144 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
154 * Enable all kernel tracepoint events of a channel of the kernel session.
156 int event_kernel_enable_all_tracepoints(struct ltt_kernel_session
*ksession
,
157 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
160 struct ltt_kernel_event
*kevent
;
161 struct lttng_event
*event_list
;
163 /* For each event in the kernel session */
164 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
165 ret
= kernel_enable_event(kevent
);
167 /* Enable failed but still continue */
172 size
= kernel_list_events(kernel_tracer_fd
, &event_list
);
174 ret
= LTTCOMM_KERN_LIST_FAIL
;
178 for (i
= 0; i
< size
; i
++) {
179 kevent
= trace_kernel_get_event_by_name(event_list
[i
].name
, kchan
);
180 if (kevent
== NULL
) {
181 /* Default event type for enable all */
182 event_list
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
183 /* Enable each single tracepoint event */
184 ret
= kernel_create_event(&event_list
[i
], kchan
);
186 /* Ignore error here and continue */
198 * Enable all kernel tracepoint events of a channel of the kernel session.
200 int event_kernel_enable_all_syscalls(struct ltt_kernel_session
*ksession
,
201 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
204 struct lttng_event event
;
206 init_syscalls_kernel_event(&event
);
208 DBG("Enabling all syscall tracing");
210 ret
= kernel_create_event(&event
, kchan
);
220 * Enable all kernel events of a channel of the kernel session.
222 int event_kernel_enable_all(struct ltt_kernel_session
*ksession
,
223 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
227 ret
= event_kernel_enable_all_tracepoints(ksession
, kchan
, kernel_tracer_fd
);
228 if (ret
!= LTTCOMM_OK
) {
231 ret
= event_kernel_enable_all_syscalls(ksession
, kchan
, kernel_tracer_fd
);
237 * Enable UST tracepoint event for a channel from a UST session.
240 int event_ust_enable_tracepoint(struct ltt_ust_session
*usess
,
241 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
)
244 struct lttng_ust_event ltt_uevent
;
245 struct object_data
*obj_event
;
247 strncpy(ltt_uevent
.name
, uevent
->attr
.name
, sizeof(ltt_uevent
.name
));
248 ltt_uevent
.name
[sizeof(ltt_uevent
.name
) - 1] = '\0';
249 /* TODO: adjust to other instrumentation types */
250 ltt_uevent
.instrumentation
= LTTNG_UST_TRACEPOINT
;
252 ret
= ustctl_create_event(app
->key
.sock
, <t_uevent
,
253 uchan
->obj
, &obj_event
);
255 DBG("Error ustctl create event %s for app pid: %d, sock: %d ret %d",
256 uevent
->attr
.name
, app
->key
.pid
, app
->key
.sock
, ret
);
260 uevent
->obj
= obj_event
;
261 uevent
->handle
= obj_event
->handle
;
270 int event_ust_disable_tracepoint(struct ltt_ust_session
*ustsession
,
271 struct ltt_ust_channel
*ustchan
, char *event_name
)
274 struct ltt_ust_event
*ustevent
;
276 ustevent
= trace_ust_find_event_by_name(ustchan
->events
, event_name
);
277 if (ustevent
== NULL
) {
278 ret
= LTTCOMM_NO_EVENT
;
281 //ret = ustctl_disable(ustsession->sock, ustevent->obj);
283 ret
= LTTCOMM_UST_ENABLE_FAIL
;
286 ustevent
->enabled
= 0;