Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1245813 > unrolled thread

Re: [PATCH 1/1] perf:Adding --list-opts to usage string

Started byArnaldo Carvalho de Melo <acme@kernel.org>
First post2015-10-13 17:00 +0200
Last post2015-10-15 09:40 +0200
Articles 12 — 4 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 1/1] perf:Adding --list-opts to usage string Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-13 17:00 +0200
    Re: [PATCH 1/1] perf:Adding --list-opts to usage string Ramkumar Ramachandra <artagnon@gmail.com> - 2015-10-13 17:30 +0200
      Re: [PATCH 1/1] perf:Adding --list-opts to usage string Yunlong Song <yunlong.song@huawei.com> - 2015-10-14 04:30 +0200
        Re: [PATCH 1/1] perf:Adding --list-opts to usage string Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-14 05:20 +0200
          Re: [PATCH 1/1] perf:Adding --list-opts to usage string Namhyung Kim <namhyung@kernel.org> - 2015-10-14 05:50 +0200
          Re: [PATCH 1/1] perf:Adding --list-opts to usage string Yunlong Song <yunlong.song@huawei.com> - 2015-10-14 15:40 +0200
            Re: [PATCH 1/1] perf:Adding --list-opts to usage string Yunlong Song <yunlong.song@huawei.com> - 2015-10-15 09:20 +0200
          [PATCH] perf help: Add options description to 'perf -h' Yunlong Song <yunlong.song@huawei.com> - 2015-10-14 15:50 +0200
          [PATCH v2 2/3] perf help: Change 'usage' to 'Usage' for consistency Yunlong Song <yunlong.song@huawei.com> - 2015-10-15 09:40 +0200
          [PATCH v2 1/3] perf help: Add options description to 'perf -h' Yunlong Song <yunlong.song@huawei.com> - 2015-10-15 09:40 +0200
          [PATCH v2 3/3] perf help: Change the usage's stdout to stderr for consistency Yunlong Song <yunlong.song@huawei.com> - 2015-10-15 09:40 +0200
          [PATCH v2 0/3] perf help: Make perf's help consistent with other builtins Yunlong Song <yunlong.song@huawei.com> - 2015-10-15 09:40 +0200

#1245813 — Re: [PATCH 1/1] perf:Adding --list-opts to usage string

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-13 17:00 +0200
SubjectRe: [PATCH 1/1] perf:Adding --list-opts to usage string
Message-ID<qj9dw-1jL-25@gated-at.bofh.it>
Em Thu, Oct 08, 2015 at 10:59:50AM +0530, Sriram Raghunathan escreveu:
> Minor change, adding --list-opts to usage string. So that it is
> visible to the user on running perf --help. or just perf
> from command line.


Ramkumar, Yunlong, are you ok with this?

- Arnaldo

 
> Signed-off-by: Sriram Raghunathan <sriram.r@nokia.com>
> ---
>  tools/perf/perf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index 07dbff5..92b5007 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -19,7 +19,7 @@
>  #include <pthread.h>
> 
>  const char perf_usage_string[] =
> -	"perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
> +	"perf [--version] [--help] [--list-opts] [OPTIONS] COMMAND [ARGS]";
> 
>  const char perf_more_info_string[] =
>  	"See 'perf help COMMAND' for more information on a specific command.";
> --
> 2.6.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1245839

FromRamkumar Ramachandra <artagnon@gmail.com>
Date2015-10-13 17:30 +0200
Message-ID<qj9Gz-28L-37@gated-at.bofh.it>
In reply to#1245813
Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 08, 2015 at 10:59:50AM +0530, Sriram Raghunathan escreveu:
>> Minor change, adding --list-opts to usage string. So that it is
>> visible to the user on running perf --help. or just perf
>> from command line.
>
>
> Ramkumar, Yunlong, are you ok with this?

Not sure I understand the motivation, but I suppose it can't hurt to
show this detail?

Ram

>> Signed-off-by: Sriram Raghunathan <sriram.r@nokia.com>
>> ---
>>  tools/perf/perf.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
>> index 07dbff5..92b5007 100644
>> --- a/tools/perf/perf.c
>> +++ b/tools/perf/perf.c
>> @@ -19,7 +19,7 @@
>>  #include <pthread.h>
>>
>>  const char perf_usage_string[] =
>> -     "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
>> +     "perf [--version] [--help] [--list-opts] [OPTIONS] COMMAND [ARGS]";
>>
>>  const char perf_more_info_string[] =
>>       "See 'perf help COMMAND' for more information on a specific command.";
>> --
>> 2.6.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1246261

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-14 04:30 +0200
Message-ID<qjjZg-1gq-15@gated-at.bofh.it>
In reply to#1245839
On 2015/10/13 23:24, Ramkumar Ramachandra wrote:
> Arnaldo Carvalho de Melo wrote:
>> Em Thu, Oct 08, 2015 at 10:59:50AM +0530, Sriram Raghunathan escreveu:
>>> Minor change, adding --list-opts to usage string. So that it is
>>> visible to the user on running perf --help. or just perf
>>> from command line.
>>
>>
>> Ramkumar, Yunlong, are you ok with this?
> 
> Not sure I understand the motivation, but I suppose it can't hurt to
> show this detail?
> 
> Ram

