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.
20 #include <urcu/list.h>
23 #include <lttng/lttng.h>
24 #include <lttng-sessiond-comm.h>
29 #include "../common/hashtable.h"
33 #include "trace-kernel.h"
34 #include "trace-ust.h"
37 * Setup a lttng_event used to enable *all* syscall tracing.
39 static void init_syscalls_kernel_event(struct lttng_event
*event
)
41 event
->name
[0] = '\0';
43 * We use LTTNG_EVENT* here since the trace kernel creation will make the
44 * right changes for the kernel.
46 event
->type
= LTTNG_EVENT_SYSCALL
;
50 * Disable kernel tracepoint event for a channel from the kernel session.
52 int event_kernel_disable_tracepoint(struct ltt_kernel_session
*ksession
,
53 struct ltt_kernel_channel
*kchan
, char *event_name
)
56 struct ltt_kernel_event
*kevent
;
58 kevent
= trace_kernel_get_event_by_name(event_name
, kchan
);
60 ret
= LTTCOMM_NO_EVENT
;
64 ret
= kernel_disable_event(kevent
);
66 ret
= LTTCOMM_KERN_DISABLE_FAIL
;
70 DBG("Kernel event %s disable for channel %s.",
71 kevent
->event
->name
, kchan
->channel
->name
);
80 * Disable kernel tracepoint events for a channel from the kernel session.
82 int event_kernel_disable_all_tracepoints(struct ltt_kernel_session
*ksession
,
83 struct ltt_kernel_channel
*kchan
)
86 struct ltt_kernel_event
*kevent
;
88 /* For each event in the kernel session */
89 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
90 ret
= kernel_disable_event(kevent
);
92 /* We continue disabling the rest */
101 * Disable kernel syscall events for a channel from the kernel session.
103 int event_kernel_disable_all_syscalls(struct ltt_kernel_session
*ksession
,
104 struct ltt_kernel_channel
*kchan
)
106 ERR("Cannot disable syscall tracing for existing session. Please destroy session instead.");
107 return LTTCOMM_OK
; /* Return OK so disable all succeeds */
111 * Disable all kernel event for a channel from the kernel session.
113 int event_kernel_disable_all(struct ltt_kernel_session
*ksession
,
114 struct ltt_kernel_channel
*kchan
)
118 ret
= event_kernel_disable_all_tracepoints(ksession
, kchan
);
119 if (ret
!= LTTCOMM_OK
)
121 ret
= event_kernel_disable_all_syscalls(ksession
, kchan
);
126 * Enable kernel tracepoint event for a channel from the kernel session.
128 int event_kernel_enable_tracepoint(struct ltt_kernel_session
*ksession
,
129 struct ltt_kernel_channel
*kchan
, struct lttng_event
*event
)
132 struct ltt_kernel_event
*kevent
;
134 kevent
= trace_kernel_get_event_by_name(event
->name
, kchan
);
135 if (kevent
== NULL
) {
136 ret
= kernel_create_event(event
, kchan
);
138 if (ret
== -EEXIST
) {
139 ret
= LTTCOMM_KERN_EVENT_EXIST
;
141 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
145 } else if (kevent
->enabled
== 0) {
146 ret
= kernel_enable_event(kevent
);
148 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
158 * Enable all kernel tracepoint events of a channel of the kernel session.
160 int event_kernel_enable_all_tracepoints(struct ltt_kernel_session
*ksession
,
161 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
164 struct ltt_kernel_event
*kevent
;
165 struct lttng_event
*event_list
= NULL
;
167 /* For each event in the kernel session */
168 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
169 if (kevent
->enabled
== 0) {
170 ret
= kernel_enable_event(kevent
);
172 /* Enable failed but still continue */
178 size
= kernel_list_events(kernel_tracer_fd
, &event_list
);
180 ret
= LTTCOMM_KERN_LIST_FAIL
;
184 for (i
= 0; i
< size
; i
++) {
185 kevent
= trace_kernel_get_event_by_name(event_list
[i
].name
, kchan
);
186 if (kevent
== NULL
) {
187 /* Default event type for enable all */
188 event_list
[i
].type
= LTTNG_EVENT_TRACEPOINT
;
189 /* Enable each single tracepoint event */
190 ret
= kernel_create_event(&event_list
[i
], kchan
);
192 /* Ignore error here and continue */
205 * Enable all kernel tracepoint events of a channel of the kernel session.
207 int event_kernel_enable_all_syscalls(struct ltt_kernel_session
*ksession
,
208 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
211 struct lttng_event event
;
213 init_syscalls_kernel_event(&event
);
215 DBG("Enabling all syscall tracing");
217 ret
= kernel_create_event(&event
, kchan
);
219 if (ret
== -EEXIST
) {
220 ret
= LTTCOMM_KERN_EVENT_EXIST
;
222 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
233 * Enable all kernel events of a channel of the kernel session.
235 int event_kernel_enable_all(struct ltt_kernel_session
*ksession
,
236 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
240 ret
= event_kernel_enable_all_tracepoints(ksession
, kchan
, kernel_tracer_fd
);
241 if (ret
!= LTTCOMM_OK
) {
244 ret
= event_kernel_enable_all_syscalls(ksession
, kchan
, kernel_tracer_fd
);
250 * ============================
251 * UST : The Ultimate Frontier!
252 * ============================
256 * Enable all UST tracepoints for a channel from a UST session.
258 int event_ust_enable_all_tracepoints(struct ltt_ust_session
*usess
, int domain
,
259 struct ltt_ust_channel
*uchan
)
263 struct cds_lfht_iter iter
;
264 struct ltt_ust_event
*uevent
= NULL
;
265 struct lttng_event
*events
= NULL
;
268 case LTTNG_DOMAIN_UST
:
270 /* Enable existing events */
271 cds_lfht_for_each_entry(uchan
->events
, &iter
, uevent
, node
) {
272 if (uevent
->enabled
== 0) {
273 ret
= ust_app_enable_event_glb(usess
, uchan
, uevent
);
281 /* Get all UST available events */
282 size
= ust_app_list_events(&events
);
284 ret
= LTTCOMM_UST_LIST_FAIL
;
288 for (i
= 0; i
< size
; i
++) {
290 * Check if event exist and if so, continue since it was enable
293 uevent
= trace_ust_find_event_by_name(uchan
->events
,
295 if (uevent
!= NULL
) {
296 ret
= ust_app_enable_event_pid(usess
, uchan
, uevent
,
299 if (ret
!= -EEXIST
) {
300 ret
= LTTCOMM_UST_ENABLE_FAIL
;
307 /* Create ust event */
308 uevent
= trace_ust_create_event(&events
[i
]);
309 if (uevent
== NULL
) {
314 /* Create event for the specific PID */
315 ret
= ust_app_enable_event_pid(usess
, uchan
, uevent
,
318 if (ret
== -EEXIST
) {
319 ret
= LTTCOMM_UST_EVENT_EXIST
;
322 ret
= LTTCOMM_UST_ENABLE_FAIL
;
328 /* Add ltt ust event to channel */
330 hashtable_add_unique(uchan
->events
, &uevent
->node
);
337 case LTTNG_DOMAIN_UST_EXEC_NAME
:
338 case LTTNG_DOMAIN_UST_PID
:
339 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
341 ret
= LTTCOMM_NOT_IMPLEMENTED
;
348 trace_ust_destroy_event(uevent
);
356 * Enable UST tracepoint event for a channel from a UST session.
358 int event_ust_enable_tracepoint(struct ltt_ust_session
*usess
, int domain
,
359 struct ltt_ust_channel
*uchan
, struct lttng_event
*event
)
361 int ret
, to_create
= 0;
362 struct ltt_ust_event
*uevent
;
364 uevent
= trace_ust_find_event_by_name(uchan
->events
, event
->name
);
365 if (uevent
== NULL
) {
366 uevent
= trace_ust_create_event(event
);
367 if (uevent
== NULL
) {
374 if (uevent
->enabled
) {
375 /* It's already enabled so everything is OK */
380 case LTTNG_DOMAIN_UST
:
383 /* Create event on all UST registered apps for session */
384 ret
= ust_app_create_event_glb(usess
, uchan
, uevent
);
386 /* Enable event on all UST registered apps for session */
387 ret
= ust_app_enable_event_glb(usess
, uchan
, uevent
);
391 if (ret
== -EEXIST
) {
392 ret
= LTTCOMM_UST_EVENT_EXIST
;
395 ret
= LTTCOMM_UST_ENABLE_FAIL
;
401 case LTTNG_DOMAIN_UST_EXEC_NAME
:
402 case LTTNG_DOMAIN_UST_PID
:
403 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
405 ret
= LTTCOMM_NOT_IMPLEMENTED
;
410 /* Add ltt ust event to channel */
413 hashtable_add_unique(uchan
->events
, &uevent
->node
);
417 DBG("Event UST %s %s in channel %s", uevent
->attr
.name
,
418 to_create
? "created" : "enabled", uchan
->name
);
424 trace_ust_destroy_event(uevent
);
429 * Disable UST tracepoint of a channel from a UST session.
431 int event_ust_disable_tracepoint(struct ltt_ust_session
*usess
, int domain
,
432 struct ltt_ust_channel
*uchan
, char *event_name
)
435 struct ltt_ust_event
*uevent
;
437 uevent
= trace_ust_find_event_by_name(uchan
->events
, event_name
);
438 if (uevent
== NULL
) {
439 ret
= LTTCOMM_UST_EVENT_NOT_FOUND
;
443 if (uevent
->enabled
== 0) {
444 /* It's already enabled so everything is OK */
450 case LTTNG_DOMAIN_UST
:
451 ret
= ust_app_disable_event_glb(usess
, uchan
, uevent
);
452 if (ret
< 0 && ret
!= -EEXIST
) {
453 ret
= LTTCOMM_UST_DISABLE_FAIL
;
457 case LTTNG_DOMAIN_UST_EXEC_NAME
:
458 case LTTNG_DOMAIN_UST_PID
:
459 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
461 ret
= LTTCOMM_NOT_IMPLEMENTED
;
469 DBG2("Event UST %s disabled in channel %s", uevent
->attr
.name
,
477 * Disable all UST tracepoints for a channel from a UST session.
479 int event_ust_disable_all_tracepoints(struct ltt_ust_session
*usess
, int domain
,
480 struct ltt_ust_channel
*uchan
)
484 struct cds_lfht_iter iter
;
485 struct ltt_ust_event
*uevent
= NULL
;
486 struct lttng_event
*events
= NULL
;
489 case LTTNG_DOMAIN_UST
:
491 /* Disabling existing events */
492 cds_lfht_for_each_entry(uchan
->events
, &iter
, uevent
, node
) {
493 if (uevent
->enabled
== 1) {
494 ret
= ust_app_disable_event_glb(usess
, uchan
, uevent
);
502 /* Get all UST available events */
503 size
= ust_app_list_events(&events
);
505 ret
= LTTCOMM_UST_LIST_FAIL
;
509 for (i
= 0; i
< size
; i
++) {
510 uevent
= trace_ust_find_event_by_name(uchan
->events
,
512 if (uevent
!= NULL
&& uevent
->enabled
== 1) {
513 ret
= ust_app_disable_event_pid(usess
, uchan
, uevent
,
515 if (ret
< 0 && ret
!= -EEXIST
) {
516 ret
= LTTCOMM_UST_DISABLE_FAIL
;
527 case LTTNG_DOMAIN_UST_EXEC_NAME
:
528 case LTTNG_DOMAIN_UST_PID
:
529 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
531 ret
= LTTCOMM_NOT_IMPLEMENTED
;