From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752754AbbJYIwd (ORCPT ); Sun, 25 Oct 2015 04:52:33 -0400 Received: from terminus.zytor.com ([198.137.202.10]:37108 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750952AbbJYIwa (ORCPT ); Sun, 25 Oct 2015 04:52:30 -0400 Date: Sun, 25 Oct 2015 01:51:59 -0700 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: hpa@zytor.com, tglx@linutronix.de, dsahern@gmail.com, eranian@google.com, jolsa@redhat.com, mingo@kernel.org, a.p.zijlstra@chello.nl, chandlerc@gmail.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, fweisbec@gmail.com, namhyung@kernel.org, wangnan0@huawei.com, acme@redhat.com, brendan.d.gregg@gmail.com, bp@suse.de Reply-To: namhyung@kernel.org, wangnan0@huawei.com, adrian.hunter@intel.com, fweisbec@gmail.com, mingo@kernel.org, chandlerc@gmail.com, a.p.zijlstra@chello.nl, linux-kernel@vger.kernel.org, eranian@google.com, jolsa@redhat.com, tglx@linutronix.de, dsahern@gmail.com, hpa@zytor.com, bp@suse.de, brendan.d.gregg@gmail.com, acme@redhat.com To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Provide help for subset of options Git-Commit-ID: 161d9041782b86c5493481566539bfc058ceeaff X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 161d9041782b86c5493481566539bfc058ceeaff Gitweb: http://git.kernel.org/tip/161d9041782b86c5493481566539bfc058ceeaff Author: Arnaldo Carvalho de Melo AuthorDate: Fri, 23 Oct 2015 13:27:39 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 23 Oct 2015 21:50:50 -0300 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 [] --tui Use the TUI interface $ perf report -h --tui --showcpuutilization -b -c Usage: perf report [] -b, --branch-stack use branch records for per branch histogram filling -c, --comms 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 [] --socket-filter only show processor socket that match with this filter Suggested-by: Ingo Molnar Cc: Adrian Hunter Cc: Borislav Petkov Cc: Brendan Gregg Cc: Chandler Carruth Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-83mcdd3wj0379jcgea8w0fxa@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-options.c | 42 ++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index fb26532..22c2806 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, } static int usage_with_options_internal(const char * const *, - const struct option *, int); + const struct option *, int, + struct parse_opt_ctx_t *); int parse_options_step(struct parse_opt_ctx_t *ctx, const struct option *options, @@ -397,8 +398,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, if (arg[1] != '-') { ctx->opt = ++arg; - if (internal_help && *ctx->opt == 'h') - return usage_with_options_internal(usagestr, options, 0); + if (internal_help && *ctx->opt == 'h') { + return usage_with_options_internal(usagestr, options, 0, ctx); + } switch (parse_short_opt(ctx, options)) { case -1: return parse_options_usage(usagestr, options, arg, 1); @@ -413,7 +415,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, check_typos(arg, options); while (ctx->opt) { if (internal_help && *ctx->opt == 'h') - return usage_with_options_internal(usagestr, options, 0); + return usage_with_options_internal(usagestr, options, 0, ctx); arg = ctx->opt; switch (parse_short_opt(ctx, options)) { case -1: @@ -446,9 +448,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, arg += 2; if (internal_help && !strcmp(arg, "help-all")) - return usage_with_options_internal(usagestr, options, 1); + return usage_with_options_internal(usagestr, options, 1, ctx); if (internal_help && !strcmp(arg, "help")) - return usage_with_options_internal(usagestr, options, 0); + return usage_with_options_internal(usagestr, options, 0, ctx); if (!strcmp(arg, "list-opts")) return PARSE_OPT_LIST_OPTS; if (!strcmp(arg, "list-cmds")) @@ -682,8 +684,27 @@ out: return ordered; } +static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) +{ + int i; + + for (i = 1; i < ctx->argc; ++i) { + const char *arg = ctx->argv[i]; + + if (arg[0] != '-') + continue; + + if (arg[1] == opt->short_name || + (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0)) + return true; + } + + return false; +} + int usage_with_options_internal(const char * const *usagestr, - const struct option *opts, int full) + const struct option *opts, int full, + struct parse_opt_ctx_t *ctx) { struct option *ordered; @@ -707,8 +728,11 @@ int usage_with_options_internal(const char * const *usagestr, if (ordered) opts = ordered; - for ( ; opts->type != OPTION_END; opts++) + for ( ; opts->type != OPTION_END; opts++) { + if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx)) + continue; print_option_help(opts, full); + } fputc('\n', stderr); @@ -721,7 +745,7 @@ void usage_with_options(const char * const *usagestr, const struct option *opts) { exit_browser(false); - usage_with_options_internal(usagestr, opts, 0); + usage_with_options_internal(usagestr, opts, 0, NULL); exit(129); }