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

perf tools: Handle -h and -v options

Adding handling for '-h' and '-v' options to invoke help and version
command respectively.

Current behaviour is:

$ perf -v
Unknown option: -v

Usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]
$ perf -h
Unknown option: -h

Usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

New behaviour:

$ perf -h

usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

The most commonly used perf commands are:
annotate Read perf.data (created by perf record) and display annotated code
archive Create archive with object files with build-ids found in perf.data file
bench General framework for benchmark suites
...

$ perf -v
perf version 4.3.rc3.gc99e32

Updated man page.

Requested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1444068369-20978-10-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
a1853e2c b34b3bf0

+22
+8
tools/perf/Documentation/perf.txt
··· 27 27 Setup buildid cache directory. It has higher priority than 28 28 buildid.dir config file option. 29 29 30 + -v:: 31 + --version:: 32 + Display perf version. 33 + 34 + -h:: 35 + --help:: 36 + Run perf help command. 37 + 30 38 DESCRIPTION 31 39 ----------- 32 40 Performance counters for Linux are a new kernel-based subsystem
+14
tools/perf/perf.c
··· 162 162 break; 163 163 164 164 /* 165 + * Shortcut for '-h' and '-v' options to invoke help 166 + * and version command. 167 + */ 168 + if (!strcmp(cmd, "-h")) { 169 + (*argv)[0] = "--help"; 170 + break; 171 + } 172 + 173 + if (!strcmp(cmd, "-v")) { 174 + (*argv)[0] = "--version"; 175 + break; 176 + } 177 + 178 + /* 165 179 * Check remaining flags. 166 180 */ 167 181 if (!prefixcmp(cmd, CMD_EXEC_PATH)) {