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