Agree with Ramkumar, --list-opts is redundant due to the existing [OPTIONS] in
the perf_usage_string[].

>>>
>>>  const char perf_usage_string[] =
>>> -     "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
>>> +     "perf [--version] [--help] [--list-opts] [OPTIONS] COMMAND [ARGS]";

-- 
Thanks,
Yunlong Song

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

[toc] | [prev] | [next] | [standalone]


#1246273

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-14 05:20 +0200
Message-ID<qjkLE-2wS-7@gated-at.bofh.it>
In reply to#1246261
Em Wed, Oct 14, 2015 at 10:29:05AM +0800, Yunlong Song escreveu:
> On 2015/10/13 23:24, Ramkumar Ramachandra wrote:
> > Arnaldo Carvalho de Melo wrote:
> >> Em Thu, Oct 08, 2015 at 10:59:50AM +0530, Sriram Raghunathan escreveu:
> >>> Minor change, adding --list-opts to usage string. So that it is
> >>> visible to the user on running perf --help. or just perf
> >>> from command line.
> >>
> >> Ramkumar, Yunlong, are you ok with this?

> > Not sure I understand the motivation, but I suppose it can't hurt to
> > show this detail?

> Agree with Ramkumar, --list-opts is redundant due to the existing [OPTIONS] in
> the perf_usage_string[].

I see, thinking about it now, it seems that this is because 'perf -h'
behaves differently from other tools, i.e.:

$ 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.

--------------------------

While:

$ perf stat -h

 usage: perf stat [<options>] [<command>]

    -T, --transaction     hardware transaction statistics
    -e, --event <event>   event selector. use 'perf list' to list available events
        --filter <filter>
                          event filter
    -i, --no-inherit      child tasks do not inherit counters
    -p, --pid <pid>       stat events on existing process id
    -t, --tid <tid>       stat events on existing thread id
    -a, --all-cpus        system-wide collection from all CPUs
<SNIP>
    -I, --interval-print <n>
                          print counts at regular interval in ms (>= 10)
        --per-socket      aggregate counts per processor socket
        --per-core        aggregate counts per physical processor core
        --per-thread      aggregate counts per thread
    -D, --delay <n>       ms to wait before starting measurement after program start

--------------------------

One doesn't show what options can be used, the other does, so there is
an inconsistency, this and the fact that 'perf -h' outputs to stdout,
'perf stat -h' and the other builtins output to stderr. I think all
should output to stdout, just like 'ls --help', what do you think?

- Arnaldo
 
> >>>
> >>>  const char perf_usage_string[] =
> >>> -     "perf [--version] [--help] [OPTIONS] COMMAND [ARGS]";
> >>> +     "perf [--version] [--help] [--list-opts] [OPTIONS] COMMAND [ARGS]";
> 
> -- 
> Thanks,
> Yunlong Song
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1246290

FromNamhyung Kim <namhyung@kernel.org>
Date2015-10-14 05:50 +0200
Message-ID<qjleG-3bd-7@gated-at.bofh.it>
In reply to#1246273
Hi Arnaldo,

On Wed, Oct 14, 2015 at 12:10 PM, Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
> Em Wed, Oct 14, 2015 at 10:29:05AM +0800, Yunlong Song escreveu:
>> On 2015/10/13 23:24, Ramkumar Ramachandra wrote:
>> > Arnaldo Carvalho de Melo wrote:
>> >> Em Thu, Oct 08, 2015 at 10:59:50AM +0530, Sriram Raghunathan escreveu:
>> >>> Minor change, adding --list-opts to usage string. So that it is
>> >>> visible to the user on running perf --help. or just perf
>> >>> from command line.
>> >>
>> >> Ramkumar, Yunlong, are you ok with this?
>
>> > Not sure I understand the motivation, but I suppose it can't hurt to
>> > show this detail?
>
>> Agree with Ramkumar, --list-opts is redundant due to the existing [OPTIONS] in
>> the perf_usage_string[].

AFAIK the --list-cmds and --list-opts options are just for completion
scripts, not for human.  I don't think we need to expose them to
normal users.

>
> I see, thinking about it now, it seems that this is because 'perf -h'
> behaves differently from other tools, i.e.:
>
> $ perf -h
>
>  usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]
>
>  The most commonly used perf commands are:

One nit, these are not commonly used commands, but all commands. :)
Anyway it'd be better to add option descriptions here for consistency.

