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.
24 #include <lttng-sessiond-comm.h>
25 #include <urcu/list.h>
29 #include "kernel-ctl.h"
32 * Add kernel context to an event of a specific channel.
34 static int add_kctx_to_event(struct lttng_kernel_context
*kctx
,
35 struct ltt_kernel_channel
*kchan
, char *event_name
)
38 struct ltt_kernel_event
*kevent
;
40 DBG("Add kernel context to event %s", event_name
);
42 kevent
= trace_kernel_get_event_by_name(event_name
, kchan
);
44 ret
= kernel_add_event_context(kevent
, kctx
);
58 * Add kernel context to all channel.
60 * If event_name is specified, add context to event instead.
62 static int add_kctx_all_channels(struct ltt_kernel_session
*ksession
,
63 struct lttng_kernel_context
*kctx
, char *event_name
)
65 int ret
, no_event
= 0, found
= 0;
66 struct ltt_kernel_channel
*kchan
;
68 if (strlen(event_name
) == 0) {
72 DBG("Adding kernel context to all channels (event: %s)", event_name
);
74 /* Go over all channels */
75 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
77 ret
= kernel_add_channel_context(kchan
, kctx
);
79 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
83 ret
= add_kctx_to_event(kctx
, kchan
, event_name
);
85 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
87 } else if (ret
== 1) {
88 /* Event found and context added */
95 if (!found
&& !no_event
) {
96 ret
= LTTCOMM_NO_EVENT
;
107 * Add kernel context to a specific channel.
109 * If event_name is specified, add context to that event.
111 static int add_kctx_to_channel(struct lttng_kernel_context
*kctx
,
112 struct ltt_kernel_channel
*kchan
, char *event_name
)
114 int ret
, no_event
= 0, found
= 0;
116 if (strlen(event_name
) == 0) {
120 DBG("Add kernel context to channel '%s', event '%s'",
121 kchan
->channel
->name
, event_name
);
124 ret
= kernel_add_channel_context(kchan
, kctx
);
126 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
130 ret
= add_kctx_to_event(kctx
, kchan
, event_name
);
132 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
134 } else if (ret
== 1) {
135 /* Event found and context added */
140 if (!found
&& !no_event
) {
141 ret
= LTTCOMM_NO_EVENT
;
152 * Add kernel context to tracer.
154 int add_kernel_context(struct ltt_kernel_session
*ksession
,
155 struct lttng_kernel_context
*kctx
, char *event_name
,
159 struct ltt_kernel_channel
*kchan
;
161 if (strlen(channel_name
) == 0) {
162 ret
= add_kctx_all_channels(ksession
, kctx
, event_name
);
163 if (ret
!= LTTCOMM_OK
) {
167 /* Get kernel channel */
168 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
170 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
174 ret
= add_kctx_to_channel(kctx
, kchan
, event_name
);
175 if (ret
!= LTTCOMM_OK
) {