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