>    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.
>
> --------------------------
>
> While:
>
> $ perf stat -h
>
>  usage: perf stat [<options>] [<command>]
>
>     -T, --transaction     hardware transaction statistics
>     -e, --event <event>   event selector. use 'perf list' to list available events
>         --filter <filter>
>                           event filter
>     -i, --no-inherit      child tasks do not inherit counters
>     -p, --pid <pid>       stat events on existing process id
>     -t, --tid <tid>       stat events on existing thread id
>     -a, --all-cpus        system-wide collection from all CPUs
> <SNIP>
>     -I, --interval-print <n>
>                           print counts at regular interval in ms (>= 10)
>         --per-socket      aggregate counts per processor socket
>         --per-core        aggregate counts per physical processor core
>         --per-thread      aggregate counts per thread
>     -D, --delay <n>       ms to wait before starting measurement after program start
>
> --------------------------
>
> One doesn't show what options can be used, the other does, so there is
> an inconsistency, this and the fact that 'perf -h' outputs to stdout,
> 'perf stat -h' and the other builtins output to stderr. I think all
> should output to stdout, just like 'ls --help', what do you think?

I'm ok with changing to stdout.

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

[toc] | [prev] | [next] | [standalone]


#1246753

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-14 15:40 +0200
Message-ID<qjurE-8nB-25@gated-at.bofh.it>
In reply to#1246273
On 2015/10/14 11:10, Arnaldo Carvalho de Melo wrote:

> One doesn't show what options can be used, the other does, so there is
> an inconsistency, this and the fact that 'perf -h' outputs to stdout,
> 'perf stat -h' and the other builtins output to stderr. I think all
> should output to stdout, just like 'ls --help', what do you think?
> 
> - Arnaldo
>  

I think the reason that options do not show in 'perf -h' but show in
other builtins is not the different use of stdout or stderr. I will
send a patch to fix this instead.

-- 
Thanks,
Yunlong Song

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

[toc] | [prev] | [next] | [standalone]


#1247512

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-15 09:20 +0200
Message-ID<qjKZs-7If-27@gated-at.bofh.it>
In reply to#1246753
On 2015/10/14 21:40, Arnaldo Carvalho de Melo wrote:
> 
> Le 14 oct. 2015 10:33 AM, "Yunlong Song" <yunlong.song@huawei.com <mailto:yunlong.song@huawei.com>> a écrit :
>>
>> On 2015/10/14 11:10, Arnaldo Carvalho de Melo wrote:
>>
>> > One doesn't show what options can be used, the other does, so there is
>> > an inconsistency, this and the fact that 'perf -h' outputs to stdout,
>> > 'perf stat -h' and the other builtins output to stderr. I think all
>> > should output to stdout, just like 'ls --help', what do you think?
>> >
>> > - Arnaldo
>> >
>>
>> I think the reason that options do not show in 'perf -h' but show in
>> other builtins is not the different use of stdout or stderr. I will
>> send a patch to fix this instead.
> 
> Sure, I mentioned two problems. The invonsistency in stdout/stderr usage has nothing to do with options being not showed in 'perf -h'. :-)
>>


