Add ust start trace feature
[lttng-tools.git] / lttng / options.c
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 <popt.h>
20 #include <stdlib.h>
21
22 #include "lttng.h"
23
24 /* Option variables */
25 char *opt_tracing_group;
26 char *opt_session_uuid;
27 char *opt_create_session;
28 char *opt_sessiond_path;
29 char *opt_destroy_session;
30 int opt_trace_kernel = 0;
31 int opt_quiet = 0;
32 int opt_verbose = 0;
33 int opt_list_apps = 0;
34 int opt_no_sessiond = 0;
35 int opt_list_session = 0;
36 pid_t opt_create_trace = 0;
37 pid_t opt_start_trace = 0;
38
39 enum {
40 OPT_HELP = 42,
41 };
42
43 static struct poptOption long_options[] = {
44 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
45 {"create-session", 'c', POPT_ARG_STRING, &opt_create_session, 0, 0, 0},
46 {"create-trace", 'C', POPT_ARG_INT, &opt_create_trace, 0, 0, 0},
47 {"destroy-session", 'd', POPT_ARG_STRING, &opt_destroy_session, 0, 0, 0},
48 {"group", 0, POPT_ARG_STRING, &opt_tracing_group, 0, 0},
49 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
50 {"kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0},
51 {"list-apps", 'L', POPT_ARG_VAL, &opt_list_apps, 1, 0, 0},
52 {"list-sessions", 'l', POPT_ARG_VAL, &opt_list_session, 1, 0, 0},
53 {"no-kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 0, 0, 0},
54 {"no-sessiond", 0, POPT_ARG_VAL, &opt_no_sessiond, 1, 0, 0},
55 {"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0, 0},
56 {"session", 's', POPT_ARG_STRING, &opt_session_uuid, 0, 0, 0},
57 {"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0, 0},
58 {"start", 0, POPT_ARG_INT, &opt_start_trace, 0, 0, 0},
59 {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0, 0},
60 //{"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0},
61 {0, 0, 0, 0, 0, 0, 0}
62 };
63
64
65 /*
66 * usage
67 */
68 static void usage(FILE *ofp)
69 {
70 fprintf(ofp, "LTTng Trace Control " VERSION"\n\n");
71 fprintf(ofp, "usage : lttng [OPTION]\n");
72 fprintf(ofp, "\n");
73 fprintf(ofp, "Options:\n");
74 fprintf(ofp, " -v, --verbose Verbose mode\n");
75 fprintf(ofp, " -q, --quiet Quiet mode\n");
76 fprintf(ofp, " --help Show help\n");
77 fprintf(ofp, " --group NAME Unix tracing group name. (default: tracing)\n");
78 fprintf(ofp, " --no-sessiond Don't spawn a session daemon\n");
79 fprintf(ofp, " --sessiond-path Session daemon full path\n");
80 fprintf(ofp, "\n");
81 fprintf(ofp, "Session options:\n");
82 fprintf(ofp, " -c, --create-session NAME Create a new session\n");
83 fprintf(ofp, " -l, --list-sessions List all available sessions\n");
84 fprintf(ofp, " -s, --session UUID Specify tracing session using UUID\n");
85 fprintf(ofp, " -d, --destroy-session=NAME Destroy the session specified by NAME\n");
86 fprintf(ofp, "\n");
87 fprintf(ofp, "Tracing options:\n");
88 //fprintf(ofp, " --kernel Enable kernel tracing\n");
89 //fprintf(ofp, " --no-kernel Disable kernel tracing\n");
90 fprintf(ofp, " -L, --list-apps List traceable UST applications\n");
91 fprintf(ofp, " -C, --create-trace PID Create trace for PID\n");
92 fprintf(ofp, " --start PID Start trace for PID\n");
93 fprintf(ofp, "\n");
94 fprintf(ofp, "Please see the lttng(1) man page for full documentation.\n");
95 fprintf(ofp, "See http://lttng.org/ust for updates, bug reports and news.\n");
96 }
97
98 /*
99 * parse_args
100 *
101 * Parse command line arguments.
102 * Return 0 if OK, else -1
103 */
104 int parse_args(int argc, const char **argv)
105 {
106 static poptContext pc;
107 int opt;
108
109 /* If no options, fail */
110 if (argc < 2) {
111 return -1;
112 }
113
114 pc = poptGetContext(NULL, argc, argv, long_options, 0);
115 poptReadDefaultConfig(pc, 0);
116
117 while ((opt = poptGetNextOpt(pc)) != -1) {
118 switch (opt) {
119 case OPT_HELP:
120 usage(stderr);
121 clean_exit(EXIT_SUCCESS);
122 break;
123 default:
124 usage(stderr);
125 clean_exit(EXIT_FAILURE);
126 break;
127 }
128 }
129
130 if (pc) {
131 poptFreeContext(pc);
132 }
133
134 return 0;
135 }
This page took 0.031529 seconds and 4 git commands to generate.