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


Groups > linux.kernel > #1255076 > unrolled thread

[GIT PULL 0/2] perf/core new features

Started byArnaldo Carvalho de Melo <acme@kernel.org>
First post2015-10-24 03:00 +0200
Last post2015-10-25 20:40 +0100
Articles 5 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [GIT PULL 0/2] perf/core new features Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-24 03:00 +0200
    [PATCH 1/2] perf tools: Show tool command line options ordered Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-24 03:00 +0200
    [PATCH 2/2] perf tools: Provide help for subset of options Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-24 03:00 +0200
    Re: [GIT PULL 0/2] perf/core new features Ingo Molnar <mingo@kernel.org> - 2015-10-25 09:50 +0100
      Re: [GIT PULL 0/2] perf/core new features Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-10-25 20:40 +0100

#1255076 — [GIT PULL 0/2] perf/core new features

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-24 03:00 +0200
Subject[GIT PULL 0/2] perf/core new features
Message-ID<qmVlE-1eL-1@gated-at.bofh.it>
Hi Ingo,

	Please consider pulling,

- Arnaldo

The following changes since commit 80fcd45ee05b4ef05e61d37a5ffb70a67095a9f6:

  Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2015-10-23 10:25:57 +0200)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo

for you to fetch changes up to 161d9041782b86c5493481566539bfc058ceeaff:

  perf tools: Provide help for subset of options (2015-10-23 21:50:50 -0300)

----------------------------------------------------------------
perf/core improvements:

New features:

- Show ordered command line options when -h is used or when an
  unknown option is specified (Arnaldo Carvalho de Melo)

- If options are passed after -h, show just its descriptions, not
  all options (Arnaldo Carvalho de Melo)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

----------------------------------------------------------------
Arnaldo Carvalho de Melo (2):
      perf tools: Show tool command line options ordered
      perf tools: Provide help for subset of options

 tools/perf/util/parse-options.c | 90 ++++++++++++++++++++++++++++++++++++-----
 1 file changed, 81 insertions(+), 9 deletions(-)
--
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]


#1255077 — [PATCH 1/2] perf tools: Show tool command line options ordered

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-24 03:00 +0200
Subject[PATCH 1/2] perf tools: Show tool command line options ordered
Message-ID<qmVlE-1eL-3@gated-at.bofh.it>
In reply to#1255076
From: Arnaldo Carvalho de Melo <acme@redhat.com>

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 <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-41qh68t35n4ehrpsuazp1dx8@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-options.c | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 8aa7922397a9..fb26532d67c3 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 <linux/string.h>
 
 #define OPT_SHORT 1
 #define OPT_UNSET 2
@@ -642,9 +643,50 @@ 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;
+
+	if (ret == 0) {
+		const char *la = a->long_name ?: "",
+			   *lb = b->long_name ?: "";
+		ret = strcmp(la, lb);
+	}
+
+	return ret;
+}
+
+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 +703,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

--
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]


#1255079 — [PATCH 2/2] perf tools: Provide help for subset of options

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-24 03:00 +0200
Subject[PATCH 2/2] perf tools: Provide help for subset of options
Message-ID<qmVlE-1eL-9@gated-at.bofh.it>
In reply to#1255076
From: Arnaldo Carvalho de Melo <acme@redhat.com>

Some tools have a lot of options, so, providing a way to show help just
for some of them may come handy:

  $ perf report -h --tui

   Usage: perf report [<options>]

        --tui             Use the TUI interface

  $ perf report -h --tui --showcpuutilization -b -c

   Usage: perf report [<options>]

    -b, --branch-stack    use branch records for per branch histogram filling
    -c, --comms <comm[,comm...]>
                          only consider symbols in these comms
        --showcpuutilization
                          Show sample percentage for different cpu modes
        --tui             Use the TUI interface

  $

Using it with perf bash completion is also handy, just make sure you
source the needed file:

  $ . ~/git/linux/tools/perf/perf-completion.sh

