| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #include <popt.h> |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include "lttng.h" |
| 23 | |
| 24 | /* Option variables */ |
| 25 | char *opt_tracing_group; |
| 26 | char *opt_session_name; |
| 27 | char *opt_sessiond_path; |
| 28 | int opt_trace_kernel = 0; |
| 29 | int opt_quiet = 0; |
| 30 | int opt_verbose = 0; |
| 31 | int opt_list_apps = 0; |
| 32 | int opt_no_sessiond = 0; |
| 33 | int opt_list_session = 0; |
| 34 | |
| 35 | enum { |
| 36 | OPT_HELP = 42, |
| 37 | }; |
| 38 | |
| 39 | static struct poptOption long_options[] = { |
| 40 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ |
| 41 | {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, |
| 42 | {"group", 0, POPT_ARG_STRING, &opt_tracing_group, 0, 0}, |
| 43 | {"kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 1, 0, 0}, |
| 44 | {"no-kernel", 0, POPT_ARG_VAL, &opt_trace_kernel, 0, 0, 0}, |
| 45 | {"session", 0, POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_session_name, 0, 0}, |
| 46 | {"quiet", 'q', POPT_ARG_VAL, &opt_quiet, 1, 0}, |
| 47 | {"verbose", 'v', POPT_ARG_VAL, &opt_verbose, 1, 0}, |
| 48 | {"list-apps", 'l', POPT_ARG_VAL, &opt_list_apps, 1, 0}, |
| 49 | {"no-sessiond", 0, POPT_ARG_VAL, &opt_no_sessiond, 1, 0}, |
| 50 | {"sessiond-path", 0, POPT_ARG_STRING, &opt_sessiond_path, 0, 0}, |
| 51 | {"list-session", 0, POPT_ARG_VAL, &opt_list_session, 1, 0}, |
| 52 | {0, 0, 0, 0, 0, 0} |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * usage |
| 58 | */ |
| 59 | static void usage(FILE *ofp) |
| 60 | { |
| 61 | fprintf(ofp, "LTTng Trace Control " VERSION"\n\n"); |
| 62 | fprintf(ofp, "usage : lttng [OPTION]\n"); |
| 63 | fprintf(ofp, "\n"); |
| 64 | fprintf(ofp, "Options:\n"); |
| 65 | fprintf(ofp, " -v, --verbose Verbose mode\n"); |
| 66 | fprintf(ofp, " -q, --quiet Quiet mode\n"); |
| 67 | fprintf(ofp, " --help Show help\n"); |
| 68 | fprintf(ofp, " --group NAME Unix tracing group name. (default: tracing)\n"); |
| 69 | fprintf(ofp, " --no-sessiond Don't spawn a session daemon.\n"); |
| 70 | fprintf(ofp, " --sessiond-path Session daemon full path\n"); |
| 71 | fprintf(ofp, "\n"); |
| 72 | fprintf(ofp, "Session options:\n"); |
| 73 | fprintf(ofp, " --list-session List all available sessions\n"); |
| 74 | fprintf(ofp, "\n"); |
| 75 | fprintf(ofp, "Tracing options:\n"); |
| 76 | //fprintf(ofp, " --session [NAME] Specify tracing session. If no NAME is given\n"); |
| 77 | //fprintf(ofp, " or option is ommited, a session will be created\n"); |
| 78 | //fprintf(ofp, " --kernel Enable kernel tracing\n"); |
| 79 | //fprintf(ofp, " --no-kernel Disable kernel tracing\n"); |
| 80 | fprintf(ofp, " -l, --list-apps List traceable UST applications\n"); |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * parse_args |
| 85 | * |
| 86 | * Parse command line arguments. |
| 87 | * Return 0 if OK, else -1 |
| 88 | */ |
| 89 | int parse_args(int argc, const char **argv) |
| 90 | { |
| 91 | static poptContext pc; |
| 92 | int opt; |
| 93 | |
| 94 | pc = poptGetContext("lttng", argc, argv, long_options, 0); |
| 95 | poptReadDefaultConfig(pc, 0); |
| 96 | |
| 97 | while ((opt = poptGetNextOpt(pc)) != -1) { |
| 98 | switch (opt) { |
| 99 | case OPT_HELP: |
| 100 | usage(stderr); |
| 101 | clean_exit(EXIT_SUCCESS); |
| 102 | break; |
| 103 | default: |
| 104 | usage(stderr); |
| 105 | clean_exit(EXIT_FAILURE); |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (pc) { |
| 111 | poptFreeContext(pc); |
| 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | } |