2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 * Copyright (C) 2012 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2 only,
7 * as published by the Free Software Foundation.
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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <urcu/list.h>
26 #include <common/error.h>
27 #include <common/sessiond-comm/sessiond-comm.h>
32 #include "trace-ust.h"
35 * Add UST context to event.
37 static int add_ufilter_to_event(struct ltt_ust_session
*usess
, int domain
,
38 struct ltt_ust_channel
*uchan
, struct ltt_ust_event
*uevent
,
39 struct lttng_filter_bytecode
*bytecode
)
48 uevent
->filter
= (struct lttng_ust_filter_bytecode
*) bytecode
;
51 case LTTNG_DOMAIN_UST
:
52 ret
= ust_app_set_filter_event_glb(usess
, uchan
, uevent
,
63 DBG("Filter UST added to event %s",uevent
->attr
.name
);
73 * Add UST context to tracer.
75 int filter_ust_set(struct ltt_ust_session
*usess
, int domain
,
76 struct lttng_filter_bytecode
*bytecode
, char *event_name
,
79 int ret
= LTTNG_OK
, have_event
= 0;
80 struct lttng_ht_iter iter
;
81 struct lttng_ht
*chan_ht
;
82 struct ltt_ust_channel
*uchan
= NULL
;
83 struct ltt_ust_event
*uevent
= NULL
;
86 * Define which channel's hashtable to use from the domain or quit if
90 case LTTNG_DOMAIN_UST
:
91 chan_ht
= usess
->domain_global
.channels
;
94 case LTTNG_DOMAIN_UST_EXEC_NAME
:
95 case LTTNG_DOMAIN_UST_PID
:
96 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
103 /* Do we have an event name */
104 if (strlen(event_name
) != 0) {
108 /* Get UST channel if defined */
109 if (strlen(channel_name
) != 0) {
110 uchan
= trace_ust_find_channel_by_name(chan_ht
, channel_name
);
112 ret
= LTTNG_ERR_UST_CHAN_NOT_FOUND
;
117 /* If UST channel specified and event name, get UST event ref */
118 if (uchan
&& have_event
) {
119 uevent
= trace_ust_find_event_by_name(uchan
->events
, event_name
);
120 if (uevent
== NULL
) {
121 ret
= LTTNG_ERR_UST_EVENT_NOT_FOUND
;
126 /* At this point, we have 4 possibilities */
128 if (uchan
&& uevent
) { /* Add filter to event in channel */
129 ret
= add_ufilter_to_event(usess
, domain
, uchan
, uevent
,
131 } else if (uchan
&& !have_event
) { /* Add filter to channel */
132 ERR("Cannot add filter to channel");
133 ret
= LTTNG_ERR_FATAL
; /* not supported. */
135 } else if (!uchan
&& have_event
) { /* Add filter to event */
136 /* Add context to event without having the channel name */
137 cds_lfht_for_each_entry(chan_ht
->ht
, &iter
.iter
, uchan
, node
.node
) {
138 uevent
= trace_ust_find_event_by_name(uchan
->events
, event_name
);
139 if (uevent
!= NULL
) {
140 ret
= add_ufilter_to_event(usess
, domain
, uchan
, uevent
, bytecode
);
142 * LTTng UST does not allowed the same event to be registered
143 * multiple time in different or the same channel. So, if we
144 * found our event, we stop.
149 ret
= LTTNG_ERR_UST_EVENT_NOT_FOUND
;
151 } else if (!uchan
&& !have_event
) { /* Add filter all events, all channels */
152 ERR("Cannot add filter to channel");
153 ret
= LTTNG_ERR_FATAL
; /* not supported. */
160 ret
= LTTNG_ERR_FILTER_EXIST
;
163 ret
= LTTNG_ERR_FATAL
;
166 ret
= LTTNG_ERR_FILTER_INVAL
;
169 ret
= LTTNG_ERR_UNKNOWN_DOMAIN
;