Then press tab/tab after -- to see a list of options, put them after -h
and only the options chosen will have its help presented:

  $ perf report -h --
  --asm-raw              --demangle-kernel      --group
  --kallsyms             --pretty               --stdio
  --branch-history       --disassembler-style   --gtk
  --max-stack            --showcpuutilization   --symbol-filter
  --branch-stack         --dsos                 --header
  --mem-mode             --show-info            --symbols
  --call-graph           --dump-raw-trace       --header-only
  --modules              --show-nr-samples      --symfs
  --children             --exclude-other        --hide-unresolved
  --objdump              --show-ref-call-graph  --threads
  --column-widths        --fields               --ignore-callees
  --parent               --show-total-period    --tid
  --comms                --field-separator      --input
  --percentage           --socket-filter        --tui
  --cpu                  --force                --inverted
  --percent-limit        --sort                 --verbose
  --demangle             --full-source-path     --itrace
  --pid                  --source               --vmlinux
  $ perf report -h --socket-filter

   Usage: perf report [<options>]

      --socket-filter <n>
                  only show processor socket that match with this filter

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-83mcdd3wj0379jcgea8w0fxa@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/parse-options.c | 42 ++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index fb26532d67c3..22c2806bda98 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -373,7 +373,8 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
 }
 
 static int usage_with_options_internal(const char * const *,
-				       const struct option *, int);
+				       const struct option *, int,
+				       struct parse_opt_ctx_t *);
 
 int parse_options_step(struct parse_opt_ctx_t *ctx,
 		       const struct option *options,
@@ -397,8 +398,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 
 		if (arg[1] != '-') {
 			ctx->opt = ++arg;
-			if (internal_help && *ctx->opt == 'h')
-				return usage_with_options_internal(usagestr, options, 0);
+			if (internal_help && *ctx->opt == 'h') {
+				return usage_with_options_internal(usagestr, options, 0, ctx);
+			}
 			switch (parse_short_opt(ctx, options)) {
 			case -1:
 				return parse_options_usage(usagestr, options, arg, 1);
@@ -413,7 +415,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 				check_typos(arg, options);
 			while (ctx->opt) {
 				if (internal_help && *ctx->opt == 'h')
-					return usage_with_options_internal(usagestr, options, 0);
+					return usage_with_options_internal(usagestr, options, 0, ctx);
 				arg = ctx->opt;
 				switch (parse_short_opt(ctx, options)) {
 				case -1:
@@ -446,9 +448,9 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
 
 		arg += 2;
 		if (internal_help && !strcmp(arg, "help-all"))
-			return usage_with_options_internal(usagestr, options, 1);
+			return usage_with_options_internal(usagestr, options, 1, ctx);
 		if (internal_help && !strcmp(arg, "help"))
-			return usage_with_options_internal(usagestr, options, 0);
+			return usage_with_options_internal(usagestr, options, 0, ctx);
 		if (!strcmp(arg, "list-opts"))
 			return PARSE_OPT_LIST_OPTS;
 		if (!strcmp(arg, "list-cmds"))
@@ -682,8 +684,27 @@ out:
 	return ordered;
 }
 
+static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx)
+{
+	int i;
+
+	for (i = 1; i < ctx->argc; ++i) {
+		const char *arg = ctx->argv[i];
+
+		if (arg[0] != '-')
+			continue;
+
+		if (arg[1] == opt->short_name ||
+		    (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0))
+			return true;
+	}
+
+	return false;
+}
+
 int usage_with_options_internal(const char * const *usagestr,
-				const struct option *opts, int full)
+				const struct option *opts, int full,
+				struct parse_opt_ctx_t *ctx)
 {
 	struct option *ordered;
 
@@ -707,8 +728,11 @@ int usage_with_options_internal(const char * const *usagestr,
 	if (ordered)
 		opts = ordered;
 
-	for (  ; opts->type != OPTION_END; opts++)
+	for (  ; opts->type != OPTION_END; opts++) {
+		if (ctx && ctx->argc > 1 && !option__in_argv(opts, ctx))
+			continue;
 		print_option_help(opts, full);
+	}
 
 	fputc('\n', stderr);
 
@@ -721,7 +745,7 @@ void usage_with_options(const char * const *usagestr,
 			const struct option *opts)
 {
 	exit_browser(false);
-	usage_with_options_internal(usagestr, opts, 0);
+	usage_with_options_internal(usagestr, opts, 0, NULL);
 	exit(129);
 }
 
-- 
2.1.0

--
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]


#1255309

FromIngo Molnar <mingo@kernel.org>
Date2015-10-25 09:50 +0100
Message-ID<qnpa2-8lF-9@gated-at.bofh.it>
In reply to#1255076
* Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> Hi Ingo,
> 
> 	Please consider pulling,
> 
> - Arnaldo
> 
> The following changes since commit 80fcd45ee05b4ef05e61d37a5ffb70a67095a9f6:
> 
>   Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2015-10-23 10:25:57 +0200)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo
> 
> for you to fetch changes up to 161d9041782b86c5493481566539bfc058ceeaff:
> 
>   perf tools: Provide help for subset of options (2015-10-23 21:50:50 -0300)
> 
> ----------------------------------------------------------------
> perf/core improvements:
> 
> New features:
> 
> - Show ordered command line options when -h is used or when an
>   unknown option is specified (Arnaldo Carvalho de Melo)
> 
> - If options are passed after -h, show just its descriptions, not
>   all options (Arnaldo Carvalho de Melo)

Very nice!

> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> ----------------------------------------------------------------
> Arnaldo Carvalho de Melo (2):
>       perf tools: Show tool command line options ordered
>       perf tools: Provide help for subset of options
> 
>  tools/perf/util/parse-options.c | 90 ++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 81 insertions(+), 9 deletions(-)

Pulled, thanks a lot Arnaldo!

So I tested this a bit, and the ordering works well.

What wasn't so obvious to me was behavior like:

  triton:~/tip> perf report -h x

   Usage: perf report [<options>]


  triton:~/tip> 

  triton:~/tip> perf report -h exclude-other

   Usage: perf report [<options>]


  triton:~/tip> 

I.e. it outputs nothing and does not tell the user what's wrong.

Then I figured out the right syntax:

  triton:~/tip> perf report -h --exclude-other

   Usage: perf report [<options>]

      -x, --exclude-other   Only display entries with parent-match

  triton:~/tip> 

:)

So maybe we should also try a search for the option name with a '-' and '--' 
prepended? Also, my pet peeve are partial matches:

  triton:~/tip> perf report -h --exclude

   Usage: perf report [<options>]


  triton:~/tip> 

But in any case it's a nice step forward!

	Ingo
--
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]


