From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
David Ahern <dsahern@gmail.com>,
Hemant Kumar <hemant@linux.vnet.ibm.com>,
Jiri Olsa <jolsa@redhat.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
Peter Zijlstra <peterz@infradead.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/32] perf tools: Add support for exclusive option
Date: Tue, 28 Oct 2014 11:32:05 -0200 [thread overview]
Message-ID: <1414503146-22789-12-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1414503146-22789-1-git-send-email-acme@kernel.org>
From: Namhyung Kim <namhyung@kernel.org>
Some options cannot be used at the same time. To handle such options
add a new PARSE_OPT_EXCLUSIVE flag and show error message if more than
one of them is used.
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1413990949-13953-5-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/parse-options.c | 59 +++++++++++++++++++++++++++++++++--------
tools/perf/util/parse-options.h | 2 ++
2 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index b6016101b40b..f62dee7bd924 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -45,6 +45,23 @@ static int get_value(struct parse_opt_ctx_t *p,
if (opt->flags & PARSE_OPT_DISABLED)
return opterror(opt, "is not usable", flags);
+ if (opt->flags & PARSE_OPT_EXCLUSIVE) {
+ if (p->excl_opt) {
+ char msg[128];
+
+ if (((flags & OPT_SHORT) && p->excl_opt->short_name) ||
+ p->excl_opt->long_name == NULL) {
+ scnprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
+ p->excl_opt->short_name);
+ } else {
+ scnprintf(msg, sizeof(msg), "cannot be used with %s",
+ p->excl_opt->long_name);
+ }
+ opterror(opt, msg, flags);
+ return -3;
+ }
+ p->excl_opt = opt;
+ }
if (!(flags & OPT_SHORT) && p->opt) {
switch (opt->type) {
case OPTION_CALLBACK:
@@ -345,13 +362,14 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
const char * const usagestr[])
{
int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
+ int excl_short_opt = 1;
+ const char *arg;
/* we must reset ->opt, unknown short option leave it dangling */
ctx->opt = NULL;
for (; ctx->argc; ctx->argc--, ctx->argv++) {
- const char *arg = ctx->argv[0];
-
+ arg = ctx->argv[0];
if (*arg != '-' || !arg[1]) {
if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
break;
@@ -360,19 +378,21 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
}
if (arg[1] != '-') {
- ctx->opt = arg + 1;
+ ctx->opt = ++arg;
if (internal_help && *ctx->opt == 'h')
return usage_with_options_internal(usagestr, options, 0);
switch (parse_short_opt(ctx, options)) {
case -1:
- return parse_options_usage(usagestr, options, arg + 1, 1);
+ return parse_options_usage(usagestr, options, arg, 1);
case -2:
goto unknown;
+ case -3:
+ goto exclusive;
default:
break;
}
if (ctx->opt)
- check_typos(arg + 1, options);
+ check_typos(arg, options);
while (ctx->opt) {
if (internal_help && *ctx->opt == 'h')
return usage_with_options_internal(usagestr, options, 0);
@@ -389,6 +409,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
ctx->argv[0] = strdup(ctx->opt - 1);
*(char *)ctx->argv[0] = '-';
goto unknown;
+ case -3:
+ goto exclusive;
default:
break;
}
@@ -404,19 +426,23 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
break;
}
- if (internal_help && !strcmp(arg + 2, "help-all"))
+ arg += 2;
+ if (internal_help && !strcmp(arg, "help-all"))
return usage_with_options_internal(usagestr, options, 1);
- if (internal_help && !strcmp(arg + 2, "help"))
+ if (internal_help && !strcmp(arg, "help"))
return usage_with_options_internal(usagestr, options, 0);
- if (!strcmp(arg + 2, "list-opts"))
+ if (!strcmp(arg, "list-opts"))
return PARSE_OPT_LIST_OPTS;
- if (!strcmp(arg + 2, "list-cmds"))
+ if (!strcmp(arg, "list-cmds"))
return PARSE_OPT_LIST_SUBCMDS;
- switch (parse_long_opt(ctx, arg + 2, options)) {
+ switch (parse_long_opt(ctx, arg, options)) {
case -1:
- return parse_options_usage(usagestr, options, arg + 2, 0);
+ return parse_options_usage(usagestr, options, arg, 0);
case -2:
goto unknown;
+ case -3:
+ excl_short_opt = 0;
+ goto exclusive;
default:
break;
}
@@ -428,6 +454,17 @@ unknown:
ctx->opt = NULL;
}
return PARSE_OPT_DONE;
+
+exclusive:
+ parse_options_usage(usagestr, options, arg, excl_short_opt);
+ if ((excl_short_opt && ctx->excl_opt->short_name) ||
+ ctx->excl_opt->long_name == NULL) {
+ char opt = ctx->excl_opt->short_name;
+ parse_options_usage(NULL, options, &opt, 1);
+ } else {
+ parse_options_usage(NULL, options, ctx->excl_opt->long_name, 0);
+ }
+ return PARSE_OPT_HELP;
}
int parse_options_end(struct parse_opt_ctx_t *ctx)
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index b7c80dbc7627..97b153fb4999 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -39,6 +39,7 @@ enum parse_opt_option_flags {
PARSE_OPT_HIDDEN = 8,
PARSE_OPT_LASTARG_DEFAULT = 16,
PARSE_OPT_DISABLED = 32,
+ PARSE_OPT_EXCLUSIVE = 64,
};
struct option;
@@ -174,6 +175,7 @@ struct parse_opt_ctx_t {
const char **out;
int argc, cpidx;
const char *opt;
+ const struct option *excl_opt;
int flags;
};
--
1.9.3
next prev parent reply other threads:[~2014-10-28 13:33 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-28 13:31 [GIT PULL 00/32] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 01/32] perf tools powerpc: Cache the DWARF debug info Arnaldo Carvalho de Melo
2014-10-29 6:39 ` Namhyung Kim
2014-10-29 21:26 ` Sukadev Bhattiprolu
2014-10-31 3:10 ` Namhyung Kim
2014-10-28 13:31 ` [PATCH 02/32] perf tools: Set thread->mg.machine in all places Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 03/32] perf tools: A thread's machine can be found via thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 04/32] perf thread: Adopt resolve_callchain method from machine Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 05/32] perf callchains: Use thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 06/32] perf tests: Remove misplaced __maybe_unused Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 07/32] perf tests: Use thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 08/32] perf tools: Add PARSE_OPT_DISABLED flag Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 09/32] perf tools: Export usage string and option table of perf record Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 10/32] perf kvm: Print kvm specific --help output Arnaldo Carvalho de Melo
2014-10-28 13:32 ` Arnaldo Carvalho de Melo [this message]
2014-10-28 13:32 ` [PATCH 12/32] perf probe: Use PARSE_OPT_EXCLUSIVE flag Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 13/32] perf callchain: Use global caching provided by libunwind Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 14/32] perf tools: Ensure return negative value when write header error Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 15/32] perf pmu: Let pmu's with no events show up on perf list Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 16/32] perf tools: Build programs to copy 32-bit compatibility Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 17/32] perf tools: Add support for 32-bit compatibility VDSOs Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 18/32] perf tools: Do not attempt to run perf-read-vdso32 if it wasn't built Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 19/32] perf tools: Make CPUINFO_PROC an array to support different kernel versions Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 20/32] perf pmu: Add proper error handling to print_pmu_events() Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 21/32] perf tools: Fix report -F abort for data without branch info Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 22/32] perf tools: Fix report -F in_tx " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 23/32] perf tools: Fix report -F mispredict " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 24/32] perf tools: Fix report -F symbol_to " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 25/32] perf tools: Fix report -F symbol_from " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 26/32] perf tools: Fix report -F dso_to " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 27/32] perf tools: Fix report -F dso_from " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 28/32] perf tools: Add facility to export data in database-friendly way Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 29/32] perf scripting python: Extend interface to export data in a " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 30/32] perf script: Add Python script to export to postgresql Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 31/32] perf probe: Trivial typo fix for --demangle Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 32/32] perf probe: Add --quiet option to suppress output result message Arnaldo Carvalho de Melo
2014-10-29 9:11 ` [GIT PULL 00/32] perf/core improvements and fixes Ingo Molnar
2014-10-29 12:58 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414503146-22789-12-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=hemant@linux.vnet.ibm.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.