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