Skip to contentSkip to conversation

perf/core new features

GIT PULL New Arnaldo Carvalho de Melo 2 participants 5 messages Oct 24, 2015 – Oct 25, 2015 perf events

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

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)

----------------------------------------------------------------
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(-)
author maintainer
#1 lore raw

PATCH 1/2 perf tools: Show tool command line options ordered

From: Arnaldo Carvalho de Melo <[email protected]>

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.

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brendan Gregg <[email protected]>
Cc Chandler Carruth <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/util/parse-options.c | 48 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
tools/perf/util/parse-options.c +48 -0
index 8aa7922397a9..fb26532d67c3 100644
@@ -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;
 }
 
Signature · 1 line
2.1.0
author maintainer
#2 lore raw

PATCH 2/2 perf tools: Provide help for subset of options

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

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

Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Brendan Gregg <[email protected]>
Cc Chandler Carruth <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Wang Nan <[email protected]>
---
 tools/perf/util/parse-options.c | 42 ++++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)
tools/perf/util/parse-options.c +33 -9
index fb26532d67c3..22c2806bda98 100644
@@ -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);
 }
 
Signature · 1 line
2.1.0
#3 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 21 lines · Arnaldo Carvalho de Melo

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:

Quoted 7 lines

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!

Quoted 9 lines

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

author maintainer
#4 lore raw

Em Sun, Oct 25, 2015 at 09:46:07AM +0100, Ingo Molnar escreveu:

Quoted 46 lines · Arnaldo Carvalho de Melo
Quoted 22 lines

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:

Quoted 7 lines

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!

Quoted 9 lines

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

Quoted 7 lines

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

Quoted 37 lines

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