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.
24 #include "ltt-sessiond.h"
25 #include "libkernelctl.h"
26 #include "kernel-ctl.h"
30 * kernel_create_session
32 * Create a new kernel session using the command context session.
34 int kernel_create_session(struct command_ctx
*cmd_ctx
, int tracer_fd
)
37 struct ltt_kernel_session
*lks
;
39 /* Allocate a new kernel session */
40 lks
= malloc(sizeof(struct ltt_kernel_session
));
42 perror("kernel session malloc");
47 ret
= kernctl_create_session(tracer_fd
);
52 /* Assigning session fd and to the command context */
54 cmd_ctx
->session
->kernel_session
= lks
;
55 cmd_ctx
->session
->kern_session_count
++;
64 * kernel_create_channel
66 * Create a kernel channel within the kernel session.
68 int kernel_create_channel(struct command_ctx
*cmd_ctx
)
71 struct ltt_kernel_channel
*lkc
;
72 struct lttng_kernel_channel
*chan
;
74 lkc
= malloc(sizeof(struct ltt_kernel_channel
));
75 chan
= malloc(sizeof(struct lttng_kernel_channel
));
77 if (lkc
== NULL
|| chan
== NULL
) {
78 perror("kernel channel malloc");
83 chan
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
84 chan
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
85 chan
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
86 chan
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
87 chan
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
89 ret
= kernctl_create_channel(cmd_ctx
->session
->kernel_session
->fd
, chan
);
91 perror("ioctl create channel");
97 CDS_INIT_LIST_HEAD(&lkc
->events_list
.head
);
99 cmd_ctx
->session
->kernel_session
->channel
= lkc
;
108 * kernel_enable_event
110 * Enable kernel event.
112 int kernel_enable_event(struct ltt_kernel_channel
*channel
, char *name
)
115 struct ltt_kernel_event
*event
;
116 struct lttng_kernel_event
*lke
;
118 event
= malloc(sizeof(struct ltt_kernel_event
));
119 lke
= malloc(sizeof(struct lttng_kernel_event
));
121 if (event
== NULL
|| lke
== NULL
) {
122 perror("kernel enable event malloc");
127 /* Setting up a kernel event */
128 strncpy(lke
->name
, name
, LTTNG_SYM_NAME_LEN
);
129 lke
->instrumentation
= LTTNG_KERNEL_TRACEPOINTS
;
132 ret
= kernctl_create_event(channel
->fd
, lke
);
137 /* Add event to event list */
138 cds_list_add(&event
->list
, &channel
->events_list
.head
);
147 * kernel_open_metadata
149 * Open metadata stream.
151 int kernel_open_metadata(struct ltt_kernel_session
*session
)
154 struct ltt_kernel_metadata
*lkm
;
155 struct lttng_kernel_channel
*conf
;
157 lkm
= malloc(sizeof(struct ltt_kernel_metadata
));
158 conf
= malloc(sizeof(struct lttng_kernel_channel
));
160 if (lkm
== NULL
|| conf
== NULL
) {
161 perror("kernel open metadata malloc");
166 conf
->overwrite
= DEFAULT_KERNEL_OVERWRITE
;
167 conf
->subbuf_size
= DEFAULT_KERNEL_SUBBUF_SIZE
;
168 conf
->num_subbuf
= DEFAULT_KERNEL_SUBBUF_NUM
;
169 conf
->switch_timer_interval
= DEFAULT_KERNEL_SWITCH_TIMER
;
170 conf
->read_timer_interval
= DEFAULT_KERNEL_READ_TIMER
;
172 ret
= kernctl_open_metadata(session
->fd
, conf
);
177 session
->metadata
= lkm
;
178 session
->metadata
->fd
= ret
;
179 session
->metadata
->conf
= conf
;