diff options
author | Ingo Molnar <mingo@kernel.org> | 2014-03-18 04:23:09 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-03-18 04:23:09 -0400 |
commit | 0afd2d51029961281572d02545c7bde1b3f4292c (patch) | |
tree | 73f8b07ee0b43ebd93fb0556b0af0f217f897d5c /tools/perf/util/parse-options.c | |
parent | 81827ed8d85e892311965dc9ec4120b2b2e745bd (diff) | |
parent | d75e6097ef1f7669deb500fbbdf53cfe524f1b53 (diff) |
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core improvements and fixes from Arnaldo:
User visible:
* Add several futex 'perf bench' microbenchmarks (Davidlohr Bueso)
* Speed up thread map generation (Don Zickus)
* Fix synthesizing mmaps for threads (Don Zickus)
* Fix invalid output on event group stdio report (Namhyung Kim)
* Introduce 'perf kvm --list-cmds' command line option for use by
scripts (Ramkumar Ramachandra)
Documentation:
* Clarify load-latency information in the 'perf mem' docs (Andi Kleen)
* Clarify x86 register naming in 'perf probe' docs (Andi Kleen)
Refactorings:
* hists browser refactorings to reuse code accross UIs (Namhyung Kim)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'tools/perf/util/parse-options.c')
-rw-r--r-- | tools/perf/util/parse-options.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index d22e3f8017dc..bf48092983c6 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -407,7 +407,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, | |||
407 | if (internal_help && !strcmp(arg + 2, "help")) | 407 | if (internal_help && !strcmp(arg + 2, "help")) |
408 | return usage_with_options_internal(usagestr, options, 0); | 408 | return usage_with_options_internal(usagestr, options, 0); |
409 | if (!strcmp(arg + 2, "list-opts")) | 409 | if (!strcmp(arg + 2, "list-opts")) |
410 | return PARSE_OPT_LIST; | 410 | return PARSE_OPT_LIST_OPTS; |
411 | if (!strcmp(arg + 2, "list-cmds")) | ||
412 | return PARSE_OPT_LIST_SUBCMDS; | ||
411 | switch (parse_long_opt(ctx, arg + 2, options)) { | 413 | switch (parse_long_opt(ctx, arg + 2, options)) { |
412 | case -1: | 414 | case -1: |
413 | return parse_options_usage(usagestr, options, arg + 2, 0); | 415 | return parse_options_usage(usagestr, options, arg + 2, 0); |
@@ -433,25 +435,45 @@ int parse_options_end(struct parse_opt_ctx_t *ctx) | |||
433 | return ctx->cpidx + ctx->argc; | 435 | return ctx->cpidx + ctx->argc; |
434 | } | 436 | } |
435 | 437 | ||
436 | int parse_options(int argc, const char **argv, const struct option *options, | 438 | int parse_options_subcommand(int argc, const char **argv, const struct option *options, |
437 | const char * const usagestr[], int flags) | 439 | const char *const subcommands[], const char *usagestr[], int flags) |
438 | { | 440 | { |
439 | struct parse_opt_ctx_t ctx; | 441 | struct parse_opt_ctx_t ctx; |
440 | 442 | ||
441 | perf_header__set_cmdline(argc, argv); | 443 | perf_header__set_cmdline(argc, argv); |
442 | 444 | ||
445 | /* build usage string if it's not provided */ | ||
446 | if (subcommands && !usagestr[0]) { | ||
447 | struct strbuf buf = STRBUF_INIT; | ||
448 | |||
449 | strbuf_addf(&buf, "perf %s [<options>] {", argv[0]); | ||
450 | for (int i = 0; subcommands[i]; i++) { | ||
451 | if (i) | ||
452 | strbuf_addstr(&buf, "|"); | ||
453 | strbuf_addstr(&buf, subcommands[i]); | ||
454 | } | ||
455 | strbuf_addstr(&buf, "}"); | ||
456 | |||
457 | usagestr[0] = strdup(buf.buf); | ||
458 | strbuf_release(&buf); | ||
459 | } | ||
460 | |||
443 | parse_options_start(&ctx, argc, argv, flags); | 461 | parse_options_start(&ctx, argc, argv, flags); |
444 | switch (parse_options_step(&ctx, options, usagestr)) { | 462 | switch (parse_options_step(&ctx, options, usagestr)) { |
445 | case PARSE_OPT_HELP: | 463 | case PARSE_OPT_HELP: |
446 | exit(129); | 464 | exit(129); |
447 | case PARSE_OPT_DONE: | 465 | case PARSE_OPT_DONE: |
448 | break; | 466 | break; |
449 | case PARSE_OPT_LIST: | 467 | case PARSE_OPT_LIST_OPTS: |
450 | while (options->type != OPTION_END) { | 468 | while (options->type != OPTION_END) { |
451 | printf("--%s ", options->long_name); | 469 | printf("--%s ", options->long_name); |
452 | options++; | 470 | options++; |
453 | } | 471 | } |
454 | exit(130); | 472 | exit(130); |
473 | case PARSE_OPT_LIST_SUBCMDS: | ||
474 | for (int i = 0; subcommands[i]; i++) | ||
475 | printf("%s ", subcommands[i]); | ||
476 | exit(130); | ||
455 | default: /* PARSE_OPT_UNKNOWN */ | 477 | default: /* PARSE_OPT_UNKNOWN */ |
456 | if (ctx.argv[0][1] == '-') { | 478 | if (ctx.argv[0][1] == '-') { |
457 | error("unknown option `%s'", ctx.argv[0] + 2); | 479 | error("unknown option `%s'", ctx.argv[0] + 2); |
@@ -464,6 +486,13 @@ int parse_options(int argc, const char **argv, const struct option *options, | |||
464 | return parse_options_end(&ctx); | 486 | return parse_options_end(&ctx); |
465 | } | 487 | } |
466 | 488 | ||
489 | int parse_options(int argc, const char **argv, const struct option *options, | ||
490 | const char * const usagestr[], int flags) | ||
491 | { | ||
492 | return parse_options_subcommand(argc, argv, options, NULL, | ||
493 | (const char **) usagestr, flags); | ||
494 | } | ||
495 | |||
467 | #define USAGE_OPTS_WIDTH 24 | 496 | #define USAGE_OPTS_WIDTH 24 |
468 | #define USAGE_GAP 2 | 497 | #define USAGE_GAP 2 |
469 | 498 | ||