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
);
96 CDS_INIT_LIST_HEAD(&lkc
->events_list
.head
);
98 cmd_ctx
->session
->kernel_session
->channel
= lkc
;
107 * kernel_enable_event
109 * Enable kernel event.
111 int kernel_enable_event(struct ltt_kernel_channel
*channel
, char *name
)
114 struct ltt_kernel_event
*event
;
115 struct lttng_kernel_event
*lke
;
117 event
= malloc(sizeof(struct ltt_kernel_event
));
118 lke
= malloc(sizeof(struct lttng_kernel_event
));
120 if (event
== NULL
|| lke
== NULL
) {
121 perror("kernel enable event malloc");
126 /* Setting up a kernel event */
127 strncpy(lke
->name
, name
, LTTNG_SYM_NAME_LEN
);
128 lke
->instrumentation
= LTTNG_KERNEL_TRACEPOINTS
;
131 ret
= kernctl_create_event(channel
->fd
, lke
);
136 /* Add event to event list */
137 cds_list_add(&event
->list
, &channel
->events_list
.head
);