Commit | Line | Data |
---|---|---|
d36b8583 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
d36b8583 DG |
7 | * |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
d36b8583 DG |
16 | */ |
17 | ||
18 | #define _GNU_SOURCE | |
19 | #include <popt.h> | |
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | #include <string.h> | |
23 | #include <sys/stat.h> | |
24 | #include <sys/types.h> | |
25 | #include <unistd.h> | |
5a0de755 | 26 | #include <inttypes.h> |
1cb514ce MD |
27 | #include <assert.h> |
28 | #include <ctype.h> | |
d36b8583 | 29 | |
c399183f | 30 | #include "../command.h" |
1cb514ce | 31 | #include "../utils.h" |
d36b8583 | 32 | |
42224349 | 33 | #include <src/common/sessiond-comm/sessiond-comm.h> |
70d0b120 | 34 | #include <src/common/utils.h> |
42224349 | 35 | |
d36b8583 | 36 | static char *opt_channels; |
5edd7e09 | 37 | static int opt_kernel; |
5440dc42 | 38 | static char *opt_session_name; |
d36b8583 | 39 | static int opt_userspace; |
d78d6610 | 40 | static struct lttng_channel chan; |
a79d84dd | 41 | static char *opt_output; |
7972aab2 DG |
42 | static int opt_buffer_uid; |
43 | static int opt_buffer_pid; | |
44 | static int opt_buffer_global; | |
d36b8583 DG |
45 | |
46 | enum { | |
47 | OPT_HELP = 1, | |
7d29a247 DG |
48 | OPT_DISCARD, |
49 | OPT_OVERWRITE, | |
50 | OPT_SUBBUF_SIZE, | |
51 | OPT_NUM_SUBBUF, | |
52 | OPT_SWITCH_TIMER, | |
53 | OPT_READ_TIMER, | |
d36b8583 | 54 | OPT_USERSPACE, |
679b4943 | 55 | OPT_LIST_OPTIONS, |
1624d5b7 JD |
56 | OPT_TRACEFILE_SIZE, |
57 | OPT_TRACEFILE_COUNT, | |
d36b8583 DG |
58 | }; |
59 | ||
cd80958d DG |
60 | static struct lttng_handle *handle; |
61 | ||
a79d84dd DG |
62 | const char *output_mmap = "mmap"; |
63 | const char *output_splice = "splice"; | |
64 | ||
d36b8583 DG |
65 | static struct poptOption long_options[] = { |
66 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
67 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, | |
5440dc42 | 68 | {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, |
d36b8583 | 69 | {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, |
d78d6610 | 70 | {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, |
7d29a247 DG |
71 | {"discard", 0, POPT_ARG_NONE, 0, OPT_DISCARD, 0, 0}, |
72 | {"overwrite", 0, POPT_ARG_NONE, 0, OPT_OVERWRITE, 0, 0}, | |
70d0b120 | 73 | {"subbuf-size", 0, POPT_ARG_STRING, 0, OPT_SUBBUF_SIZE, 0, 0}, |
1b579521 DG |
74 | {"num-subbuf", 0, POPT_ARG_INT, 0, OPT_NUM_SUBBUF, 0, 0}, |
75 | {"switch-timer", 0, POPT_ARG_INT, 0, OPT_SWITCH_TIMER, 0, 0}, | |
76 | {"read-timer", 0, POPT_ARG_INT, 0, OPT_READ_TIMER, 0, 0}, | |
679b4943 | 77 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, |
a79d84dd | 78 | {"output", 0, POPT_ARG_STRING, &opt_output, 0, 0, 0}, |
7972aab2 DG |
79 | {"buffers-uid", 0, POPT_ARG_VAL, &opt_buffer_uid, 1, 0, 0}, |
80 | {"buffers-pid", 0, POPT_ARG_VAL, &opt_buffer_pid, 1, 0, 0}, | |
81 | {"buffers-global", 0, POPT_ARG_VAL, &opt_buffer_global, 1, 0, 0}, | |
1624d5b7 JD |
82 | {"tracefile-size", 'C', POPT_ARG_INT, 0, OPT_TRACEFILE_SIZE, 0, 0}, |
83 | {"tracefile-count", 'W', POPT_ARG_INT, 0, OPT_TRACEFILE_COUNT, 0, 0}, | |
d36b8583 DG |
84 | {0, 0, 0, 0, 0, 0, 0} |
85 | }; | |
86 | ||
87 | /* | |
88 | * usage | |
89 | */ | |
90 | static void usage(FILE *ofp) | |
91 | { | |
05be3802 | 92 | fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] (-u | -k) [OPTIONS]\n"); |
d36b8583 | 93 | fprintf(ofp, "\n"); |
32a6298d | 94 | fprintf(ofp, "Options:\n"); |
7d29a247 | 95 | fprintf(ofp, " -h, --help Show this help\n"); |
679b4943 | 96 | fprintf(ofp, " --list-options Simple listing of options\n"); |
32a6298d | 97 | fprintf(ofp, " -s, --session NAME Apply to session name\n"); |
27221701 | 98 | fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n"); |
27221701 | 99 | fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); |
7d29a247 DG |
100 | fprintf(ofp, "\n"); |
101 | fprintf(ofp, "Channel options:\n"); | |
cabd9892 MD |
102 | fprintf(ofp, " --discard Discard event when buffers are full%s\n", |
103 | DEFAULT_CHANNEL_OVERWRITE ? "" : " (default)"); | |
104 | fprintf(ofp, " --overwrite Flight recorder mode%s\n", | |
105 | DEFAULT_CHANNEL_OVERWRITE ? " (default)" : ""); | |
70d0b120 | 106 | fprintf(ofp, " --subbuf-size SIZE Subbuffer size in bytes {+k,+M,+G}\n"); |
0a9c6494 DG |
107 | fprintf(ofp, " (default UST uid: %zu, UST pid: %zu, kernel: %zu, metadata: %zu)\n", |
108 | default_get_ust_uid_channel_subbuf_size(), | |
109 | default_get_ust_pid_channel_subbuf_size(), | |
110 | default_get_kernel_channel_subbuf_size(), | |
111 | default_get_metadata_subbuf_size()); | |
1cb514ce | 112 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
cc62c0c0 | 113 | fprintf(ofp, " --num-subbuf NUM Number of subbufers\n"); |
0a9c6494 DG |
114 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", |
115 | DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM, DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM, | |
116 | DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM, DEFAULT_METADATA_SUBBUF_NUM); | |
1cb514ce | 117 | fprintf(ofp, " Rounded up to the next power of 2.\n"); |
0a9c6494 DG |
118 | fprintf(ofp, " --switch-timer USEC Switch timer interval in usec\n"); |
119 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", | |
120 | DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER, DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER, | |
121 | DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER, DEFAULT_METADATA_SWITCH_TIMER); | |
122 | fprintf(ofp, " --read-timer USEC Read timer interval in usec.\n"); | |
123 | fprintf(ofp, " (default UST uid: %u, UST pid: %u, kernel: %u, metadata: %u)\n", | |
124 | DEFAULT_UST_UID_CHANNEL_READ_TIMER, DEFAULT_UST_UID_CHANNEL_READ_TIMER, | |
125 | DEFAULT_KERNEL_CHANNEL_READ_TIMER, DEFAULT_METADATA_READ_TIMER); | |
a79d84dd DG |
126 | fprintf(ofp, " --output TYPE Channel output type (Values: %s, %s)\n", |
127 | output_mmap, output_splice); | |
0a9c6494 DG |
128 | fprintf(ofp, " (default UST uid: %s, UST pid: %s, kernel: %s, metadata: %s)\n", |
129 | DEFAULT_UST_UID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
130 | DEFAULT_UST_PID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
131 | DEFAULT_KERNEL_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, | |
132 | DEFAULT_METADATA_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice); | |
05c35276 DG |
133 | fprintf(ofp, " --buffers-uid Use per UID buffer (-u only)\n"); |
134 | fprintf(ofp, " --buffers-pid Use per PID buffer (-u only)\n"); | |
7972aab2 | 135 | fprintf(ofp, " --buffers-global Use shared buffer for the whole system (-k only)\n"); |
1624d5b7 | 136 | fprintf(ofp, " -C, --tracefile-size SIZE\n"); |
0a9c6494 DG |
137 | fprintf(ofp, " Maximum size of each tracefile within a stream (in bytes). 0 means unlimited.\n"); |
138 | fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_SIZE); | |
c0684a0d MD |
139 | fprintf(ofp, " Note: traces generated with this option may inaccurately report\n"); |
140 | fprintf(ofp, " discarded events as per CTF 1.8.\n"); | |
1624d5b7 JD |
141 | fprintf(ofp, " -W, --tracefile-count COUNT\n"); |
142 | fprintf(ofp, " Used in conjunction with -C option, this will limit the number\n"); | |
0a9c6494 DG |
143 | fprintf(ofp, " of files created to the specified count. 0 means unlimited.\n"); |
144 | fprintf(ofp, " (default: %u)\n", DEFAULT_CHANNEL_TRACEFILE_COUNT); | |
d36b8583 DG |
145 | fprintf(ofp, "\n"); |
146 | } | |
147 | ||
5edd7e09 DG |
148 | /* |
149 | * Set default attributes depending on those already defined from the command | |
150 | * line. | |
151 | */ | |
152 | static void set_default_attr(struct lttng_domain *dom) | |
153 | { | |
154 | struct lttng_channel_attr default_attr; | |
155 | ||
156 | /* Set attributes */ | |
157 | lttng_channel_set_default_attr(dom, &default_attr); | |
158 | ||
159 | if (chan.attr.overwrite == -1) { | |
160 | chan.attr.overwrite = default_attr.overwrite; | |
161 | } | |
162 | if (chan.attr.subbuf_size == -1) { | |
163 | chan.attr.subbuf_size = default_attr.subbuf_size; | |
164 | } | |
165 | if (chan.attr.num_subbuf == -1) { | |
166 | chan.attr.num_subbuf = default_attr.num_subbuf; | |
167 | } | |
168 | if (chan.attr.switch_timer_interval == -1) { | |
169 | chan.attr.switch_timer_interval = default_attr.switch_timer_interval; | |
170 | } | |
171 | if (chan.attr.read_timer_interval == -1) { | |
172 | chan.attr.read_timer_interval = default_attr.read_timer_interval; | |
173 | } | |
109be0da | 174 | if ((int) chan.attr.output == -1) { |
5edd7e09 DG |
175 | chan.attr.output = default_attr.output; |
176 | } | |
1624d5b7 JD |
177 | if (chan.attr.tracefile_count == -1) { |
178 | chan.attr.tracefile_count = default_attr.tracefile_count; | |
179 | } | |
180 | if (chan.attr.tracefile_size == -1) { | |
181 | chan.attr.tracefile_size = default_attr.tracefile_size; | |
182 | } | |
5edd7e09 DG |
183 | } |
184 | ||
d36b8583 | 185 | /* |
0fdd1e2c | 186 | * Adding channel using the lttng API. |
d36b8583 | 187 | */ |
cd80958d | 188 | static int enable_channel(char *session_name) |
d36b8583 | 189 | { |
ae856491 | 190 | int ret = CMD_SUCCESS, warn = 0; |
d36b8583 | 191 | char *channel_name; |
7d29a247 | 192 | struct lttng_domain dom; |
d36b8583 | 193 | |
441c16a7 MD |
194 | memset(&dom, 0, sizeof(dom)); |
195 | ||
d78d6610 | 196 | /* Create lttng domain */ |
7d29a247 DG |
197 | if (opt_kernel) { |
198 | dom.type = LTTNG_DOMAIN_KERNEL; | |
7972aab2 | 199 | dom.buf_type = LTTNG_BUFFER_GLOBAL; |
88c5f0d8 DG |
200 | if (opt_buffer_uid || opt_buffer_pid) { |
201 | ERR("Buffer type not supported for domain -k"); | |
202 | ret = CMD_ERROR; | |
203 | goto error; | |
204 | } | |
d78d6610 | 205 | } else if (opt_userspace) { |
f6a9efaa | 206 | dom.type = LTTNG_DOMAIN_UST; |
8692d4e5 DG |
207 | if (opt_buffer_pid) { |
208 | dom.buf_type = LTTNG_BUFFER_PER_PID; | |
7972aab2 | 209 | } else { |
88c5f0d8 DG |
210 | if (opt_buffer_global) { |
211 | ERR("Buffer type not supported for domain -u"); | |
212 | ret = CMD_ERROR; | |
213 | goto error; | |
214 | } | |
8692d4e5 | 215 | dom.buf_type = LTTNG_BUFFER_PER_UID; |
7972aab2 | 216 | } |
0fdd1e2c | 217 | } else { |
b9dfb167 | 218 | print_missing_domain(); |
d16c1a4c | 219 | ret = CMD_ERROR; |
0fdd1e2c | 220 | goto error; |
7d29a247 DG |
221 | } |
222 | ||
5edd7e09 DG |
223 | set_default_attr(&dom); |
224 | ||
d16dee89 DG |
225 | if (chan.attr.tracefile_size == 0 && chan.attr.tracefile_count) { |
226 | ERR("Missing option --tracefile-size. " | |
227 | "A file count without a size won't do anything."); | |
228 | ret = CMD_ERROR; | |
229 | goto error; | |
230 | } | |
231 | ||
1624d5b7 JD |
232 | if ((chan.attr.tracefile_size > 0) && |
233 | (chan.attr.tracefile_size < chan.attr.subbuf_size)) { | |
de65565a | 234 | WARN("Tracefile size rounded up from (%" PRIu64 ") to subbuffer size (%" PRIu64 ")", |
1624d5b7 | 235 | chan.attr.tracefile_size, chan.attr.subbuf_size); |
de65565a | 236 | chan.attr.tracefile_size = chan.attr.subbuf_size; |
1624d5b7 JD |
237 | } |
238 | ||
a79d84dd DG |
239 | /* Setting channel output */ |
240 | if (opt_output) { | |
241 | if (!strncmp(output_mmap, opt_output, strlen(output_mmap))) { | |
242 | chan.attr.output = LTTNG_EVENT_MMAP; | |
243 | } else if (!strncmp(output_splice, opt_output, strlen(output_splice))) { | |
244 | chan.attr.output = LTTNG_EVENT_SPLICE; | |
245 | } else { | |
246 | ERR("Unknown output type %s. Possible values are: %s, %s\n", | |
247 | opt_output, output_mmap, output_splice); | |
248 | usage(stderr); | |
249 | ret = CMD_ERROR; | |
250 | goto error; | |
251 | } | |
252 | } | |
253 | ||
cd80958d DG |
254 | handle = lttng_create_handle(session_name, &dom); |
255 | if (handle == NULL) { | |
256 | ret = -1; | |
257 | goto error; | |
258 | } | |
259 | ||
0fdd1e2c | 260 | /* Strip channel list (format: chan1,chan2,...) */ |
d36b8583 DG |
261 | channel_name = strtok(opt_channels, ","); |
262 | while (channel_name != NULL) { | |
0fdd1e2c DG |
263 | /* Copy channel name and normalize it */ |
264 | strncpy(chan.name, channel_name, NAME_MAX); | |
265 | chan.name[NAME_MAX - 1] = '\0'; | |
266 | ||
267 | DBG("Enabling channel %s", channel_name); | |
268 | ||
269 | ret = lttng_enable_channel(handle, &chan); | |
270 | if (ret < 0) { | |
42224349 | 271 | switch (-ret) { |
f73fabfd DG |
272 | case LTTNG_ERR_KERN_CHAN_EXIST: |
273 | case LTTNG_ERR_UST_CHAN_EXIST: | |
b9dfb167 | 274 | case LTTNG_ERR_CHAN_EXIST: |
88c5f0d8 | 275 | WARN("Channel %s: %s (session %s)", channel_name, |
42224349 DG |
276 | lttng_strerror(ret), session_name); |
277 | goto error; | |
278 | default: | |
279 | ERR("Channel %s: %s (session %s)", channel_name, | |
280 | lttng_strerror(ret), session_name); | |
281 | break; | |
282 | } | |
ae856491 | 283 | warn = 1; |
d36b8583 | 284 | } else { |
7885e399 | 285 | MSG("%s channel %s enabled for session %s", |
b9dfb167 | 286 | get_domain_str(dom.type), channel_name, session_name); |
d36b8583 DG |
287 | } |
288 | ||
289 | /* Next event */ | |
290 | channel_name = strtok(NULL, ","); | |
291 | } | |
292 | ||
ae856491 DG |
293 | ret = CMD_SUCCESS; |
294 | ||
d36b8583 | 295 | error: |
ae856491 DG |
296 | if (warn) { |
297 | ret = CMD_WARNING; | |
298 | } | |
299 | ||
cd80958d DG |
300 | lttng_destroy_handle(handle); |
301 | ||
d36b8583 DG |
302 | return ret; |
303 | } | |
304 | ||
305 | /* | |
0fdd1e2c | 306 | * Default value for channel configuration. |
7d29a247 DG |
307 | */ |
308 | static void init_channel_config(void) | |
309 | { | |
5edd7e09 DG |
310 | /* |
311 | * Put -1 everywhere so we can identify those set by the command line and | |
312 | * those needed to be set by the default values. | |
313 | */ | |
314 | memset(&chan.attr, -1, sizeof(chan.attr)); | |
7d29a247 DG |
315 | } |
316 | ||
317 | /* | |
0fdd1e2c | 318 | * Add channel to trace session |
d36b8583 DG |
319 | */ |
320 | int cmd_enable_channels(int argc, const char **argv) | |
321 | { | |
ca1c3607 | 322 | int opt, ret = CMD_SUCCESS; |
d36b8583 | 323 | static poptContext pc; |
cd80958d | 324 | char *session_name = NULL; |
70d0b120 | 325 | char *opt_arg = NULL; |
d36b8583 | 326 | |
7d29a247 DG |
327 | init_channel_config(); |
328 | ||
d36b8583 DG |
329 | pc = poptGetContext(NULL, argc, argv, long_options, 0); |
330 | poptReadDefaultConfig(pc, 0); | |
331 | ||
332 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
333 | switch (opt) { | |
334 | case OPT_HELP: | |
ca1c3607 | 335 | usage(stdout); |
d36b8583 | 336 | goto end; |
7d29a247 DG |
337 | case OPT_DISCARD: |
338 | chan.attr.overwrite = 0; | |
339 | DBG("Channel set to discard"); | |
340 | break; | |
341 | case OPT_OVERWRITE: | |
342 | chan.attr.overwrite = 1; | |
343 | DBG("Channel set to overwrite"); | |
344 | break; | |
345 | case OPT_SUBBUF_SIZE: | |
1cb514ce MD |
346 | { |
347 | uint64_t rounded_size; | |
348 | int order; | |
349 | ||
70d0b120 SM |
350 | /* Parse the size */ |
351 | opt_arg = poptGetOptArg(pc); | |
1cb514ce MD |
352 | if (utils_parse_size_suffix(opt_arg, &chan.attr.subbuf_size) < 0 || !chan.attr.subbuf_size) { |
353 | ERR("Wrong value in --subbuf-size parameter: %s", opt_arg); | |
70d0b120 SM |
354 | ret = CMD_ERROR; |
355 | goto end; | |
356 | } | |
357 | ||
1cb514ce MD |
358 | order = get_count_order_u64(chan.attr.subbuf_size); |
359 | assert(order >= 0); | |
360 | rounded_size = 1ULL << order; | |
06c0da96 DG |
361 | if (rounded_size < chan.attr.subbuf_size) { |
362 | ERR("The subbuf size (%" PRIu64 ") is rounded and overflows!", | |
363 | chan.attr.subbuf_size); | |
364 | ret = CMD_ERROR; | |
365 | goto end; | |
366 | } | |
367 | ||
1cb514ce MD |
368 | if (rounded_size != chan.attr.subbuf_size) { |
369 | WARN("The subbuf size (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
370 | chan.attr.subbuf_size, rounded_size); | |
371 | chan.attr.subbuf_size = rounded_size; | |
70d0b120 SM |
372 | } |
373 | ||
1cb514ce MD |
374 | /* Should now be power of 2 */ |
375 | assert(!((chan.attr.subbuf_size - 1) & chan.attr.subbuf_size)); | |
376 | ||
5a0de755 | 377 | DBG("Channel subbuf size set to %" PRIu64, chan.attr.subbuf_size); |
7d29a247 | 378 | break; |
1cb514ce | 379 | } |
7d29a247 | 380 | case OPT_NUM_SUBBUF: |
1cb514ce MD |
381 | { |
382 | uint64_t rounded_size; | |
383 | int order; | |
384 | ||
16068db5 | 385 | errno = 0; |
1cb514ce MD |
386 | opt_arg = poptGetOptArg(pc); |
387 | chan.attr.num_subbuf = strtoull(opt_arg, NULL, 0); | |
388 | if (errno != 0 || !chan.attr.num_subbuf || !isdigit(opt_arg[0])) { | |
389 | ERR("Wrong value in --num-subbuf parameter: %s", opt_arg); | |
16068db5 MD |
390 | ret = CMD_ERROR; |
391 | goto end; | |
392 | } | |
393 | ||
1cb514ce MD |
394 | order = get_count_order_u64(chan.attr.num_subbuf); |
395 | assert(order >= 0); | |
396 | rounded_size = 1ULL << order; | |
e123b80c | 397 | if (rounded_size < chan.attr.num_subbuf) { |
06c0da96 DG |
398 | ERR("The number of subbuffers (%" PRIu64 ") is rounded and overflows!", |
399 | chan.attr.num_subbuf); | |
400 | ret = CMD_ERROR; | |
401 | goto end; | |
402 | } | |
403 | ||
1cb514ce MD |
404 | if (rounded_size != chan.attr.num_subbuf) { |
405 | WARN("The number of subbuffers (%" PRIu64 ") is rounded to the next power of 2 (%" PRIu64 ")", | |
406 | chan.attr.num_subbuf, rounded_size); | |
407 | chan.attr.num_subbuf = rounded_size; | |
408 | } | |
409 | ||
410 | /* Should now be power of 2 */ | |
411 | assert(!((chan.attr.num_subbuf - 1) & chan.attr.num_subbuf)); | |
412 | ||
5a0de755 | 413 | DBG("Channel subbuf num set to %" PRIu64, chan.attr.num_subbuf); |
7d29a247 | 414 | break; |
1cb514ce | 415 | } |
7d29a247 | 416 | case OPT_SWITCH_TIMER: |
16068db5 MD |
417 | { |
418 | unsigned long v; | |
419 | ||
420 | errno = 0; | |
1cb514ce MD |
421 | opt_arg = poptGetOptArg(pc); |
422 | v = strtoul(opt_arg, NULL, 0); | |
423 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
424 | ERR("Wrong value in --switch-timer parameter: %s", opt_arg); | |
16068db5 MD |
425 | ret = CMD_ERROR; |
426 | goto end; | |
427 | } | |
428 | if (v != (uint32_t) v) { | |
429 | ERR("32-bit overflow in --switch-timer parameter: %s", opt_arg); | |
430 | ret = CMD_ERROR; | |
431 | goto end; | |
432 | } | |
433 | chan.attr.switch_timer_interval = (uint32_t) v; | |
7d29a247 DG |
434 | DBG("Channel switch timer interval set to %d", chan.attr.switch_timer_interval); |
435 | break; | |
16068db5 | 436 | } |
7d29a247 | 437 | case OPT_READ_TIMER: |
16068db5 MD |
438 | { |
439 | unsigned long v; | |
440 | ||
441 | errno = 0; | |
1cb514ce MD |
442 | opt_arg = poptGetOptArg(pc); |
443 | v = strtoul(opt_arg, NULL, 0); | |
444 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
445 | ERR("Wrong value in --read-timer parameter: %s", opt_arg); | |
16068db5 MD |
446 | ret = CMD_ERROR; |
447 | goto end; | |
448 | } | |
449 | if (v != (uint32_t) v) { | |
450 | ERR("32-bit overflow in --read-timer parameter: %s", opt_arg); | |
451 | ret = CMD_ERROR; | |
452 | goto end; | |
453 | } | |
454 | chan.attr.read_timer_interval = (uint32_t) v; | |
7d29a247 | 455 | DBG("Channel read timer interval set to %d", chan.attr.read_timer_interval); |
d36b8583 | 456 | break; |
16068db5 | 457 | } |
eeac7d46 MD |
458 | case OPT_USERSPACE: |
459 | opt_userspace = 1; | |
eeac7d46 | 460 | break; |
1624d5b7 | 461 | case OPT_TRACEFILE_SIZE: |
1cb514ce | 462 | opt_arg = poptGetOptArg(pc); |
16068db5 | 463 | if (utils_parse_size_suffix(opt_arg, &chan.attr.tracefile_size) < 0) { |
1cb514ce | 464 | ERR("Wrong value in --tracefile-size parameter: %s", opt_arg); |
16068db5 MD |
465 | ret = CMD_ERROR; |
466 | goto end; | |
467 | } | |
1624d5b7 JD |
468 | DBG("Maximum tracefile size set to %" PRIu64, |
469 | chan.attr.tracefile_size); | |
470 | break; | |
471 | case OPT_TRACEFILE_COUNT: | |
16068db5 MD |
472 | { |
473 | unsigned long v; | |
474 | ||
475 | errno = 0; | |
1cb514ce MD |
476 | opt_arg = poptGetOptArg(pc); |
477 | v = strtoul(opt_arg, NULL, 0); | |
478 | if (errno != 0 || !isdigit(opt_arg[0])) { | |
479 | ERR("Wrong value in --tracefile-count parameter: %s", opt_arg); | |
16068db5 MD |
480 | ret = CMD_ERROR; |
481 | goto end; | |
482 | } | |
483 | if (v != (uint32_t) v) { | |
484 | ERR("32-bit overflow in --tracefile-count parameter: %s", opt_arg); | |
485 | ret = CMD_ERROR; | |
486 | goto end; | |
487 | } | |
488 | chan.attr.tracefile_count = (uint32_t) v; | |
1624d5b7 JD |
489 | DBG("Maximum tracefile count set to %" PRIu64, |
490 | chan.attr.tracefile_count); | |
491 | break; | |
16068db5 | 492 | } |
679b4943 SM |
493 | case OPT_LIST_OPTIONS: |
494 | list_cmd_options(stdout, long_options); | |
679b4943 | 495 | goto end; |
d36b8583 DG |
496 | default: |
497 | usage(stderr); | |
498 | ret = CMD_UNDEFINED; | |
499 | goto end; | |
500 | } | |
501 | } | |
502 | ||
503 | opt_channels = (char*) poptGetArg(pc); | |
504 | if (opt_channels == NULL) { | |
7d29a247 | 505 | ERR("Missing channel name.\n"); |
d36b8583 | 506 | usage(stderr); |
ca1c3607 | 507 | ret = CMD_ERROR; |
d36b8583 DG |
508 | goto end; |
509 | } | |
510 | ||
cd80958d DG |
511 | if (!opt_session_name) { |
512 | session_name = get_session_name(); | |
513 | if (session_name == NULL) { | |
ca1c3607 | 514 | ret = CMD_ERROR; |
cd80958d DG |
515 | goto end; |
516 | } | |
517 | } else { | |
518 | session_name = opt_session_name; | |
519 | } | |
520 | ||
521 | ret = enable_channel(session_name); | |
d36b8583 DG |
522 | |
523 | end: | |
5853fd43 DG |
524 | if (!opt_session_name && session_name) { |
525 | free(session_name); | |
526 | } | |
ca1c3607 | 527 | poptFreeContext(pc); |
d36b8583 DG |
528 | return ret; |
529 | } |