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; either version 2
7 * of the License, or (at your option) any later version.
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.
27 #include "ltt-sessiond.h"
28 #include "libkernelctl.h"
29 #include "kernel-ctl.h"
32 * kernel_create_session
34 * Create a new kernel session, register it to the kernel tracer and add it to
35 * the session daemon session.
37 int kernel_create_session(struct ltt_session
*session
, int tracer_fd
)
40 struct ltt_kernel_session
*lks
;
42 /* Allocate data structure */
43 lks
= trace_create_kernel_session();
49 /* Kernel tracer session creation */
50 ret
= kernctl_create_session(tracer_fd
);
52 perror("ioctl kernel create session");
57 lks
->kconsumer_fds_sent
= 0;
58 session
->kernel_session
= lks
;
59 session
->kern_session_count
++;
61 DBG("Kernel session created (fd: %d)", lks
->fd
);
70 * kernel_create_channel
72 * Create a kernel channel, register it to the kernel tracer and add it to the
75 int kernel_create_channel(struct ltt_kernel_session
*session
, struct lttng_channel
*chan
)
78 struct ltt_kernel_channel
*lkc
;
80 /* Allocate kernel channel */
81 lkc
= trace_create_kernel_channel(chan
);
86 /* Kernel tracer channel creation */
87 ret
= kernctl_create_channel(session
->fd
, &lkc
->channel
->attr
);
89 perror("ioctl kernel create channel");
93 /* Setup the channel fd */
95 /* Add channel to session */
96 cds_list_add(&lkc
->list
, &session
->channel_list
.head
);
97 session
->channel_count
++;
99 DBG("Kernel channel %s created (fd: %d and path: %s)",
100 lkc
->channel
->name
, lkc
->fd
, lkc
->pathname
);
109 * kernel_create_event
111 * Create a kernel event, enable it to the kernel tracer and add it to the
112 * channel event list of the kernel session.
114 int kernel_create_event(struct ltt_kernel_channel
*channel
, struct lttng_event
*ev
)
117 struct ltt_kernel_event
*event
;
119 event
= trace_create_kernel_event(ev
);
124 ret
= kernctl_create_event(channel
->fd
, event
->event
);
126 ERR("Unable to enable event %s for channel %s", ev
->name
, channel
->channel
->name
);
131 /* Add event to event list */
132 cds_list_add(&event
->list
, &channel
->events_list
.head
);
133 DBG("Event %s enabled (fd: %d)", ev
->name
, event
->fd
);
142 * kernel_open_metadata
144 * Create kernel metadata, open from the kernel tracer and add it to the
147 int kernel_open_metadata(struct ltt_kernel_session
*session
)
150 struct ltt_kernel_metadata
*lkm
;
152 /* Allocate kernel metadata */
153 lkm
= trace_create_kernel_metadata();
158 /* Kernel tracer metadata creation */
159 ret
= kernctl_open_metadata(session
->fd
, &lkm
->conf
->attr
);
165 session
->metadata
= lkm
;
167 DBG("Kernel metadata opened (fd: %d and path: %s)", lkm
->fd
, lkm
->pathname
);
176 * kernel_start_session
178 * Start tracing session.
180 int kernel_start_session(struct ltt_kernel_session
*session
)
184 ret
= kernctl_start_session(session
->fd
);
186 perror("ioctl start session");
190 DBG("Kernel session started");
199 * kernel_wait_quiescent
201 * Make a kernel wait to make sure in-flight probe have completed.
203 void kernel_wait_quiescent(int fd
)
207 DBG("Kernel quiescent wait on %d", fd
);
209 ret
= kernctl_wait_quiescent(fd
);
211 perror("wait quiescent ioctl");
212 ERR("Kernel quiescent wait failed");
217 * kernel_metadata_flush_buffer
219 * Force flush buffer of metadata.
221 int kernel_metadata_flush_buffer(int fd
)
225 ret
= kernctl_buffer_flush(fd
);
227 ERR("Fail to flush metadata buffers %d (ret: %d", fd
, ret
);
234 * kernel_flush_buffer
236 * Force flush buffer for channel.
238 int kernel_flush_buffer(struct ltt_kernel_channel
*channel
)
241 struct ltt_kernel_stream
*stream
;
243 DBG("Flush buffer for channel %s", channel
->channel
->name
);
245 cds_list_for_each_entry(stream
, &channel
->stream_list
.head
, list
) {
246 DBG("Flushing channel stream %d", stream
->fd
);
247 ret
= kernctl_buffer_flush(stream
->fd
);
250 ERR("Fail to flush buffer for stream %d (ret: %d)",
259 * kernel_stop_session
261 * Stop tracing session.
263 int kernel_stop_session(struct ltt_kernel_session
*session
)
267 ret
= kernctl_stop_session(session
->fd
);
272 DBG("Kernel session stopped");
281 * kernel_open_channel_stream
283 * Open stream of channel, register it to the kernel tracer and add it
284 * to the stream list of the channel.
286 * Return the number of created stream. Else, a negative value.
288 int kernel_open_channel_stream(struct ltt_kernel_channel
*channel
)
291 struct ltt_kernel_stream
*lks
;
293 while ((ret
= kernctl_create_stream(channel
->fd
)) > 0) {
294 lks
= trace_create_kernel_stream();
301 ret
= asprintf(&lks
->pathname
, "%s/trace_%d",
302 channel
->pathname
, channel
->stream_count
);
304 perror("asprintf kernel create stream");
308 /* Add stream to channe stream list */
309 cds_list_add(&lks
->list
, &channel
->stream_list
.head
);
310 channel
->stream_count
++;
312 DBG("Kernel stream %d created (fd: %d, state: %d, path: %s)",
313 channel
->stream_count
, lks
->fd
, lks
->state
, lks
->pathname
);
316 return channel
->stream_count
;
323 * kernel_open_metadata_stream
325 * Open the metadata stream and set it to the kernel session.
327 int kernel_open_metadata_stream(struct ltt_kernel_session
*session
)
331 ret
= kernctl_create_stream(session
->metadata
->fd
);
333 perror("kernel create metadata stream");
337 DBG("Kernel metadata stream created (fd: %d)", ret
);
338 session
->metadata_stream_fd
= ret
;
349 * Get the event list from the kernel tracer and return that list in the CTF
352 ssize_t
kernel_list_events(int tracer_fd
, char **list
)
355 char *buf
, *line
= NULL
;
356 size_t nb
, nbmem
, total
= 0;
360 fd
= kernctl_tracepoint_list(tracer_fd
);
362 perror("kernel tracepoint list");
366 fp
= fdopen(fd
, "r");
368 perror("kernel tracepoint list fdopen");
373 * Init memory size counter
374 * See kernel-ctl.h for explanation of this value
376 nbmem
= KERNEL_EVENT_LIST_SIZE
;
379 while ((size
= getline(&line
, &nb
, fp
)) != -1) {
380 if (total
+ size
> nbmem
) {
381 DBG("Reallocating event list from %zd to %zd bytes", nbmem
,
382 total
+ size
+ KERNEL_EVENT_LIST_SIZE
);
383 /* Adding the default size again */
384 nbmem
= total
+ size
+ KERNEL_EVENT_LIST_SIZE
;
385 buf
= realloc(buf
, nbmem
);
387 perror("realloc list events");
391 memcpy(buf
+ total
, line
, size
);
397 DBG("Kernel list events done");
This page took 0.04755 seconds and 5 git commands to generate.