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 session
->kernel_session
= lks
;
58 session
->kern_session_count
++;
60 DBG("Kernel session created (fd: %d)", lks
->fd
);
69 * kernel_create_channel
71 * Create a kernel channel, register it to the kernel tracer and add it to the
74 int kernel_create_channel(struct ltt_kernel_session
*session
)
77 struct ltt_kernel_channel
*lkc
;
79 /* Allocate kernel channel */
80 lkc
= trace_create_kernel_channel();
85 /* Kernel tracer channel creation */
86 ret
= kernctl_create_channel(session
->fd
, lkc
->channel
);
88 perror("ioctl kernel create channel");
92 /* Setup the channel fd */
94 /* Add channel to session */
95 cds_list_add(&lkc
->list
, &session
->channel_list
.head
);
96 session
->channel_count
++;
98 DBG("Kernel channel created (fd: %d and path: %s)", lkc
->fd
, lkc
->pathname
);
107 * kernel_enable_event
109 * Create a kernel event, enable it to the kernel tracer and add it to the
110 * channel event list of the kernel session.
112 int kernel_enable_event(struct ltt_kernel_session
*session
, char *name
)
115 struct ltt_kernel_channel
*chan
;
116 struct ltt_kernel_event
*event
;
118 event
= trace_create_kernel_event(name
, LTTNG_KERNEL_TRACEPOINTS
);
123 cds_list_for_each_entry(chan
, &session
->channel_list
.head
, list
) {
124 ret
= kernctl_create_event(chan
->fd
, event
->event
);
130 /* Add event to event list */
131 cds_list_add(&event
->list
, &chan
->events_list
.head
);
132 DBG("Event %s enabled (fd: %d)", 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
);
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
);
189 DBG("Kernel session started");
198 * kernel_stop_session
200 * Stop tracing session.
202 int kernel_stop_session(struct ltt_kernel_session
*session
)
206 ret
= kernctl_stop_session(session
->fd
);
211 DBG("Kernel session stopped");
220 * kernel_create_channel_stream
222 * Create a stream for a channel, register it to the kernel tracer and add it
223 * to the stream list of the channel.
225 * Return the number of created stream. Else, a negative value.
227 int kernel_create_channel_stream(struct ltt_kernel_channel
*channel
)
230 struct ltt_kernel_stream
*lks
;
232 while ((ret
= kernctl_create_stream(channel
->fd
)) > 0) {
233 lks
= trace_create_kernel_stream();
240 ret
= asprintf(&lks
->pathname
, "%s/trace_%d",
241 channel
->pathname
, channel
->stream_count
);
243 perror("asprintf kernel create stream");
247 /* Add stream to channe stream list */
248 cds_list_add(&lks
->list
, &channel
->stream_list
.head
);
249 channel
->stream_count
++;
251 DBG("Kernel stream %d created (fd: %d, state: %d, path: %s)",
252 channel
->stream_count
, lks
->fd
, lks
->state
, lks
->pathname
);
255 return channel
->stream_count
;
262 * kernel_create_metadata_stream
264 * Create the metadata stream and set it to the kernel session.
266 int kernel_create_metadata_stream(struct ltt_kernel_session
*session
)
270 ret
= kernctl_create_stream(session
->metadata
->fd
);
272 perror("kernel create metadata stream");
276 DBG("Kernel metadata stream created (fd: %d)", ret
);
277 session
->metadata_stream_fd
= ret
;
This page took 0.034399 seconds and 4 git commands to generate.