Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Search for more options when passing args to -h

Recently 'perf <tool> -h' was made aware of arguments and would show
just the help for the arguments specified, but that required a strict
form, i.e.:

$ perf -h --tui

worked, but:

$ perf -h tui

didn't.

Make it support both cases and also look at the option help when neither
matches, so that he following examples works:

$ perf report -h interface

Usage: perf report [<options>]

--gtk Use the GTK2 interface
--stdio Use the stdio interface
--tui Use the TUI interface

$ perf report -h stack

Usage: perf report [<options>]

-g, --call-graph <print_type,threshold[,print_limit],order,
sort_key[,branch]>
Display call graph (stack chain/backtrace):

print_type: call graph printing style (graph|flat|fractal|none)
threshold: minimum call graph inclusion threshold (<percent>)
print_limit: maximum number of call graph entry (<number>)
order: call graph order (caller|callee)
sort_key: call graph sort key (function|address)
branch: include last branch info to call graph (branch)

Default: graph,0.5,caller,function
--max-stack <n> Set the maximum stack depth when parsing the
callchain, anything beyond the specified depth
will be ignored. Default: 127
$

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-xzqvamzqv3cv0p6w3inhols3@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+14 -1
+14 -1
tools/perf/util/parse-options.c
··· 695 695 for (i = 1; i < ctx->argc; ++i) { 696 696 const char *arg = ctx->argv[i]; 697 697 698 - if (arg[0] != '-') 698 + if (arg[0] != '-') { 699 + if (arg[1] == '\0') { 700 + if (arg[0] == opt->short_name) 701 + return true; 702 + continue; 703 + } 704 + 705 + if (opt->long_name && strcmp(opt->long_name, arg) == 0) 706 + return true; 707 + 708 + if (opt->help && strcasestr(opt->help, arg) != NULL) 709 + return true; 710 + 699 711 continue; 712 + } 700 713 701 714 if (arg[1] == opt->short_name || 702 715 (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0))