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