#1255538

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2015-10-25 20:40 +0100
Message-ID<qnzj4-6ZB-11@gated-at.bofh.it>
In reply to#1255309
Em Sun, Oct 25, 2015 at 09:46:07AM +0100, Ingo Molnar escreveu:
> 
> * Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> 
> > Hi Ingo,
> > 
> > 	Please consider pulling,
> > 
> > - Arnaldo
> > 
> > The following changes since commit 80fcd45ee05b4ef05e61d37a5ffb70a67095a9f6:
> > 
> >   Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core (2015-10-23 10:25:57 +0200)
> > 
> > are available in the git repository at:
> > 
> >   git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git tags/perf-core-for-mingo
> > 
> > for you to fetch changes up to 161d9041782b86c5493481566539bfc058ceeaff:
> > 
> >   perf tools: Provide help for subset of options (2015-10-23 21:50:50 -0300)
> > 
> > ----------------------------------------------------------------
> > perf/core improvements:
> > 
> > New features:
> > 
> > - Show ordered command line options when -h is used or when an
> >   unknown option is specified (Arnaldo Carvalho de Melo)
> > 
> > - If options are passed after -h, show just its descriptions, not
> >   all options (Arnaldo Carvalho de Melo)
> 
> Very nice!
> 
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> > 
> > ----------------------------------------------------------------
> > Arnaldo Carvalho de Melo (2):
> >       perf tools: Show tool command line options ordered
> >       perf tools: Provide help for subset of options
> > 
> >  tools/perf/util/parse-options.c | 90 ++++++++++++++++++++++++++++++++++++-----
> >  1 file changed, 81 insertions(+), 9 deletions(-)
> 
> Pulled, thanks a lot Arnaldo!
> 
> So I tested this a bit, and the ordering works well.
> 
> What wasn't so obvious to me was behavior like:
> 
>   triton:~/tip> perf report -h x
> 
>    Usage: perf report [<options>]

I'll fix that, and also make it search the provided key as a substring
in the event descriptions, like 'perf list' does now, does that sound ok?

- Arnaldo
 
> 
>   triton:~/tip> 
> 
>   triton:~/tip> perf report -h exclude-other
> 
>    Usage: perf report [<options>]
> 
> 
>   triton:~/tip> 
> 
> I.e. it outputs nothing and does not tell the user what's wrong.
> 
> Then I figured out the right syntax:
> 
>   triton:~/tip> perf report -h --exclude-other
> 
>    Usage: perf report [<options>]
> 
>       -x, --exclude-other   Only display entries with parent-match
> 
>   triton:~/tip> 
> 
> :)
> 
> So maybe we should also try a search for the option name with a '-' and '--' 
> prepended? Also, my pet peeve are partial matches:
> 
>   triton:~/tip> perf report -h --exclude
> 
>    Usage: perf report [<options>]
> 
> 
>   triton:~/tip> 
> 
> But in any case it's a nice step forward!
> 
> 	Ingo
--
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