From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752433AbbJWO1Z (ORCPT ); Fri, 23 Oct 2015 10:27:25 -0400 Received: from mail.kernel.org ([198.145.29.136]:33569 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751543AbbJWO1Y (ORCPT ); Fri, 23 Oct 2015 10:27:24 -0400 Date: Fri, 23 Oct 2015 11:27:15 -0300 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Namhyung Kim , Peter Zijlstra , Jiri Olsa , LKML , David Ahern , Adrian Hunter , Borislav Petkov , Chandler Carruth , Frederic Weisbecker , Stephane Eranian , Wang Nan , Brendan Gregg Subject: Re: [PATCH 1/3] perf tools: Move callchain help messages to callchain.h Message-ID: <20151023142715.GE27006@kernel.org> References: <1445495330-25416-1-git-send-email-namhyung@kernel.org> <20151022080204.GA18916@gmail.com> <20151023095932.GA22657@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20151023095932.GA22657@gmail.com> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Oct 23, 2015 at 11:59:32AM +0200, Ingo Molnar escreveu: > Btw., another usability detail I noticed yesterday is that when I typed 'perf > report -h' I got so much output that I couldn't find the specific option I was > looking for, because there's no apparent ordering of the output: > > triton:~/tip> perf report -h 2>&1 | grep -e ' -[a-Z],' > -i, --input input file name > -v, --verbose be more verbose (show symbol address, etc) > -D, --dump-raw-trace dump raw trace in ASCII SNIP: > -C, --cpu list of cpus to profile > -I, --show-info Display extended information about perf.data file > -M, --disassembler-style > -b, --branch-stack use branch records for per branch histogram filling > > Such (alphabetic) ordering would be easier to navigate: > > -b, --branch-stack use branch records for per branch histogram filling > -c, --comms > -C, --cpu list of cpus to profile Try the patch below: >>From 182ec8d7c105e331884def4f98f56b4f876a4f1d Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Fri, 23 Oct 2015 11:23:28 -0300 Subject: [PATCH 1/1] perf tools: Show tool command line options ordered When asking for a listing of the options, be it using -h or when an unknown option is passed, order it by one-letter options, then the ones having just long names. Suggested-by: Ingo Molnar Cc: Adrian Hunter Cc: Borislav Petkov Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-41qh68t35n4ehrpsuazp1dx8@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-options.c | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 8aa7922397a9..47fb1405df7e 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -2,6 +2,7 @@ #include "parse-options.h" #include "cache.h" #include "header.h" +#include #define OPT_SHORT 1 #define OPT_UNSET 2 @@ -642,9 +643,44 @@ static void print_option_help(const struct option *opts, int full) fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help); } +static int option__cmp(const void *va, const void *vb) +{ + const struct option *a = va, *b = vb; + int sa = tolower(a->short_name), sb = tolower(b->short_name), ret; + + if (sa == 0) + sa = 'z' + 1; + if (sb == 0) + sb = 'z' + 1; + + ret = sa - sb; + + return ret ?: strcmp(a->long_name, b->long_name); +} + +static struct option *options__order(const struct option *opts) +{ + int nr_opts = 0; + const struct option *o = opts; + struct option *ordered; + + for (o = opts; o->type != OPTION_END; o++) + ++nr_opts; + + ordered = memdup(opts, sizeof(*o) * (nr_opts + 1)); + if (ordered == NULL) + goto out; + + qsort(ordered, nr_opts, sizeof(*o), option__cmp); +out: + return ordered; +} + int usage_with_options_internal(const char * const *usagestr, const struct option *opts, int full) { + struct option *ordered; + if (!usagestr) return PARSE_OPT_HELP; @@ -661,11 +697,17 @@ int usage_with_options_internal(const char * const *usagestr, if (opts->type != OPTION_GROUP) fputc('\n', stderr); + ordered = options__order(opts); + if (ordered) + opts = ordered; + for ( ; opts->type != OPTION_END; opts++) print_option_help(opts, full); fputc('\n', stderr); + free(ordered); + return PARSE_OPT_HELP; } -- 2.1.0