Fix errors due to lttng.h cleanup
[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 "options.h"
23
24 /* Option variables */
25 char *opt_event_list;
26 char *opt_tracing_group;
27 char *opt_sessiond_path;
28 char *opt_session_name;
29 char *opt_trace_name;
30 int opt_destroy_trace;
31 int opt_create_session;
32 int opt_destroy_session;
33 int opt_trace_kernel = 0;
34 int opt_quiet = 0;
35 int opt_verbose = 0;
36 int opt_list_apps = 0;
37 int opt_no_sessiond = 0;
38 int opt_list_session = 0;
39 int opt_list_traces = 0;
40 int opt_create_trace;
41 int opt_start_trace = 0;
42 int opt_stop_trace = 0;
43 int opt_enable_event;
44 int opt_disable_event;
45 int opt_kern_create_channel;
46 pid_t opt_trace_pid = 0;
47
48 enum {
49 OPT_HELP = 1,
50 OPT_ENABLE_EVENT,
51 OPT_DISABLE_EVENT,
52 OPT_CREATE_SESSION,
53 OPT_CREATE_TRACE,
54 OPT_DESTROY_SESSION,
55 OPT_DESTROY_TRACE,
56 OPT_START_TRACE,
57 OPT_STOP_TRACE,
58 };
59
60 static struct poptOption long_options[] = {
61 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
62 {"create-session", 'c', POPT_ARG_STRING, 0, OPT_CREATE_SESSION, 0, 0},
63 {"create-trace", 'C', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_CREATE_TRACE, 0, 0},
64 {"destroy-trace", 'D', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_DESTROY_TRACE, 0, 0},
65 {"destroy-session", 'd', POPT_ARG_STRING, 0, OPT_DESTROY_SESSION, 0, 0},
66 {"disable-event", 0, POPT_ARG_STRING, 0, OPT_DISABLE_EVENT, 0, 0},
67 {"enable-event", 'e', POPT_ARG_STRING, 0, OPT_ENABLE_EVENT, 0, 0},
68 {"group", 0, POPT_ARG_STRING, &opt_tracing_group, 0, 0, 0},
69 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
70 {"kernel", 'k', POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0},
71 {"kern-create-channel",0, POPT_ARG_VAL, &opt_kern_create_channel, 1, 0, 0},
72 {"list-apps", 'L', POPT_ARG_VAL, &opt_list_apps, 1, 0, 0},
73 {"list-sessions", 'l', POPT_ARG_VAL, &opt_list_session, 1, 0, 0},
74 {"list-traces", 't', POPT_ARG_VAL, &opt_list_traces, 1, 0, 0},
75 {"no-kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 0, 0, 0},
76 {"no-sessiond", 0, POPT_ARG_VAL, &opt_no_sessiond, 1, 0, 0},
77 {"pid", 'p', POPT_ARG_INT, &opt_trace_pid, 0, 0, 0},
78 {"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0, 0},
79 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
80 {"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0, 0},
81 {"start", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_START_TRACE, 0, 0},
82 {"stop", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_STOP_TRACE, 0, 0},
83 {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0, 0},
84 {0, 0, 0, 0, 0, 0, 0}
85 };
86
87
88 /*
89 * usage
90 */
91 static void usage(FILE *ofp)
92 {
93 fprintf(ofp, "LTTng Trace Control " VERSION"\n\n");
94 fprintf(ofp, "usage : lttng [OPTION]\n");
95 fprintf(ofp, "\n");
96 fprintf(ofp, "Options:\n");
97 fprintf(ofp, " -v, --verbose Verbose mode\n");
98 fprintf(ofp, " -q, --quiet Quiet mode\n");
99 fprintf(ofp, " --help Show help\n");
100 fprintf(ofp, " --group NAME Unix tracing group name. (default: tracing)\n");
101 fprintf(ofp, " --no-sessiond Don't spawn a session daemon\n");
102 fprintf(ofp, " --sessiond-path Session daemon full path\n");
103 fprintf(ofp, " -L, --list-apps List traceable user-space applications\n");
104 fprintf(ofp, "\n");
105 fprintf(ofp, "Session options:\n");
106 fprintf(ofp, " -c, --create-session NAME Create a new session\n");
107 fprintf(ofp, " -l, --list-sessions List all available sessions by name\n");
108 fprintf(ofp, " -s, --session UUID Specify tracing session using UUID\n");
109 fprintf(ofp, " -d, --destroy-session NAME Destroy the session specified by NAME\n");
110 fprintf(ofp, " -t, --list-traces List session's traces. Use -s to specify the session\n");
111 fprintf(ofp, "\n");
112 fprintf(ofp, "Tracing options:\n");
113 fprintf(ofp, " -p, --pid PID Specify action on user-space tracer for PID\n");
114 fprintf(ofp, " -k, --kernel Specify action on kernel tracer\n");
115 fprintf(ofp, " -e, --enable-event LIST Enable tracing event (support marker and tracepoint)\n");
116 fprintf(ofp, " --disable-event LIST Disable tracing event (support marker and tracepoint)\n");
117 fprintf(ofp, " -C, --create-trace Create a trace. Allocate and setup a trace\n");
118 fprintf(ofp, " -D, --destroy-trace [NAME] Destroy a trace. Use NAME to identify user-space trace\n");
119 fprintf(ofp, " --start [NAME] Start tracing. Use NAME to identify user-space trace\n");
120 fprintf(ofp, " --stop [NAME] Stop tracing. Use NAME to identify user-space trace\n");
121 fprintf(ofp, "\n");
122 fprintf(ofp, "Kernel tracing options:\n");
123 fprintf(ofp, " --kern-create-channel Create a kernel channel\n");
124 fprintf(ofp, "\n");
125 fprintf(ofp, "User-space tracing options:\n");
126 fprintf(ofp, "\n");
127 fprintf(ofp, "Please see the lttng(1) man page for full documentation.\n");
128 fprintf(ofp, "See http://lttng.org for updates, bug reports and news.\n");
129 }
130
131 /*
132 * parse_args
133 *
134 * Parse command line arguments.
135 * Return 0 if OK, else -1
136 */
137 int parse_args(int argc, const char **argv)
138 {
139 static poptContext pc;
140 int opt;
141
142 /* If no options, fail */
143 if (argc < 2) {
144 return -1;
145 }
146
147 pc = poptGetContext(NULL, argc, argv, long_options, 0);
148 poptReadDefaultConfig(pc, 0);
149
150 while ((opt = poptGetNextOpt(pc)) != -1) {
151 switch (opt) {
152 case OPT_HELP:
153 usage(stderr);
154 clean_exit(EXIT_SUCCESS);
155 break;
156 case OPT_CREATE_SESSION:
157 opt_create_session = 1;
158 opt_session_name = poptGetOptArg(pc);
159 break;
160 case OPT_DESTROY_SESSION:
161 opt_destroy_session = 1;
162 opt_session_name = poptGetOptArg(pc);
163 break;
164 case OPT_ENABLE_EVENT:
165 opt_enable_event = 1;
166 opt_event_list = poptGetOptArg(pc);
167 break;
168 case OPT_DESTROY_TRACE:
169 opt_destroy_trace = 1;
170 opt_trace_name = poptGetOptArg(pc);
171 break;
172 case OPT_START_TRACE:
173 opt_start_trace = 1;
174 opt_trace_name = poptGetOptArg(pc);
175 break;
176 case OPT_STOP_TRACE:
177 opt_stop_trace = 1;
178 opt_trace_name = poptGetOptArg(pc);
179 break;
180 case OPT_CREATE_TRACE:
181 opt_create_trace = 1;
182 opt_trace_name = poptGetOptArg(pc);
183 break;
184 default:
185 usage(stderr);
186 clean_exit(EXIT_FAILURE);
187 break;
188 }
189 }
190
191 if (pc) {
192 poptFreeContext(pc);
193 }
194
195 return 0;
196 }
This page took 0.033816 seconds and 4 git commands to generate.