Commit | Line | Data |
---|---|---|
54d01ffb DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
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. | |
7 | * | |
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 | |
11 | * more details. | |
12 | * | |
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. | |
16 | */ | |
17 | ||
d87bfb32 | 18 | #include <errno.h> |
54d01ffb | 19 | #include <urcu/list.h> |
2bdd86d4 | 20 | #include <string.h> |
54d01ffb DG |
21 | |
22 | #include <lttng/lttng.h> | |
23 | #include <lttng-sessiond-comm.h> | |
24 | #include <lttngerr.h> | |
25 | ||
26 | #include "channel.h" | |
27 | #include "event.h" | |
48842b30 | 28 | #include "hashtable.h" |
4771f025 | 29 | #include "kernel.h" |
9df8df5e | 30 | #include "ust-ctl.h" |
edb67388 DG |
31 | #include "ust-app.h" |
32 | #include "trace-kernel.h" | |
33 | #include "trace-ust.h" | |
54d01ffb | 34 | |
8c9ae521 DG |
35 | /* |
36 | * Setup a lttng_event used to enable *all* syscall tracing. | |
37 | */ | |
38 | static void init_syscalls_kernel_event(struct lttng_event *event) | |
39 | { | |
40 | event->name[0] = '\0'; | |
41 | /* | |
42 | * We use LTTNG_EVENT* here since the trace kernel creation will make the | |
43 | * right changes for the kernel. | |
44 | */ | |
45 | event->type = LTTNG_EVENT_SYSCALL; | |
46 | } | |
47 | ||
54d01ffb | 48 | /* |
7a3d1328 | 49 | * Disable kernel tracepoint event for a channel from the kernel session. |
54d01ffb | 50 | */ |
7a3d1328 | 51 | int event_kernel_disable_tracepoint(struct ltt_kernel_session *ksession, |
54d01ffb DG |
52 | struct ltt_kernel_channel *kchan, char *event_name) |
53 | { | |
54 | int ret; | |
55 | struct ltt_kernel_event *kevent; | |
56 | ||
57 | kevent = trace_kernel_get_event_by_name(event_name, kchan); | |
58 | if (kevent == NULL) { | |
59 | ret = LTTCOMM_NO_EVENT; | |
60 | goto error; | |
61 | } | |
62 | ||
63 | ret = kernel_disable_event(kevent); | |
64 | if (ret < 0) { | |
65 | ret = LTTCOMM_KERN_DISABLE_FAIL; | |
66 | goto error; | |
67 | } | |
68 | ||
69 | DBG("Kernel event %s disable for channel %s.", | |
70 | kevent->event->name, kchan->channel->name); | |
71 | ||
72 | ret = LTTCOMM_OK; | |
73 | ||
74 | error: | |
75 | return ret; | |
76 | } | |
77 | ||
78 | /* | |
7a3d1328 | 79 | * Disable kernel tracepoint events for a channel from the kernel session. |
54d01ffb | 80 | */ |
7a3d1328 | 81 | int event_kernel_disable_all_tracepoints(struct ltt_kernel_session *ksession, |
54d01ffb DG |
82 | struct ltt_kernel_channel *kchan) |
83 | { | |
84 | int ret; | |
85 | struct ltt_kernel_event *kevent; | |
86 | ||
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); | |
90 | if (ret < 0) { | |
91 | /* We continue disabling the rest */ | |
92 | continue; | |
93 | } | |
94 | } | |
54d01ffb | 95 | ret = LTTCOMM_OK; |
7a3d1328 MD |
96 | return ret; |
97 | } | |
98 | ||
99 | /* | |
100 | * Disable kernel syscall events for a channel from the kernel session. | |
101 | */ | |
102 | int event_kernel_disable_all_syscalls(struct ltt_kernel_session *ksession, | |
103 | struct ltt_kernel_channel *kchan) | |
104 | { | |
105 | ERR("Cannot disable syscall tracing for existing session. Please destroy session instead."); | |
106 | return LTTCOMM_OK; /* Return OK so disable all succeeds */ | |
107 | } | |
54d01ffb | 108 | |
7a3d1328 MD |
109 | /* |
110 | * Disable all kernel event for a channel from the kernel session. | |
111 | */ | |
112 | int event_kernel_disable_all(struct ltt_kernel_session *ksession, | |
113 | struct ltt_kernel_channel *kchan) | |
114 | { | |
115 | int ret; | |
116 | ||
117 | ret = event_kernel_disable_all_tracepoints(ksession, kchan); | |
118 | if (ret != LTTCOMM_OK) | |
119 | return ret; | |
120 | ret = event_kernel_disable_all_syscalls(ksession, kchan); | |
54d01ffb DG |
121 | return ret; |
122 | } | |
123 | ||
124 | /* | |
7a3d1328 | 125 | * Enable kernel tracepoint event for a channel from the kernel session. |
54d01ffb | 126 | */ |
7a3d1328 | 127 | int event_kernel_enable_tracepoint(struct ltt_kernel_session *ksession, |
54d01ffb DG |
128 | struct ltt_kernel_channel *kchan, struct lttng_event *event) |
129 | { | |
130 | int ret; | |
131 | struct ltt_kernel_event *kevent; | |
132 | ||
133 | kevent = trace_kernel_get_event_by_name(event->name, kchan); | |
134 | if (kevent == NULL) { | |
135 | ret = kernel_create_event(event, kchan); | |
136 | if (ret < 0) { | |
d87bfb32 DG |
137 | if (ret == -EEXIST) { |
138 | ret = LTTCOMM_KERN_EVENT_EXIST; | |
139 | } else { | |
140 | ret = LTTCOMM_KERN_ENABLE_FAIL; | |
141 | } | |
7a3d1328 | 142 | goto end; |
54d01ffb DG |
143 | } |
144 | } else if (kevent->enabled == 0) { | |
145 | ret = kernel_enable_event(kevent); | |
146 | if (ret < 0) { | |
147 | ret = LTTCOMM_KERN_ENABLE_FAIL; | |
7a3d1328 | 148 | goto end; |
54d01ffb DG |
149 | } |
150 | } | |
54d01ffb | 151 | ret = LTTCOMM_OK; |
7a3d1328 | 152 | end: |
54d01ffb DG |
153 | return ret; |
154 | } | |
155 | ||
156 | /* | |
7a3d1328 | 157 | * Enable all kernel tracepoint events of a channel of the kernel session. |
54d01ffb | 158 | */ |
7a3d1328 | 159 | int event_kernel_enable_all_tracepoints(struct ltt_kernel_session *ksession, |
54d01ffb DG |
160 | struct ltt_kernel_channel *kchan, int kernel_tracer_fd) |
161 | { | |
162 | int size, i, ret; | |
163 | struct ltt_kernel_event *kevent; | |
164 | struct lttng_event *event_list; | |
165 | ||
166 | /* For each event in the kernel session */ | |
167 | cds_list_for_each_entry(kevent, &kchan->events_list.head, list) { | |
168 | ret = kernel_enable_event(kevent); | |
169 | if (ret < 0) { | |
170 | /* Enable failed but still continue */ | |
171 | continue; | |
172 | } | |
173 | } | |
174 | ||
175 | size = kernel_list_events(kernel_tracer_fd, &event_list); | |
176 | if (size < 0) { | |
177 | ret = LTTCOMM_KERN_LIST_FAIL; | |
7a3d1328 | 178 | goto end; |
54d01ffb DG |
179 | } |
180 | ||
181 | for (i = 0; i < size; i++) { | |
182 | kevent = trace_kernel_get_event_by_name(event_list[i].name, kchan); | |
183 | if (kevent == NULL) { | |
184 | /* Default event type for enable all */ | |
185 | event_list[i].type = LTTNG_EVENT_TRACEPOINT; | |
186 | /* Enable each single tracepoint event */ | |
187 | ret = kernel_create_event(&event_list[i], kchan); | |
188 | if (ret < 0) { | |
189 | /* Ignore error here and continue */ | |
190 | } | |
191 | } | |
192 | } | |
54d01ffb | 193 | free(event_list); |
54d01ffb | 194 | ret = LTTCOMM_OK; |
7a3d1328 | 195 | end: |
54d01ffb | 196 | return ret; |
7a3d1328 | 197 | |
54d01ffb | 198 | } |
8c9ae521 DG |
199 | |
200 | /* | |
7a3d1328 | 201 | * Enable all kernel tracepoint events of a channel of the kernel session. |
8c9ae521 | 202 | */ |
7a3d1328 | 203 | int event_kernel_enable_all_syscalls(struct ltt_kernel_session *ksession, |
8c9ae521 DG |
204 | struct ltt_kernel_channel *kchan, int kernel_tracer_fd) |
205 | { | |
206 | int ret; | |
207 | struct lttng_event event; | |
208 | ||
209 | init_syscalls_kernel_event(&event); | |
210 | ||
211 | DBG("Enabling all syscall tracing"); | |
212 | ||
213 | ret = kernel_create_event(&event, kchan); | |
214 | if (ret < 0) { | |
7a3d1328 | 215 | goto end; |
8c9ae521 | 216 | } |
8c9ae521 | 217 | ret = LTTCOMM_OK; |
7a3d1328 MD |
218 | end: |
219 | return ret; | |
220 | } | |
8c9ae521 | 221 | |
7a3d1328 MD |
222 | /* |
223 | * Enable all kernel events of a channel of the kernel session. | |
224 | */ | |
225 | int event_kernel_enable_all(struct ltt_kernel_session *ksession, | |
226 | struct ltt_kernel_channel *kchan, int kernel_tracer_fd) | |
227 | { | |
228 | int ret; | |
229 | ||
230 | ret = event_kernel_enable_all_tracepoints(ksession, kchan, kernel_tracer_fd); | |
231 | if (ret != LTTCOMM_OK) { | |
232 | goto end; | |
233 | } | |
234 | ret = event_kernel_enable_all_syscalls(ksession, kchan, kernel_tracer_fd); | |
235 | end: | |
8c9ae521 DG |
236 | return ret; |
237 | } | |
2bdd86d4 MD |
238 | |
239 | /* | |
240 | * Enable UST tracepoint event for a channel from a UST session. | |
241 | */ | |
edb67388 DG |
242 | int event_ust_enable_tracepoint(struct ltt_ust_session *usess, int domain, |
243 | struct ltt_ust_channel *uchan, struct lttng_event *event) | |
2bdd86d4 | 244 | { |
edb67388 DG |
245 | int ret, to_create = 0; |
246 | struct ltt_ust_event *uevent; | |
247 | ||
248 | uevent = trace_ust_find_event_by_name(uchan->events, event->name); | |
249 | if (uevent == NULL) { | |
250 | uevent = trace_ust_create_event(event); | |
251 | if (uevent == NULL) { | |
252 | ret = LTTCOMM_FATAL; | |
253 | goto error; | |
254 | } | |
255 | to_create = 1; | |
256 | } | |
2bdd86d4 | 257 | |
edb67388 DG |
258 | switch (domain) { |
259 | case LTTNG_DOMAIN_UST: | |
260 | { | |
261 | if (to_create) { | |
262 | /* Create event on all UST registered apps for session */ | |
35a9059d | 263 | ret = ust_app_create_event_glb(usess, uchan, uevent); |
edb67388 DG |
264 | } else { |
265 | /* Enable event on all UST registered apps for session */ | |
35a9059d | 266 | ret = ust_app_enable_event_glb(usess, uchan, uevent); |
edb67388 | 267 | } |
48842b30 | 268 | |
edb67388 DG |
269 | if (ret < 0) { |
270 | if (ret == -EEXIST) { | |
271 | ret = LTTCOMM_UST_EVENT_EXIST; | |
272 | } else { | |
273 | ret = LTTCOMM_UST_ENABLE_FAIL; | |
274 | } | |
275 | goto error; | |
276 | } | |
277 | ||
278 | DBG("Event UST %s added to channel %s", uevent->attr.name, | |
279 | uchan->name); | |
280 | break; | |
281 | } | |
282 | case LTTNG_DOMAIN_UST_EXEC_NAME: | |
283 | case LTTNG_DOMAIN_UST_PID: | |
284 | case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN: | |
285 | default: | |
286 | ret = LTTCOMM_NOT_IMPLEMENTED; | |
287 | goto error; | |
2bdd86d4 | 288 | } |
48842b30 | 289 | |
48842b30 | 290 | uevent->enabled = 1; |
edb67388 DG |
291 | /* Add ltt ust event to channel */ |
292 | rcu_read_lock(); | |
293 | hashtable_add_unique(uchan->events, &uevent->node); | |
294 | rcu_read_unlock(); | |
295 | ||
296 | return LTTCOMM_OK; | |
297 | ||
298 | error: | |
299 | trace_ust_destroy_event(uevent); | |
2bdd86d4 MD |
300 | return ret; |
301 | } | |
302 | ||
48842b30 | 303 | #ifdef DISABLE |
2bdd86d4 MD |
304 | int event_ust_disable_tracepoint(struct ltt_ust_session *ustsession, |
305 | struct ltt_ust_channel *ustchan, char *event_name) | |
306 | { | |
307 | int ret; | |
308 | struct ltt_ust_event *ustevent; | |
309 | ||
48842b30 | 310 | ustevent = trace_ust_find_event_by_name(ustchan->events, event_name); |
2bdd86d4 MD |
311 | if (ustevent == NULL) { |
312 | ret = LTTCOMM_NO_EVENT; | |
313 | goto end; | |
314 | } | |
48842b30 | 315 | //ret = ustctl_disable(ustsession->sock, ustevent->obj); |
2bdd86d4 MD |
316 | if (ret < 0) { |
317 | ret = LTTCOMM_UST_ENABLE_FAIL; | |
318 | goto end; | |
319 | } | |
320 | ustevent->enabled = 0; | |
321 | ret = LTTCOMM_OK; | |
322 | end: | |
323 | return ret; | |
324 | } | |
48842b30 | 325 | #endif |