Initial import
[lttng-tools.git] / lttng / options.c
CommitLineData
fac6795d
DG
1/* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 */
18
19#include <popt.h>
20#include <stdlib.h>
21
22#include "lttng.h"
23
24/* Option variables */
25char *opt_tracing_group;
26char *opt_session_name;
27int opt_trace_kernel = 0;
28int opt_quiet = 0;
29int opt_verbose = 0;
30int opt_list_apps = 0;
31
32enum {
33 OPT_HELP = 42,
34};
35
36static struct poptOption long_options[] = {
37 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
38 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
39 {"group", 0, POPT_ARG_STRING, &opt_tracing_group, 0, 0},
40 {"kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0},
41 {"no-kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 0, 0, 0},
42 {"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0},
43 {"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0},
44 {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0},
45 {"list-apps", 'l', POPT_ARG_VAL, &opt_list_apps, 1, 0},
46 {0, 0, 0, 0, 0, 0}
47};
48
49
50/*
51 * usage
52 */
53static void usage(FILE *ofp)
54{
55 fprintf(ofp, "LTTng Trace Control " VERSION"\n\n");
56 fprintf(ofp, "usage : lttng [OPTION]\n");
57 fprintf(ofp, "\n");
58 fprintf(ofp, "Options:\n");
59 fprintf(ofp, " -v, --verbose Verbose mode\n");
60 fprintf(ofp, " -q, --quiet Quiet mode\n");
61 fprintf(ofp, " --help Show help\n");
62 fprintf(ofp, " --group NAME Unix tracing group name. (default: tracing)\n");
63 fprintf(ofp, "\n");
64 fprintf(ofp, "Tracing options:\n");
65 //fprintf(ofp, " --session [NAME] Specify tracing session. If no NAME is given\n");
66 //fprintf(ofp, " or option is ommited, a session will be created\n");
67 //fprintf(ofp, " --kernel Enable kernel tracing\n");
68 //fprintf(ofp, " --no-kernel Disable kernel tracing\n");
69 fprintf(ofp, " -l, --list-apps List traceable UST applications\n");
70}
71
72/*
73 * parse_args
74 *
75 * Parse command line arguments.
76 * Return 0 if OK, else -1
77 */
78int parse_args(int argc, const char **argv)
79{
80 static poptContext pc;
81 int opt;
82
83 pc = poptGetContext("lttng", argc, argv, long_options, 0);
84 poptReadDefaultConfig(pc, 0);
85
86 while ((opt = poptGetNextOpt(pc)) != -1) {
87 switch (opt) {
88 case OPT_HELP:
89 usage(stderr);
90 clean_exit(EXIT_SUCCESS);
91 break;
92 default:
93 usage(stderr);
94 clean_exit(EXIT_FAILURE);
95 break;
96 }
97 }
98
99 if (pc) {
100 poptFreeContext(pc);
101 }
102
103 return 0;
104}
This page took 0.025931 seconds and 4 git commands to generate.