2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include <urcu/list.h>
30 * Add kernel context to an event of a specific channel.
32 static int add_kctx_to_event(struct lttng_kernel_context
*kctx
,
33 struct ltt_kernel_channel
*kchan
, char *event_name
)
36 struct ltt_kernel_event
*kevent
;
38 DBG("Add kernel context to event %s", event_name
);
40 kevent
= get_kernel_event_by_name(event_name
, kchan
);
42 ret
= kernel_add_event_context(kevent
, kctx
);
56 * Add kernel context to all channel.
58 * If event_name is specified, add context to event instead.
60 static int add_kctx_all_channels(struct ltt_kernel_session
*ksession
,
61 struct lttng_kernel_context
*kctx
, char *event_name
)
63 int ret
, no_event
= 0, found
= 0;
64 struct ltt_kernel_channel
*kchan
;
66 if (strlen(event_name
) == 0) {
70 DBG("Adding kernel context to all channels (event: %s)", event_name
);
72 /* Go over all channels */
73 cds_list_for_each_entry(kchan
, &ksession
->channel_list
.head
, list
) {
75 ret
= kernel_add_channel_context(kchan
, kctx
);
77 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
81 ret
= add_kctx_to_event(kctx
, kchan
, event_name
);
83 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
85 } else if (ret
== 1) {
86 /* Event found and context added */
93 if (!found
&& !no_event
) {
94 ret
= LTTCOMM_NO_EVENT
;
105 * Add kernel context to a specific channel.
107 * If event_name is specified, add context to that event.
109 static int add_kctx_to_channel(struct lttng_kernel_context
*kctx
,
110 struct ltt_kernel_channel
*kchan
, char *event_name
)
112 int ret
, no_event
= 0, found
= 0;
114 if (strlen(event_name
) == 0) {
118 DBG("Add kernel context to channel '%s', event '%s'",
119 kchan
->channel
->name
, event_name
);
122 ret
= kernel_add_channel_context(kchan
, kctx
);
124 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
128 ret
= add_kctx_to_event(kctx
, kchan
, event_name
);
130 ret
= LTTCOMM_KERN_CONTEXT_FAIL
;
132 } else if (ret
== 1) {
133 /* Event found and context added */
138 if (!found
&& !no_event
) {
139 ret
= LTTCOMM_NO_EVENT
;
150 * Add kernel context to tracer.
152 int add_kernel_context(struct ltt_kernel_session
*ksession
,
153 struct lttng_kernel_context
*kctx
, char *event_name
,
157 struct ltt_kernel_channel
*kchan
;
159 if (strlen(channel_name
) == 0) {
160 ret
= add_kctx_all_channels(ksession
, kctx
, event_name
);
161 if (ret
!= LTTCOMM_OK
) {
165 /* Get kernel channel */
166 kchan
= get_kernel_channel_by_name(channel_name
, ksession
);
168 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
172 ret
= add_kctx_to_channel(kctx
, kchan
, event_name
);
173 if (ret
!= LTTCOMM_OK
) {