2cdb6fcb |
1 | /* lttctl |
2 | * |
3 | * Linux Trace Toolkit Control |
4 | * |
5 | * Small program that controls LTT through libltt. |
6 | * |
7 | * Copyright 2005 - |
8 | * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca> |
9 | */ |
10 | |
4e4d11b3 |
11 | #ifdef HAVE_CONFIG_H |
12 | #include <config.h> |
13 | #endif |
14 | |
5cec0a15 |
15 | #include <liblttctl/lttctl.h> |
5adba60f |
16 | #include <errno.h> |
17 | #include <stdio.h> |
18 | #include <stdlib.h> |
19 | #include <sys/types.h> |
86a65fdb |
20 | #include <sys/wait.h> |
5adba60f |
21 | #include <unistd.h> |
22 | #include <signal.h> |
d5fbdb60 |
23 | #include <dirent.h> |
24 | #include <string.h> |
25 | #include <sys/stat.h> |
26 | |
27 | /* Buffer for file copy : 4k seems optimal. */ |
2312de30 |
28 | #define BUF_SIZE 4096 |
2cdb6fcb |
29 | |
5adba60f |
30 | enum trace_ctl_op { |
24331c3d |
31 | CTL_OP_CREATE_START, |
5adba60f |
32 | CTL_OP_CREATE, |
33 | CTL_OP_DESTROY, |
24331c3d |
34 | CTL_OP_STOP_DESTROY, |
5adba60f |
35 | CTL_OP_START, |
36 | CTL_OP_STOP, |
37 | CTL_OP_DAEMON, |
d24c12e7 |
38 | CTL_OP_DAEMON_HYBRID_FINISH, |
129fd24a |
39 | CTL_OP_DESCRIPTION, |
5adba60f |
40 | CTL_OP_NONE |
41 | }; |
2cdb6fcb |
42 | |
5adba60f |
43 | static char *trace_name = NULL; |
313b3771 |
44 | static char *trace_type = "relay"; |
5adba60f |
45 | static char *mode_name = NULL; |
d24c12e7 |
46 | static unsigned subbuf_size_low = 0; |
47 | static unsigned n_subbufs_low = 0; |
48 | static unsigned subbuf_size_med = 0; |
49 | static unsigned n_subbufs_med = 0; |
50 | static unsigned subbuf_size_high = 0; |
51 | static unsigned n_subbufs_high = 0; |
45653836 |
52 | static unsigned append_trace = 0; |
5adba60f |
53 | static enum trace_mode mode = LTT_TRACE_NORMAL; |
54 | static enum trace_ctl_op op = CTL_OP_NONE; |
55 | static char *channel_root = NULL; |
56 | static char *trace_root = NULL; |
22acb617 |
57 | static char *num_threads = "1"; |
5adba60f |
58 | |
5adba60f |
59 | /* Args : |
60 | * |
61 | */ |
62 | void show_arguments(void) |
63 | { |
64 | printf("Please use the following arguments :\n"); |
65 | printf("\n"); |
2299770f |
66 | printf("-n name Name of the trace.\n"); |
67 | printf("-b Create trace channels and start tracing (no daemon).\n"); |
68 | printf("-c Create trace channels.\n"); |
d24c12e7 |
69 | printf("-m mode Normal, flight recorder or hybrid mode.\n"); |
70 | printf(" Mode values : normal (default), flight or hybrid.\n"); |
2299770f |
71 | printf("-r Destroy trace channels.\n"); |
72 | printf("-R Stop tracing and destroy trace channels.\n"); |
73 | printf("-s Start tracing.\n"); |
74 | //printf(" Note : will automatically create a normal trace if " |
75 | // "none exists.\n"); |
76 | printf("-q Stop tracing.\n"); |
77 | printf("-d Create trace, spawn a lttd daemon, start tracing.\n"); |
d24c12e7 |
78 | printf(" (optionally, you can set LTT_DAEMON\n"); |
2299770f |
79 | printf(" and the LTT_FACILITIES env. vars.)\n"); |
d24c12e7 |
80 | printf("-f Stop tracing, dump flight recorder trace, destroy channels\n"); |
81 | printf(" (for hybrid traces)\n"); |
2299770f |
82 | printf("-t Trace root path. (ex. /root/traces/example_trace)\n"); |
83 | printf("-T Type of trace (ex. relay)\n"); |
bb01fdc6 |
84 | printf("-l LTT channels root path. (ex. /mnt/debugfs/ltt)\n"); |
d24c12e7 |
85 | printf("-Z Size of the low data rate subbuffers (will be rounded to next page size)\n"); |
86 | printf("-X Number of low data rate subbuffers\n"); |
87 | printf("-V Size of the medium data rate subbuffers (will be rounded to next page size)\n"); |
88 | printf("-B Number of medium data rate subbuffers\n"); |
89 | printf("-z Size of the high data rate subbuffers (will be rounded to next page size)\n"); |
90 | printf("-x Number of high data rate subbuffers\n"); |
2299770f |
91 | printf("-e Get XML facilities description\n"); |
92 | printf("-a Append to trace\n"); |
93 | printf("-N Number of lttd threads\n"); |
5adba60f |
94 | printf("\n"); |
95 | } |
96 | |
97 | |
98 | /* parse_arguments |
99 | * |
100 | * Parses the command line arguments. |
101 | * |
2baf08e5 |
102 | * Returns -1 if the arguments were correct, but doesn't ask for program |
103 | * continuation. Returns EINVAL if the arguments are incorrect, or 0 if OK. |
5adba60f |
104 | */ |
105 | int parse_arguments(int argc, char **argv) |
106 | { |
107 | int ret = 0; |
108 | int argn = 1; |
109 | |
110 | if(argc == 2) { |
111 | if(strcmp(argv[1], "-h") == 0) { |
2baf08e5 |
112 | return -1; |
5adba60f |
113 | } |
114 | } |
115 | |
116 | while(argn < argc) { |
117 | |
118 | switch(argv[argn][0]) { |
119 | case '-': |
120 | switch(argv[argn][1]) { |
121 | case 'n': |
122 | if(argn+1 < argc) { |
123 | trace_name = argv[argn+1]; |
124 | argn++; |
125 | } else { |
8eab4866 |
126 | printf("Specify a trace name after -n.\n"); |
5adba60f |
127 | printf("\n"); |
2baf08e5 |
128 | ret = EINVAL; |
5adba60f |
129 | } |
130 | |
131 | break; |
24331c3d |
132 | case 'b': |
133 | op = CTL_OP_CREATE_START; |
cd39bb61 |
134 | break; |
5adba60f |
135 | case 'c': |
136 | op = CTL_OP_CREATE; |
24331c3d |
137 | break; |
bc0fcb31 |
138 | case 'm': |
5adba60f |
139 | if(argn+1 < argc) { |
140 | mode_name = argv[argn+1]; |
141 | argn++; |
142 | if(strcmp(mode_name, "normal") == 0) |
143 | mode = LTT_TRACE_NORMAL; |
144 | else if(strcmp(mode_name, "flight") == 0) |
145 | mode = LTT_TRACE_FLIGHT; |
d24c12e7 |
146 | else if(strcmp(mode_name, "hybrid") == 0) |
147 | mode = LTT_TRACE_HYBRID; |
5adba60f |
148 | else { |
149 | printf("Invalid mode '%s'.\n", argv[argn]); |
150 | printf("\n"); |
2baf08e5 |
151 | ret = EINVAL; |
5adba60f |
152 | } |
153 | } else { |
bc0fcb31 |
154 | printf("Specify a mode after -m.\n"); |
5adba60f |
155 | printf("\n"); |
2baf08e5 |
156 | ret = EINVAL; |
5adba60f |
157 | } |
158 | break; |
159 | case 'r': |
160 | op = CTL_OP_DESTROY; |
161 | break; |
b7f08766 |
162 | case 'R': |
163 | op = CTL_OP_STOP_DESTROY; |
164 | break; |
5adba60f |
165 | case 's': |
166 | op = CTL_OP_START; |
167 | break; |
168 | case 'q': |
169 | op = CTL_OP_STOP; |
170 | break; |
d24c12e7 |
171 | case 'Z': |
172 | if(argn+1 < argc) { |
173 | subbuf_size_low = (unsigned)atoi(argv[argn+1]); |
174 | argn++; |
175 | } else { |
176 | printf("Specify a number of low traffic subbuffers after -Z.\n"); |
177 | printf("\n"); |
178 | ret = EINVAL; |
179 | } |
180 | break; |
181 | case 'X': |
182 | if(argn+1 < argc) { |
183 | n_subbufs_low = (unsigned)atoi(argv[argn+1]); |
184 | argn++; |
185 | } else { |
186 | printf("Specify a low traffic subbuffer size after -X.\n"); |
187 | printf("\n"); |
188 | ret = EINVAL; |
189 | } |
190 | break; |
191 | case 'V': |
192 | if(argn+1 < argc) { |
193 | subbuf_size_med = (unsigned)atoi(argv[argn+1]); |
194 | argn++; |
195 | } else { |
196 | printf("Specify a number of medium traffic subbuffers after -V.\n"); |
197 | printf("\n"); |
198 | ret = EINVAL; |
199 | } |
200 | break; |
201 | case 'B': |
202 | if(argn+1 < argc) { |
203 | n_subbufs_med = (unsigned)atoi(argv[argn+1]); |
204 | argn++; |
205 | } else { |
206 | printf("Specify a medium traffic subbuffer size after -B.\n"); |
207 | printf("\n"); |
208 | ret = EINVAL; |
209 | } |
210 | break; |
988614ed |
211 | case 'z': |
212 | if(argn+1 < argc) { |
d24c12e7 |
213 | subbuf_size_high = (unsigned)atoi(argv[argn+1]); |
988614ed |
214 | argn++; |
215 | } else { |
d24c12e7 |
216 | printf("Specify a number of high traffic subbuffers after -z.\n"); |
988614ed |
217 | printf("\n"); |
2baf08e5 |
218 | ret = EINVAL; |
988614ed |
219 | } |
220 | break; |
221 | case 'x': |
222 | if(argn+1 < argc) { |
d24c12e7 |
223 | n_subbufs_high = (unsigned)atoi(argv[argn+1]); |
988614ed |
224 | argn++; |
225 | } else { |
d24c12e7 |
226 | printf("Specify a high traffic subbuffer size after -x.\n"); |
988614ed |
227 | printf("\n"); |
2baf08e5 |
228 | ret = EINVAL; |
988614ed |
229 | } |
230 | break; |
5adba60f |
231 | case 'd': |
232 | op = CTL_OP_DAEMON; |
233 | break; |
d24c12e7 |
234 | case 'f': |
235 | op = CTL_OP_DAEMON_HYBRID_FINISH; |
236 | break; |
24331c3d |
237 | case 'e': |
238 | op = CTL_OP_DESCRIPTION; |
239 | break; |
5adba60f |
240 | case 't': |
241 | if(argn+1 < argc) { |
242 | trace_root = argv[argn+1]; |
243 | argn++; |
244 | } else { |
988614ed |
245 | printf("Specify a trace root path after -t.\n"); |
5adba60f |
246 | printf("\n"); |
2baf08e5 |
247 | ret = EINVAL; |
5adba60f |
248 | } |
249 | break; |
250 | case 'l': |
251 | if(argn+1 < argc) { |
252 | channel_root = argv[argn+1]; |
253 | argn++; |
254 | } else { |
988614ed |
255 | printf("Specify a channel root path after -l.\n"); |
5adba60f |
256 | printf("\n"); |
2baf08e5 |
257 | ret = EINVAL; |
5adba60f |
258 | } |
259 | break; |
24331c3d |
260 | case 'a': |
261 | append_trace = 1; |
262 | break; |
263 | case 'N': |
22acb617 |
264 | if(argn+1 < argc) { |
265 | num_threads = argv[argn+1]; |
266 | argn++; |
267 | } |
268 | break; |
313b3771 |
269 | case 'T': |
270 | if(argn+1 < argc) { |
271 | trace_type = argv[argn+1]; |
272 | argn++; |
273 | } else { |
274 | printf("Specify a trace type after -T.\n"); |
275 | printf("\n"); |
276 | ret = EINVAL; |
277 | } |
278 | break; |
5adba60f |
279 | default: |
280 | printf("Invalid argument '%s'.\n", argv[argn]); |
281 | printf("\n"); |
2baf08e5 |
282 | ret = EINVAL; |
5adba60f |
283 | } |
284 | break; |
285 | default: |
286 | printf("Invalid argument '%s'.\n", argv[argn]); |
287 | printf("\n"); |
2baf08e5 |
288 | ret = EINVAL; |
5adba60f |
289 | } |
290 | argn++; |
291 | } |
292 | |
129fd24a |
293 | if(op != CTL_OP_DESCRIPTION && trace_name == NULL) { |
5adba60f |
294 | printf("Please specify a trace name.\n"); |
295 | printf("\n"); |
2baf08e5 |
296 | ret = EINVAL; |
5adba60f |
297 | } |
298 | |
299 | if(op == CTL_OP_NONE) { |
300 | printf("Please specify an operation.\n"); |
301 | printf("\n"); |
2baf08e5 |
302 | ret = EINVAL; |
5adba60f |
303 | } |
304 | |
d24c12e7 |
305 | if(op == CTL_OP_DAEMON || op == CTL_OP_DAEMON_HYBRID_FINISH) { |
5adba60f |
306 | if(trace_root == NULL) { |
307 | printf("Please specify -t trace_root_path with the -d option.\n"); |
308 | printf("\n"); |
2baf08e5 |
309 | ret = EINVAL; |
5adba60f |
310 | } |
311 | if(channel_root == NULL) { |
312 | printf("Please specify -l ltt_root_path with the -d option.\n"); |
313 | printf("\n"); |
2baf08e5 |
314 | ret = EINVAL; |
5adba60f |
315 | } |
316 | } |
317 | |
24331c3d |
318 | if(op == CTL_OP_DESCRIPTION) { |
319 | if(trace_root == NULL) { |
129fd24a |
320 | printf("Please specify -t trace_root_path with the -e option.\n"); |
321 | printf("\n"); |
2baf08e5 |
322 | ret = EINVAL; |
24331c3d |
323 | } |
324 | } |
129fd24a |
325 | |
5adba60f |
326 | return ret; |
327 | } |
328 | |
329 | void show_info(void) |
330 | { |
331 | printf("Linux Trace Toolkit Trace Control\n"); |
332 | printf("\n"); |
24331c3d |
333 | if(trace_name != NULL) { |
334 | printf("Controlling trace : %s\n", trace_name); |
335 | printf("\n"); |
336 | } |
129fd24a |
337 | } |
338 | |
339 | int create_eventdefs(void) |
340 | { |
24331c3d |
341 | int ret = 0; |
342 | char eventdefs_path[PATH_MAX]; |
343 | char eventdefs_file[PATH_MAX]; |
344 | char facilities_file[PATH_MAX]; |
345 | char read_buf[BUF_SIZE]; |
346 | struct dirent *entry; |
129fd24a |
347 | char *facilities_path = getenv("LTT_FACILITIES"); |
348 | if(facilities_path == NULL) facilities_path = |
24331c3d |
349 | PACKAGE_DATA_DIR "/" PACKAGE "/facilities"; |
350 | |
351 | ret = mkdir(trace_root, S_IRWXU|S_IRWXG|S_IRWXO); |
352 | if(ret == -1 && errno != EEXIST) { |
353 | ret = errno; |
354 | perror("Cannot create trace_root directory"); |
355 | printf("trace_root is %s\n", trace_root); |
356 | goto error; |
357 | } |
358 | ret = 0; |
359 | |
360 | size_t trace_root_len = strlen(trace_root); |
361 | strncpy(eventdefs_path, trace_root, PATH_MAX); |
362 | strncat(eventdefs_path, "/eventdefs/", PATH_MAX - trace_root_len); |
363 | size_t eventdefs_path_len = strlen(eventdefs_path); |
364 | ret = mkdir(eventdefs_path, S_IRWXU|S_IRWXG|S_IRWXO); |
365 | if(ret == -1 && (!append_trace || errno != EEXIST)) { |
366 | ret = errno; |
367 | perror("Cannot create eventdefs directory"); |
368 | goto error; |
369 | } |
370 | ret = 0; |
371 | |
372 | DIR *facilities_dir = opendir(facilities_path); |
373 | |
374 | if(facilities_dir == NULL) { |
375 | perror("Cannot open facilities directory"); |
376 | ret = EEXIST; |
377 | goto error; |
378 | } |
379 | |
380 | while((entry = readdir(facilities_dir)) != NULL) { |
381 | if(entry->d_name[0] == '.') continue; |
382 | |
383 | printf("Appending facility file %s\n", entry->d_name); |
384 | strncpy(eventdefs_file, eventdefs_path, PATH_MAX); |
385 | strncat(eventdefs_file, entry->d_name, PATH_MAX - eventdefs_path_len); |
386 | /* Append to the file */ |
387 | FILE *dest = fopen(eventdefs_file, "a"); |
388 | if(!dest) { |
389 | perror("Cannot create eventdefs file"); |
390 | continue; |
391 | } |
392 | strncpy(facilities_file, facilities_path, PATH_MAX); |
393 | size_t facilities_dir_len = strlen(facilities_path); |
394 | strncat(facilities_file, "/", PATH_MAX - facilities_dir_len); |
395 | strncat(facilities_file, entry->d_name, PATH_MAX - facilities_dir_len-1); |
396 | FILE *src = fopen(facilities_file, "r"); |
397 | if(!src) { |
398 | ret = errno; |
399 | perror("Cannot open eventdefs file for reading"); |
400 | goto close_dest; |
401 | } |
402 | |
403 | do { |
404 | size_t read_size, write_size; |
405 | read_size = fread(read_buf, sizeof(char), BUF_SIZE, src); |
406 | if(ferror(src)) { |
407 | ret = errno; |
408 | perror("Cannot read eventdefs file"); |
409 | goto close_src; |
410 | } |
411 | write_size = fwrite(read_buf, sizeof(char), read_size, dest); |
412 | if(ferror(dest)) { |
413 | ret = errno; |
414 | perror("Cannot write eventdefs file"); |
415 | goto close_src; |
416 | } |
417 | } while(!feof(src)); |
418 | |
419 | /* Add spacing between facilities */ |
420 | fwrite("\n", 1, 1, dest); |
421 | |
129fd24a |
422 | close_src: |
24331c3d |
423 | fclose(src); |
129fd24a |
424 | close_dest: |
24331c3d |
425 | fclose(dest); |
426 | } |
129fd24a |
427 | |
24331c3d |
428 | closedir(facilities_dir); |
129fd24a |
429 | |
86a65fdb |
430 | error: |
24331c3d |
431 | return ret; |
129fd24a |
432 | |
5adba60f |
433 | } |
434 | |
129fd24a |
435 | |
5adba60f |
436 | int lttctl_daemon(struct lttctl_handle *handle, char *trace_name) |
437 | { |
438 | char channel_path[PATH_MAX] = ""; |
439 | pid_t pid; |
440 | int ret; |
441 | char *lttd_path = getenv("LTT_DAEMON"); |
5adba60f |
442 | |
86a65fdb |
443 | if(lttd_path == NULL) lttd_path = |
24331c3d |
444 | PACKAGE_BIN_DIR "/lttd"; |
5adba60f |
445 | |
446 | strcat(channel_path, channel_root); |
447 | strcat(channel_path, "/"); |
448 | strcat(channel_path, trace_name); |
449 | |
450 | |
d24c12e7 |
451 | ret = lttctl_create_trace(handle, trace_name, mode, trace_type, |
452 | subbuf_size_low, n_subbufs_low, |
453 | subbuf_size_med, n_subbufs_med, |
454 | subbuf_size_high, n_subbufs_high); |
5adba60f |
455 | if(ret != 0) goto create_error; |
456 | |
5adba60f |
457 | pid = fork(); |
458 | |
459 | if(pid > 0) { |
2299770f |
460 | int status = 0; |
5adba60f |
461 | /* parent */ |
2299770f |
462 | |
24331c3d |
463 | ret = waitpid(pid, &status, 0); |
464 | if(ret == -1) { |
465 | ret = errno; |
466 | perror("Error in waitpid"); |
467 | goto start_error; |
468 | } |
469 | |
470 | ret = 0; |
471 | if(WIFEXITED(status)) |
472 | ret = WEXITSTATUS(status); |
473 | if(ret) goto start_error; |
5adba60f |
474 | |
5adba60f |
475 | printf("Creating supplementary trace files\n"); |
24331c3d |
476 | ret = create_eventdefs(); |
477 | if(ret) goto start_error; |
5adba60f |
478 | |
479 | } else if(pid == 0) { |
480 | /* child */ |
24331c3d |
481 | int ret; |
d24c12e7 |
482 | if(mode != LTT_TRACE_HYBRID) { |
483 | if(append_trace) |
484 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
485 | channel_path, "-d", "-a", "-N", num_threads, NULL); |
486 | else |
487 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
488 | channel_path, "-d", "-N", num_threads, NULL); |
489 | } else { |
490 | if(append_trace) |
491 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
492 | channel_path, "-d", "-a", "-N", num_threads, "-n", NULL); |
493 | else |
494 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
495 | channel_path, "-d", "-N", num_threads, "-n", NULL); |
496 | } |
5adba60f |
497 | if(ret) { |
24331c3d |
498 | ret = errno; |
5adba60f |
499 | perror("Error in executing the lttd daemon"); |
618fbcc1 |
500 | exit(ret); |
5adba60f |
501 | } |
502 | } else { |
503 | /* error */ |
504 | perror("Error in forking for lttd daemon"); |
5adba60f |
505 | } |
506 | |
507 | ret = lttctl_start(handle, trace_name); |
508 | if(ret != 0) goto start_error; |
509 | |
510 | return 0; |
511 | |
512 | /* error handling */ |
513 | start_error: |
24331c3d |
514 | printf("Trace start error\n"); |
5adba60f |
515 | ret |= lttctl_destroy_trace(handle, trace_name); |
516 | create_error: |
517 | return ret; |
518 | } |
519 | |
d24c12e7 |
520 | |
521 | |
522 | |
523 | int lttctl_daemon_hybrid_finish(struct lttctl_handle *handle, char *trace_name) |
524 | { |
525 | char channel_path[PATH_MAX] = ""; |
526 | pid_t pid; |
527 | int ret; |
528 | char *lttd_path = getenv("LTT_DAEMON"); |
529 | |
530 | if(lttd_path == NULL) lttd_path = |
531 | PACKAGE_BIN_DIR "/lttd"; |
532 | |
533 | strcat(channel_path, channel_root); |
534 | strcat(channel_path, "/"); |
535 | strcat(channel_path, trace_name); |
536 | |
537 | |
538 | ret = lttctl_stop(handle, trace_name); |
539 | if(ret != 0) goto stop_error; |
540 | |
541 | pid = fork(); |
542 | |
543 | if(pid > 0) { |
544 | int status = 0; |
545 | /* parent */ |
546 | |
547 | ret = waitpid(pid, &status, 0); |
548 | if(ret == -1) { |
549 | ret = errno; |
550 | perror("Error in waitpid"); |
551 | goto destroy_error; |
552 | } |
553 | |
554 | ret = 0; |
555 | if(WIFEXITED(status)) |
556 | ret = WEXITSTATUS(status); |
557 | if(ret) goto destroy_error; |
558 | |
559 | } else if(pid == 0) { |
560 | /* child */ |
561 | int ret; |
562 | if(append_trace) |
563 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
564 | channel_path, "-d", "-a", "-N", num_threads, "-f", NULL); |
565 | else |
566 | ret = execlp(lttd_path, lttd_path, "-t", trace_root, "-c", |
567 | channel_path, "-d", "-N", num_threads, "-f", NULL); |
568 | if(ret) { |
569 | ret = errno; |
570 | perror("Error in executing the lttd daemon"); |
571 | exit(ret); |
572 | } |
573 | } else { |
574 | /* error */ |
575 | perror("Error in forking for lttd daemon"); |
576 | } |
577 | |
578 | ret = lttctl_destroy_trace(handle, trace_name); |
579 | if(ret != 0) goto destroy_error; |
580 | |
581 | return 0; |
582 | |
583 | /* error handling */ |
584 | destroy_error: |
585 | printf("Hybrid trace destroy error\n"); |
586 | stop_error: |
587 | return ret; |
588 | } |
589 | |
590 | |
591 | |
5adba60f |
592 | int main(int argc, char ** argv) |
593 | { |
594 | int ret; |
595 | struct lttctl_handle *handle; |
596 | |
597 | ret = parse_arguments(argc, argv); |
598 | |
599 | if(ret != 0) show_arguments(); |
2baf08e5 |
600 | if(ret == EINVAL) return EINVAL; |
601 | if(ret == -1) return 0; |
5adba60f |
602 | |
603 | show_info(); |
604 | |
605 | handle = lttctl_create_handle(); |
606 | |
607 | if(handle == NULL) return -1; |
608 | |
609 | switch(op) { |
24331c3d |
610 | case CTL_OP_CREATE_START: |
d24c12e7 |
611 | ret = lttctl_create_trace(handle, trace_name, mode, trace_type, |
612 | subbuf_size_low, n_subbufs_low, |
613 | subbuf_size_med, n_subbufs_med, |
614 | subbuf_size_high, n_subbufs_high); |
24331c3d |
615 | if(!ret) |
616 | ret = lttctl_start(handle, trace_name); |
617 | break; |
618 | case CTL_OP_CREATE: |
d24c12e7 |
619 | ret = lttctl_create_trace(handle, trace_name, mode, trace_type, |
620 | subbuf_size_low, n_subbufs_low, |
621 | subbuf_size_med, n_subbufs_med, |
622 | subbuf_size_high, n_subbufs_high); |
24331c3d |
623 | break; |
5adba60f |
624 | case CTL_OP_DESTROY: |
625 | ret = lttctl_destroy_trace(handle, trace_name); |
626 | break; |
b7f08766 |
627 | case CTL_OP_STOP_DESTROY: |
628 | ret = lttctl_stop(handle, trace_name); |
24331c3d |
629 | if(!ret) |
630 | ret = lttctl_destroy_trace(handle, trace_name); |
b7f08766 |
631 | break; |
5adba60f |
632 | case CTL_OP_START: |
633 | ret = lttctl_start(handle, trace_name); |
634 | break; |
635 | case CTL_OP_STOP: |
636 | ret = lttctl_stop(handle, trace_name); |
637 | break; |
638 | case CTL_OP_DAEMON: |
639 | ret = lttctl_daemon(handle, trace_name); |
640 | break; |
d24c12e7 |
641 | case CTL_OP_DAEMON_HYBRID_FINISH: |
642 | ret = lttctl_daemon_hybrid_finish(handle, trace_name); |
643 | break; |
24331c3d |
644 | case CTL_OP_DESCRIPTION: |
645 | ret = create_eventdefs(); |
646 | break; |
5adba60f |
647 | case CTL_OP_NONE: |
648 | break; |
649 | } |
650 | |
651 | ret |= lttctl_destroy_handle(handle); |
652 | |
653 | return ret; |
654 | } |