Commit | Line | Data |
---|---|---|
20fe2104 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 | |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
17 | */ | |
18 | ||
19 | #include <errno.h> | |
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
f34daff7 | 22 | #include <string.h> |
20fe2104 DG |
23 | |
24 | #include "ltt-sessiond.h" | |
25 | #include "libkernelctl.h" | |
26 | #include "kernel-ctl.h" | |
27 | #include "trace.h" | |
28 | ||
29 | /* | |
30 | * kernel_create_session | |
31 | * | |
32 | * Create a new kernel session using the command context session. | |
33 | */ | |
34 | int kernel_create_session(struct command_ctx *cmd_ctx, int tracer_fd) | |
35 | { | |
36 | int ret; | |
37 | struct ltt_kernel_session *lks; | |
38 | ||
39 | /* Allocate a new kernel session */ | |
40 | lks = malloc(sizeof(struct ltt_kernel_session)); | |
41 | if (lks == NULL) { | |
42 | perror("kernel session malloc"); | |
43 | ret = -errno; | |
44 | goto error; | |
45 | } | |
46 | ||
47 | ret = kernctl_create_session(tracer_fd); | |
48 | if (ret < 0) { | |
49 | goto error; | |
50 | } | |
51 | ||
52 | /* Assigning session fd and to the command context */ | |
53 | lks->fd = ret; | |
54 | cmd_ctx->session->kernel_session = lks; | |
55 | cmd_ctx->session->kern_session_count++; | |
56 | ||
57 | return 0; | |
58 | ||
59 | error: | |
60 | return ret; | |
61 | } | |
62 | ||
63 | /* | |
64 | * kernel_create_channel | |
65 | * | |
66 | * Create a kernel channel within the kernel session. | |
67 | */ | |
68 | int kernel_create_channel(struct command_ctx *cmd_ctx) | |
69 | { | |
70 | int ret; | |
71 | struct ltt_kernel_channel *lkc; | |
9cb98350 | 72 | struct lttng_kernel_channel *chan; |
20fe2104 DG |
73 | |
74 | lkc = malloc(sizeof(struct ltt_kernel_channel)); | |
9cb98350 | 75 | chan = malloc(sizeof(struct lttng_kernel_channel)); |
20fe2104 DG |
76 | |
77 | if (lkc == NULL || chan == NULL) { | |
78 | perror("kernel channel malloc"); | |
79 | ret = -errno; | |
80 | goto error; | |
81 | } | |
82 | ||
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; | |
88 | ||
89 | ret = kernctl_create_channel(cmd_ctx->session->kernel_session->fd, chan); | |
90 | if (ret < 0) { | |
aaf26714 | 91 | perror("ioctl create channel"); |
20fe2104 DG |
92 | goto error; |
93 | } | |
94 | ||
95 | lkc->fd = ret; | |
96 | lkc->channel = chan; | |
97 | CDS_INIT_LIST_HEAD(&lkc->events_list.head); | |
98 | ||
99 | cmd_ctx->session->kernel_session->channel = lkc; | |
100 | ||
101 | return 0; | |
102 | ||
103 | error: | |
104 | return ret; | |
105 | } | |
f34daff7 DG |
106 | |
107 | /* | |
108 | * kernel_enable_event | |
109 | * | |
110 | * Enable kernel event. | |
111 | */ | |
112 | int kernel_enable_event(struct ltt_kernel_channel *channel, char *name) | |
113 | { | |
114 | int ret; | |
115 | struct ltt_kernel_event *event; | |
116 | struct lttng_kernel_event *lke; | |
117 | ||
118 | event = malloc(sizeof(struct ltt_kernel_event)); | |
119 | lke = malloc(sizeof(struct lttng_kernel_event)); | |
120 | ||
121 | if (event == NULL || lke == NULL) { | |
122 | perror("kernel enable event malloc"); | |
123 | ret = -errno; | |
124 | goto error; | |
125 | } | |
126 | ||
127 | /* Setting up a kernel event */ | |
128 | strncpy(lke->name, name, LTTNG_SYM_NAME_LEN); | |
129 | lke->instrumentation = LTTNG_KERNEL_TRACEPOINTS; | |
130 | event->event = lke; | |
131 | ||
132 | ret = kernctl_create_event(channel->fd, lke); | |
133 | if (ret < 0) { | |
134 | goto error; | |
135 | } | |
136 | ||
137 | /* Add event to event list */ | |
138 | cds_list_add(&event->list, &channel->events_list.head); | |
139 | ||
140 | return 0; | |
141 | ||
142 | error: | |
143 | return ret; | |
144 | } | |
aaf26714 DG |
145 | |
146 | /* | |
147 | * kernel_open_metadata | |
148 | * | |
149 | * Open metadata stream. | |
150 | */ | |
151 | int kernel_open_metadata(struct ltt_kernel_session *session) | |
152 | { | |
153 | int ret; | |
154 | struct ltt_kernel_metadata *lkm; | |
155 | struct lttng_kernel_channel *conf; | |
156 | ||
157 | lkm = malloc(sizeof(struct ltt_kernel_metadata)); | |
158 | conf = malloc(sizeof(struct lttng_kernel_channel)); | |
159 | ||
160 | if (lkm == NULL || conf == NULL) { | |
161 | perror("kernel open metadata malloc"); | |
162 | ret = -errno; | |
163 | goto error; | |
164 | } | |
165 | ||
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; | |
171 | ||
172 | ret = kernctl_open_metadata(session->fd, conf); | |
173 | if (ret < 0) { | |
174 | goto error; | |
175 | } | |
176 | ||
177 | session->metadata = lkm; | |
178 | session->metadata->fd = ret; | |
179 | session->metadata->conf = conf; | |
180 | ||
181 | return 0; | |
182 | ||
183 | error: | |
184 | return ret; | |
185 | } |