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 <common/error.h>
25 #include <common/sessiond-comm/sessiond-comm.h>
32 #include "trace-kernel.h"
33 #include "trace-ust.h"
36 * Setup a lttng_event used to enable *all* syscall tracing.
38 static void init_syscalls_kernel_event(struct lttng_event
*event
)
40 event
->name
[0] = '\0';
42 * We use LTTNG_EVENT* here since the trace kernel creation will make the
43 * right changes for the kernel.
45 event
->type
= LTTNG_EVENT_SYSCALL
;
49 * Disable kernel tracepoint event for a channel from the kernel session.
51 int event_kernel_disable_tracepoint(struct ltt_kernel_session
*ksession
,
52 struct ltt_kernel_channel
*kchan
, char *event_name
)
55 struct ltt_kernel_event
*kevent
;
57 kevent
= trace_kernel_get_event_by_name(event_name
, kchan
);
59 ret
= LTTCOMM_NO_EVENT
;
63 ret
= kernel_disable_event(kevent
);
65 ret
= LTTCOMM_KERN_DISABLE_FAIL
;
69 DBG("Kernel event %s disable for channel %s.",
70 kevent
->event
->name
, kchan
->channel
->name
);
79 * Disable kernel tracepoint events for a channel from the kernel session.
81 int event_kernel_disable_all_tracepoints(struct ltt_kernel_session
*ksession
,
82 struct ltt_kernel_channel
*kchan
)
85 struct ltt_kernel_event
*kevent
;
87 /* For each event in the kernel session */
88 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
89 ret
= kernel_disable_event(kevent
);
91 /* We continue disabling the rest */
100 * Disable kernel syscall events for a channel from the kernel session.
102 int event_kernel_disable_all_syscalls(struct ltt_kernel_session
*ksession
,
103 struct ltt_kernel_channel
*kchan
)
105 ERR("Cannot disable syscall tracing for existing session. Please destroy session instead.");
106 return LTTCOMM_OK
; /* Return OK so disable all succeeds */
110 * Disable all kernel event for a channel from the kernel session.
112 int event_kernel_disable_all(struct ltt_kernel_session
*ksession
,
113 struct ltt_kernel_channel
*kchan
)
117 ret
= event_kernel_disable_all_tracepoints(ksession
, kchan
);
118 if (ret
!= LTTCOMM_OK
)
120 ret
= event_kernel_disable_all_syscalls(ksession
, kchan
);
125 * Enable kernel tracepoint event for a channel from the kernel session.
127 int event_kernel_enable_tracepoint(struct ltt_kernel_session
*ksession
,
128 struct ltt_kernel_channel
*kchan
, struct lttng_event
*event
)
131 struct ltt_kernel_event
*kevent
;
133 kevent
= trace_kernel_get_event_by_name(event
->name
, kchan
);
134 if (kevent
== NULL
) {
135 ret
= kernel_create_event(event
, kchan
);
137 if (ret
== -EEXIST
) {
138 ret
= LTTCOMM_KERN_EVENT_EXIST
;
140 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
144 } else if (kevent
->enabled
== 0) {
145 ret
= kernel_enable_event(kevent
);
147 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
157 * Enable all kernel tracepoint events of a channel of the kernel session.
159 int event_kernel_enable_all_tracepoints(struct ltt_kernel_session
*ksession
,
160 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
163 struct ltt_kernel_event
*kevent
;
164 struct lttng_event
*event_list
= NULL
;
166 /* For each event in the kernel session */
167 cds_list_for_each_entry(kevent
, &kchan
->events_list
.head
, list
) {
168 if (kevent
->enabled
== 0) {
169 ret
= kernel_enable_event(kevent
);
171 /* 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 */
204 * Enable all kernel tracepoint events of a channel of the kernel session.
206 int event_kernel_enable_all_syscalls(struct ltt_kernel_session
*ksession
,
207 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
210 struct lttng_event event
;
212 init_syscalls_kernel_event(&event
);
214 DBG("Enabling all syscall tracing");
216 ret
= kernel_create_event(&event
, kchan
);
218 if (ret
== -EEXIST
) {
219 ret
= LTTCOMM_KERN_EVENT_EXIST
;
221 ret
= LTTCOMM_KERN_ENABLE_FAIL
;
232 * Enable all kernel events of a channel of the kernel session.
234 int event_kernel_enable_all(struct ltt_kernel_session
*ksession
,
235 struct ltt_kernel_channel
*kchan
, int kernel_tracer_fd
)
239 ret
= event_kernel_enable_all_tracepoints(ksession
, kchan
, kernel_tracer_fd
);
240 if (ret
!= LTTCOMM_OK
) {
243 ret
= event_kernel_enable_all_syscalls(ksession
, kchan
, kernel_tracer_fd
);
249 * ============================
250 * UST : The Ultimate Frontier!
251 * ============================
255 * Enable all UST tracepoints for a channel from a UST session.
257 int event_ust_enable_all_tracepoints(struct ltt_ust_session
*usess
, int domain
,
258 struct ltt_ust_channel
*uchan
)
262 struct lttng_ht_iter iter
;
263 struct ltt_ust_event
*uevent
= NULL
;
264 struct lttng_event
*events
= NULL
;
267 case LTTNG_DOMAIN_UST
:
269 /* Enable existing events */
270 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
,
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 lttng_ht_add_unique_str(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
= LTTCOMM_OK
, 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
) {
371 /* Valid to set it after the goto error since uevent is still NULL */
375 if (uevent
->enabled
) {
376 /* It's already enabled so everything is OK */
383 case LTTNG_DOMAIN_UST
:
386 /* Create event on all UST registered apps for session */
387 ret
= ust_app_create_event_glb(usess
, uchan
, uevent
);
389 /* Enable event on all UST registered apps for session */
390 ret
= ust_app_enable_event_glb(usess
, uchan
, uevent
);
394 if (ret
== -EEXIST
) {
395 ret
= LTTCOMM_UST_EVENT_EXIST
;
398 ret
= LTTCOMM_UST_ENABLE_FAIL
;
404 case LTTNG_DOMAIN_UST_EXEC_NAME
:
405 case LTTNG_DOMAIN_UST_PID
:
406 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
408 ret
= LTTCOMM_NOT_IMPLEMENTED
;
414 /* Add ltt ust event to channel */
415 lttng_ht_add_unique_str(uchan
->events
, &uevent
->node
);
419 DBG("Event UST %s %s in channel %s", uevent
->attr
.name
,
420 to_create
? "created" : "enabled", uchan
->name
);
429 * Only destroy event on creation time (not enabling time) because if the
430 * event is found in the channel (to_create == 0), it means that at some
431 * point the enable_event worked and it's thus valid to keep it alive.
432 * Destroying it also implies that we also destroy it's shadow copy to sync
436 /* In this code path, the uevent was not added to the hash table */
437 trace_ust_destroy_event(uevent
);
443 * Disable UST tracepoint of a channel from a UST session.
445 int event_ust_disable_tracepoint(struct ltt_ust_session
*usess
, int domain
,
446 struct ltt_ust_channel
*uchan
, char *event_name
)
449 struct ltt_ust_event
*uevent
;
451 uevent
= trace_ust_find_event_by_name(uchan
->events
, event_name
);
452 if (uevent
== NULL
) {
453 ret
= LTTCOMM_UST_EVENT_NOT_FOUND
;
457 if (uevent
->enabled
== 0) {
458 /* It's already enabled so everything is OK */
464 case LTTNG_DOMAIN_UST
:
465 ret
= ust_app_disable_event_glb(usess
, uchan
, uevent
);
466 if (ret
< 0 && ret
!= -EEXIST
) {
467 ret
= LTTCOMM_UST_DISABLE_FAIL
;
471 case LTTNG_DOMAIN_UST_EXEC_NAME
:
472 case LTTNG_DOMAIN_UST_PID
:
473 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
475 ret
= LTTCOMM_NOT_IMPLEMENTED
;
483 DBG2("Event UST %s disabled in channel %s", uevent
->attr
.name
,
491 * Disable all UST tracepoints for a channel from a UST session.
493 int event_ust_disable_all_tracepoints(struct ltt_ust_session
*usess
, int domain
,
494 struct ltt_ust_channel
*uchan
)
498 struct lttng_ht_iter iter
;
499 struct ltt_ust_event
*uevent
= NULL
;
500 struct lttng_event
*events
= NULL
;
503 case LTTNG_DOMAIN_UST
:
505 /* Disabling existing events */
506 cds_lfht_for_each_entry(uchan
->events
->ht
, &iter
.iter
, uevent
,
508 if (uevent
->enabled
== 1) {
509 ret
= ust_app_disable_event_glb(usess
, uchan
, uevent
);
517 /* Get all UST available events */
518 size
= ust_app_list_events(&events
);
520 ret
= LTTCOMM_UST_LIST_FAIL
;
524 for (i
= 0; i
< size
; i
++) {
525 uevent
= trace_ust_find_event_by_name(uchan
->events
,
527 if (uevent
!= NULL
&& uevent
->enabled
== 1) {
528 ret
= ust_app_disable_event_pid(usess
, uchan
, uevent
,
530 if (ret
< 0 && ret
!= -EEXIST
) {
531 ret
= LTTCOMM_UST_DISABLE_FAIL
;
542 case LTTNG_DOMAIN_UST_EXEC_NAME
:
543 case LTTNG_DOMAIN_UST_PID
:
544 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
546 ret
= LTTCOMM_NOT_IMPLEMENTED
;