lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1444830244-17557-1-git-send-email-yunlong.song@huawei.com>
Date:	Wed, 14 Oct 2015 21:44:04 +0800
From:	Yunlong Song <yunlong.song@...wei.com>
To:	<a.p.zijlstra@...llo.nl>, <paulus@...ba.org>, <mingo@...hat.com>,
	<acme@...nel.org>
CC:	<linux-kernel@...r.kernel.org>, <wangnan0@...wei.com>,
	<namhyung@...nel.org>, <artagnon@...il.com>, <sriram.r@...ia.com>,
	<adrian.hunter@...el.com>, <jolsa@...nel.org>, <dsahern@...il.com>
Subject: [PATCH] perf help: Add options description to 'perf -h'

Add options description to 'perf -h' to make it consistent with other builtins
(e.g., 'perf stat -h').

Example:

Before this patch:

 # 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
    buildid-cache   Manage build-id cache.
    buildid-list    List the buildids in a perf.data file
 <SNIP>
    test            Runs sanity tests.
    timechart       Tool to visualize total system behavior during a workload
    top             System profiling tool.
    trace           strace inspired tool
    probe           Define new dynamic tracepoints

  See 'perf help COMMAND' for more information on a specific command.

After this patch:

 # perf -h

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

         --help            help
         --version         version
         --exec-path       exec-path
         --html-path       html-path
         --paginate        paginate
         --no-pager        no-pager
         --perf-dir        perf-dir
         --work-tree       work-tree
         --debugfs-dir     debugfs-dir
         --buildid-dir     buildid-dir
         --list-cmds       list-cmds
         --list-opts       list-opts
         --debug           debug

  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
    buildid-cache   Manage build-id cache.
    buildid-list    List the buildids in a perf.data file
 <SNIP>
    test            Runs sanity tests.
    timechart       Tool to visualize total system behavior during a workload
    top             System profiling tool.
    trace           strace inspired tool
    probe           Define new dynamic tracepoints

  See 'perf help COMMAND' for more information on a specific command.

As shown above, the options description really appears now.

Signed-off-by: Yunlong Song <yunlong.song@...wei.com>
---
 tools/perf/builtin-help.c       |  2 +-
 tools/perf/builtin.h            |  3 +++
 tools/perf/perf.c               | 12 ++++++++----
 tools/perf/util/parse-options.c |  9 ++++++++-
 tools/perf/util/parse-options.h |  3 +++
 5 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 36486ea..5cb29fe 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -470,7 +470,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 
 	if (!argv[0]) {
-		printf("\n usage: %s\n\n", perf_usage_string);
+		usage_with_options_return(perf_usage, perf_options);
 		list_common_cmds_help();
 		printf("\n %s\n\n", perf_more_info_string);
 		return 0;
diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
index 3688ad2..4439db0 100644
--- a/tools/perf/builtin.h
+++ b/tools/perf/builtin.h
@@ -3,9 +3,12 @@
 
 #include "util/util.h"
 #include "util/strbuf.h"
+#include "util/parse-options.h"
 
 extern const char perf_usage_string[];
 extern const char perf_more_info_string[];
+extern const char * const perf_usage[];
+extern struct option perf_options[];
 
 extern void list_common_cmds_help(void);
 extern const char *help_unknown_cmd(const char *cmd);
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 5437134..3bcaa10d 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -21,6 +21,10 @@
 
 const char perf_usage_string[] =
 	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
+const char * const perf_usage[] = {
+	perf_usage_string,
+	NULL
+};
 
 const char perf_more_info_string[] =
 	"See 'perf help COMMAND' for more information on a specific command.";
@@ -127,7 +131,7 @@ static void commit_pager_choice(void)
 	}
 }
 
-struct option options[] = {
+struct option perf_options[] = {
 	OPT_ARGUMENT("help", "help"),
 	OPT_ARGUMENT("version", "version"),
 	OPT_ARGUMENT("exec-path", "exec-path"),
@@ -261,8 +265,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 		} else if (!strcmp(cmd, "--list-opts")) {
 			unsigned int i;
 
-			for (i = 0; i < ARRAY_SIZE(options)-1; i++) {
-				struct option *p = options+i;
+			for (i = 0; i < ARRAY_SIZE(perf_options)-1; i++) {
+				struct option *p = perf_options+i;
 				printf("--%s ", p->long_name);
 			}
 			putchar('\n');
@@ -578,7 +582,7 @@ int main(int argc, const char **argv)
 			argv[0] += 2;
 	} else {
 		/* The user didn't specify a command; give them help */
-		printf("\n usage: %s\n\n", perf_usage_string);
+		usage_with_options_return(perf_usage, perf_options);
 		list_common_cmds_help();
 		printf("\n %s\n\n", perf_more_info_string);
 		goto out;
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 9a38b05..0ebfa4d 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -648,7 +648,7 @@ int usage_with_options_internal(const char * const *usagestr,
 	if (!usagestr)
 		return PARSE_OPT_HELP;
 
-	fprintf(stderr, "\n usage: %s\n", *usagestr++);
+	fprintf(stderr, "\n Usage: %s\n", *usagestr++);
 	while (*usagestr && **usagestr)
 		fprintf(stderr, "    or: %s\n", *usagestr++);
 	while (*usagestr) {
@@ -677,6 +677,13 @@ void usage_with_options(const char * const *usagestr,
 	exit(129);
 }
 
+void usage_with_options_return(const char * const *usagestr,
+			const struct option *opts)
+{
+	exit_browser(false);
+	usage_with_options_internal(usagestr, opts, 0);
+}
+
 int parse_options_usage(const char * const *usagestr,
 			const struct option *opts,
 			const char *optstr, bool short_opt)
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index 367d8b8..8130f83 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -161,6 +161,9 @@ extern int parse_options_subcommand(int argc, const char **argv,
 extern NORETURN void usage_with_options(const char * const *usagestr,
                                         const struct option *options);
 
+extern void usage_with_options_return(const char * const *usagestr,
+                                      const struct option *options);
+
 /*----- incremantal advanced APIs -----*/
 
 enum {
-- 
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