Sorry, I understand now. I think it makes sense that the builtins use stderr everywhere
to show its usage info when the opts or cmds are incorrectly used. Usually, there is an
error description followed with the usage info, for example:
 # ./perf stat -f
  Error: unknown switch `f'

 Usage: perf stat [<options>] [<command>]

    -T, --transaction     hardware transaction statistics
    -e, --event <event>   event selector. use 'perf list' to list available events
        --filter <filter>
                          event filter
    -i, --no-inherit      child tasks do not inherit counters
<SNIP>
    -I, --interval-print <n>
                          print counts at regular interval in ms (>= 10)
        --per-socket      aggregate counts per processor socket
        --per-core        aggregate counts per physical processor core
        --per-thread      aggregate counts per thread
    -D, --delay <n>       ms to wait before starting measurement after program start

As shown above, I think the error description and the usage info should output to the same
stderr area as it is now to be clear.

Thus I think it is better to make perf output its usage info to stderr instead of stdout for
consistency. I will resend patches to fix this.

-- 
Thanks,
Yunlong Song

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

[toc] | [prev] | [next] | [standalone]


#1246764 — [PATCH] perf help: Add options description to 'perf -h'

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-14 15:50 +0200
Subject[PATCH] perf help: Add options description to 'perf -h'
Message-ID<qjuBk-8B-23@gated-at.bofh.it>
In reply to#1246273
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@huawei.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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1247524 — [PATCH v2 2/3] perf help: Change 'usage' to 'Usage' for consistency

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-15 09:40 +0200
Subject[PATCH v2 2/3] perf help: Change 'usage' to 'Usage' for consistency
Message-ID<qjLiO-85x-3@gated-at.bofh.it>
In reply to#1246273
Capitalize 'usage' to make it consistent with all the other 'Usage' in the
codes, e.g., usage_builtin.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-help.c       | 2 +-
 tools/perf/util/parse-options.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 5cb29fe..09b0368 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -463,7 +463,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 			builtin_help_subcommands, builtin_help_usage, 0);
 
 	if (show_all) {
-		printf("\n usage: %s\n\n", perf_usage_string);
+		printf("\n Usage: %s\n\n", perf_usage_string);
 		list_commands("perf commands", &main_cmds, &other_cmds);
 		printf(" %s\n\n", perf_more_info_string);
 		return 0;
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 494089b..06793d9 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) {
@@ -691,7 +691,7 @@ int parse_options_usage(const char * const *usagestr,
 	if (!usagestr)
 		goto opt;
 
-	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) {
-- 
1.8.5.2

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

[toc] | [prev] | [next] | [standalone]


#1247525 — [PATCH v2 1/3] perf help: Add options description to 'perf -h'

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-15 09:40 +0200
Subject[PATCH v2 1/3] perf help: Add options description to 'perf -h'
Message-ID<qjLiO-85x-9@gated-at.bofh.it>
In reply to#1246273
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@huawei.com>
---
 tools/perf/builtin-help.c       |  2 +-
 tools/perf/builtin.h            |  3 +++
 tools/perf/perf.c               | 12 ++++++++----
 tools/perf/util/parse-options.c |  7 +++++++
 tools/perf/util/parse-options.h |  3 +++
 5 files changed, 22 insertions(+), 5 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..494089b 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1247528 — [PATCH v2 3/3] perf help: Change the usage's stdout to stderr for consistency

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-15 09:40 +0200
Subject[PATCH v2 3/3] perf help: Change the usage's stdout to stderr for consistency
Message-ID<qjLiO-85x-11@gated-at.bofh.it>
In reply to#1246273
The builtins use stderr everywhere to show the usage info when the opts
or cmds are incorrectly used, for consistency, change perf's stdout to
stderr to show its usage info when it is incorrectly (including no
command) used.

Signed-off-by: Yunlong Song <yunlong.song@huawei.com>
---
 tools/perf/builtin-help.c | 9 +++++----
 tools/perf/perf.c         | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 09b0368..8cee457 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -287,10 +287,11 @@ void list_common_cmds_help(void)
 			longest = strlen(common_cmds[i].name);
 	}
 
-	puts(" The most commonly used perf commands are:");
+	fputs(" The most commonly used perf commands are:\n", stderr);
 	for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
-		printf("   %-*s   ", longest, common_cmds[i].name);
-		puts(common_cmds[i].help);
+		fprintf(stderr, "   %-*s   ", longest, common_cmds[i].name);
+		fputs(common_cmds[i].help, stderr);
+		fputc('\n', stderr);
 	}
 }
 
@@ -472,7 +473,7 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!argv[0]) {
 		usage_with_options_return(perf_usage, perf_options);
 		list_common_cmds_help();
-		printf("\n %s\n\n", perf_more_info_string);
+		fprintf(stderr, "\n %s\n\n", perf_more_info_string);
 		return 0;
 	}
 
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 3bcaa10d..54ef361 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -584,7 +584,7 @@ int main(int argc, const char **argv)
 		/* The user didn't specify a command; give them help */
 		usage_with_options_return(perf_usage, perf_options);
 		list_common_cmds_help();
-		printf("\n %s\n\n", perf_more_info_string);
+		fprintf(stderr, "\n %s\n\n", perf_more_info_string);
 		goto out;
 	}
 	cmd = argv[0];
-- 
1.8.5.2

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

[toc] | [prev] | [next] | [standalone]


#1247529 — [PATCH v2 0/3] perf help: Make perf's help consistent with other builtins

FromYunlong Song <yunlong.song@huawei.com>
Date2015-10-15 09:40 +0200
Subject[PATCH v2 0/3] perf help: Make perf's help consistent with other builtins
Message-ID<qjLiO-85x-5@gated-at.bofh.it>
In reply to#1246273
Hi,
  Make some fixes to perf's help for consistency.

Yunlong Song (3):
  perf help: Add options description to 'perf -h'
  perf help: Change 'usage' to 'Usage' for consistency
  perf help: Change the usage's stdout to stderr for consistency

 tools/perf/builtin-help.c       | 13 +++++++------
 tools/perf/builtin.h            |  3 +++
 tools/perf/perf.c               | 14 +++++++++-----
 tools/perf/util/parse-options.c | 11 +++++++++--
 tools/perf/util/parse-options.h |  3 +++
 5 files changed, 31 insertions(+), 13 deletions(-)

-- 
1.8.5.2

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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web