diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-10-23 12:27:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-10-23 20:50:50 -0400 |
commit | 161d9041782b86c5493481566539bfc058ceeaff (patch) | |
tree | 473e96f38af8c9e5a6bfd99ef20c021584168343 /tools/perf/util/parse-options.c | |
parent | 869c55b0f473fecfe6c294c6fa965dedfe469e02 (diff) |
perf tools: Provide help for subset of options
Some tools have a lot of options, so, providing a way to show help just
for some of them may come handy:
$ perf report -h --tui
Usage: perf report [<options>]
--tui Use the TUI interface
$ perf report -h --tui --showcpuutilization -b -c
Usage: perf report [<options>]
-b, --branch-stack use branch records for per branch histogram filling
-c, --comms <comm[,comm...]>
only consider symbols in these comms
--showcpuutilization
Show sample percentage for different cpu modes
--tui Use the TUI interface
$
Using it with perf bash completion is also handy, just make sure you
source the needed file:
$ . ~/git/linux/tools/perf/perf-completion.sh
Then press tab/tab after -- to see a list of options, put them after -h
and only the options chosen will have its help presented:
$ perf report -h --
--asm-raw --demangle-kernel --group
--kallsyms --pretty --stdio
--branch-history --disassembler-style --gtk
--max-stack --showcpuutilization --symbol-filter
--branch-stack --dsos --header
--mem-mode --show-info --symbols
--call-graph --dump-raw-trace --header-only
--modules --show-nr-samples --symfs
--children --exclude-other --hide-unresolved
--objdump --show-ref-call-graph --threads
--column-widths --fields --ignore-callees
--parent --show-total-period --tid
--comms --field-separator --input
--percentage --socket-filter --tui
--cpu --force --inverted
--percent-limit --sort --verbose
--demangle --full-source-path --itrace
--pid --source --vmlinux
$ perf report -h --socket-filter
Usage: perf report [<options>]
--socket-filter <n>
only show processor socket that match with this filter
Suggested-by: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Chandler Carruth <chandlerc@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-83mcdd3wj0379jcgea8w0fxa@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/parse-options.c')
-rw-r--r-- | tools/perf/util/parse-options.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index fb26532d67c3..22c2806bda98 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -373,7 +373,8 @@ void parse_options_start(struct parse_opt_ctx_t *ctx, | |||
373 | } | 373 | } |
374 | 374 | ||
375 | static int usage_with_options_internal(const char * const *, | 375 | static int usage_with_options_internal(const char * const *, |
376 | const struct option *, int); | 376 | const struct option *, int, |
377 | struct parse_opt_ctx_t *); | ||
377 | 378 | ||
378 | int parse_options_step(struct parse_opt_ctx_t *ctx, | 379 | int parse_options_step(struct parse_opt_ctx_t *ctx, |
379 | const struct option *options, | 380 | const struct option *options, |
@@ -397,8 +398,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, | |||
397 | 398 | ||
398 | if (arg[1] != '-') { | 399 | if (arg[1] != '-') { |
399 | ctx->opt = ++arg; | 400 | ctx->opt = ++arg; |
400 | if (internal_help && *ctx->opt == 'h') | 401 | if (internal_help && *ctx->opt == 'h') { |
401 | return usage_with_options_internal(usagestr, options, 0); | 402 | return usage_with_options_internal(usagestr, options, 0, ctx); |
403 | } | ||
402 | switch (parse_short_opt(ctx, options)) { | 404 | switch (parse_short_opt(ctx, options)) { |
403 | case -1: | 405 | case -1: |
404 | return parse_options_usage(usagestr, options, arg, 1); | 406 | return parse_options_usage(usagestr, options, arg, 1); |
@@ -413,7 +415,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, | |||
413 | check_typos(arg, options); | 415 | check_typos(arg, options); |
414 | while (ctx->opt) { | 416 | while (ctx->opt) { |
415 | if (internal_help && *ctx->opt == 'h') | 417 | if (internal_help && *ctx->opt == 'h') |
416 | return usage_with_options_internal(usagestr, options, 0); | 418 | return usage_with_options_internal(usagestr, options, 0, ctx); |
417 | arg = ctx->opt; | 419 | arg = ctx->opt; |
418 | switch (parse_short_opt(ctx, options)) { | 420 | switch (parse_short_opt(ctx, options)) { |
419 | case -1: | 421 | case -1: |
@@ -446,9 +448,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, | |||
446 | 448 | ||
447 | arg += 2; | 449 | arg += 2; |
448 | if (internal_help && !strcmp(arg, "help-all")) | 450 | if (internal_help && !strcmp(arg, "help-all")) |
449 | return usage_with_options_internal(usagestr, options, 1); | 451 | return usage_with_options_internal(usagestr, options, 1, ctx); |
450 | if (internal_help && !strcmp(arg, "help")) | 452 | if (internal_help && !strcmp(arg, "help")) |
451 | return usage_with_options_internal(usagestr, options, 0); | 453 | return usage_with_options_internal(usagestr, options, 0, ctx); |
452 | if (!strcmp(arg, "list-opts")) | 454 | if (!strcmp(arg, "list-opts")) |
453 | return PARSE_OPT_LIST_OPTS; | 455 | return PARSE_OPT_LIST_OPTS; |
454 | if (!strcmp(arg, "list-cmds")) | 456 | if (!strcmp(arg, "list-cmds")) |
@@ -682,8 +684,27 @@ out: | |||
682 | return ordered; | 684 | return ordered; |
683 | } | 685 | } |
684 | 686 | ||
687 | static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) | ||
688 | { | ||
689 | int i; | ||
690 | |||
691 | for (i = 1; i < ctx->argc; ++i) { | ||
692 | const char *arg = ctx->argv[i]; | ||
693 | |||
694 | if (arg[0] != '-') | ||
695 | continue; | ||
696 | |||
697 | if (arg[1] == opt->short_name || | ||
698 | (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0)) | ||
699 | return true; | ||
700 | } | ||
701 | |||
702 | return false; | ||
703 | } | ||
704 | |||
685 | int usage_with_options_internal(const char * const *usagestr, | 705 | int usage_with_options_internal(const char * const *usagestr, |
686 | const struct option *opts, int full) | 706 | const struct option *opts, int full, |
707 | struct parse_opt_ctx_t *ctx) | ||
687 | { | 708 | { |
688 | struct option *ordered; | 709 | struct option *ordered; |
689 | 710 | ||
@@ -707,8 +728,11 @@ int usage_with_options_internal(const char * const *usagestr, | |||
707 | if (ordered) | 728 | if (ordered) |
708 | opts = ordered; | 729 | opts = ordered; |
709 | 730 | ||
710 | for ( ; opts->type != OPTION_END; opts++) | 731 | for ( ; opts->type != OPTION_END; opts++) { |
732 | if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx)) | ||
733 | continue; | ||
711 | print_option_help(opts, full); | 734 | print_option_help(opts, full); |
735 | } | ||
712 | 736 | ||
713 | fputc('\n', stderr); | 737 | fputc('\n', stderr); |
714 | 738 | ||
@@ -721,7 +745,7 @@ void usage_with_options(const char * const *usagestr, | |||
721 | const struct option *opts) | 745 | const struct option *opts) |
722 | { | 746 | { |
723 | exit_browser(false); | 747 | exit_browser(false); |
724 | usage_with_options_internal(usagestr, opts, 0); | 748 | usage_with_options_internal(usagestr, opts, 0, NULL); |
725 | exit(129); | 749 | exit(129); |
726 | } | 750 | } |
727 | 751 | ||