All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>
Cc: <lizefan@huawei.com>, <pi3orama@163.com>,
	<linux-kernel@vger.kernel.org>, Wang Nan <wangnan0@huawei.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Namhyung Kim <namhyung@kernel.org>
Subject: [PATCH 1/2] perf tools: Always give options even it not compiled
Date: Thu, 19 Nov 2015 14:03:12 +0000	[thread overview]
Message-ID: <1447941793-118639-2-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1447941793-118639-1-git-send-email-wangnan0@huawei.com>

This patch keeps options of perf builtins same in all condition. If the
option is disabled because of compiling options, users should be
notified.

This patch does it by introducing a series of new option macros, flags
and field in struct options. For those options disabled by compiling,
OPT_NOTBUILT_NOARG, OPT_NOTBUILT_OPTARG and OPT_NOTBUILT can be used
to record the help messages and the reason why not built them.

Options in 'perf record' and 'perf probe' are fixed by those new macros.

Test result:

- Normal result:
 # ./perf probe -L sys_write
 <SyS_write@/path/to/kernel/fs/read_write.c:0>
       0  SYSCALL_DEFINE3(write, unsigned int, fd, const char __user *, buf,
 ...

- Build with NO_DWARF=1:

 # ./perf probe -L sys_write
 ERROR: option '--line' is not built (disabled by NO_DWARF)

  Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
     or: perf probe [<options>] --del '[GROUP:]EVENT' ...
     or: perf probe --list [GROUP:]EVENT ...
     or: perf probe [<options>] --funcs

     -L, --line <FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]>
                           Show source code lines.
                           (disabled by NO_DWARF)

 # ./perf probe -k /tmp/vmlinux sys_write
 WARNING: option '--vmlinux' is not built (disabled by NO_DWARF)
 Added new event:
   probe:sys_write      (on sys_write)

 You can now use it in all perf tools, such as:

 	perf record -e probe:sys_write -aR sleep 1

 # ./perf probe -k sys_write

  Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
  ...

- Help messages:

 # ./perf probe -h

  Usage: perf probe [<options>] 'PROBEDEF' ['PROBEDEF' ...]
     or: perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]
  ...
     -k, --vmlinux <file>  vmlinux pathname
                           (disabled by NO_DWARF)
     -L, --line <FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]>
                           Show source code lines.
                           (disabled by NO_DWARF)
     -l, --list <[GROUP:]EVENT>
                           list up probe events
  ...
     -s, --source <directory>
                           path to kernel source
                           (disabled by NO_DWARF)
     -V, --vars <FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT>
                           Show accessible variables on PROBEDEF
                           (disabled by NO_DWARF)
  ...
         --no-inlines      Don't search inlined functions
                           (disabled by NO_DWARF)
         --range           Show variables location range in scope (with --vars only)
                           (disabled by NO_DWARF)

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/builtin-probe.c      | 23 +++++++++++++++++++++++
 tools/perf/builtin-record.c     |  7 +++++++
 tools/perf/util/parse-options.c | 30 +++++++++++++++++++++++++++++-
 tools/perf/util/parse-options.h | 16 ++++++++++++++++
 4 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index 132afc9..4d7cf57 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -490,6 +490,29 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "directory", "path to kernel source"),
 	OPT_BOOLEAN('\0', "no-inlines", &probe_conf.no_inlines,
 		"Don't search inlined functions"),
+#else
+#define DISABLE_MSG	"disabled by NO_DWARF"
+	OPT_NOTBUILT('L', "line",
+		     "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
+		     "Show source code lines.",
+		     DISABLE_MSG, false),
+	OPT_NOTBUILT('V', "vars",
+		     "FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT",
+		     "Show accessible variables on PROBEDEF",
+		     DISABLE_MSG, false),
+	OPT_NOTBUILT_NOARG('\0', "externs",
+			   "Show external variables too (with --vars only)",
+			   DISABLE_MSG, false),
+	OPT_NOTBUILT_NOARG('\0', "range",
+			   "Show variables location range in scope (with --vars only)",
+			   DISABLE_MSG, false),
+	OPT_NOTBUILT('k', "vmlinux", "file", "vmlinux pathname",
+		     DISABLE_MSG, true),
+	OPT_NOTBUILT('s', "source", "directory", "path to kernel source",
+		     DISABLE_MSG, true),
+	OPT_NOTBUILT_NOARG('\0', "no-inlines", "Don't search inlined functions",
+			   DISABLE_MSG, true),
+#undef DISABLE_MSG
 #endif
 	OPT__DRY_RUN(&probe_event_dry_run),
 	OPT_INTEGER('\0', "max-probes", &probe_conf.max_probes,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 199fc31..b02d1ee 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1118,6 +1118,13 @@ struct option __record_options[] = {
 		   "clang binary to use for compiling BPF scriptlets"),
 	OPT_STRING(0, "clang-opt", &llvm_param.clang_opt, "clang options",
 		   "options passed to clang when compiling BPF scriptlets"),
+#else
+	OPT_NOTBUILT(0, "clang-path", "clang path",
+		     "clang binary to use for compiling BPF scriptlets",
+		     "disabled by NO_LIBBPF", true),
+	OPT_NOTBUILT(0, "clang-opt", "clang options",
+		     "options passed to clang when compiling BPF scriptlets",
+		     "disabled by NO_LIBBPF", true),
 #endif
 	OPT_END()
 };
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 9fca092..5c3eb7a 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -1,4 +1,5 @@
 #include "util.h"
+#include "debug.h"
 #include "parse-options.h"
 #include "cache.h"
 #include "header.h"
@@ -69,6 +70,7 @@ static int get_value(struct parse_opt_ctx_t *p,
 	if (!(flags & OPT_SHORT) && p->opt) {
 		switch (opt->type) {
 		case OPTION_CALLBACK:
+		case OPTION_NOTBUILT:
 			if (!(opt->flags & PARSE_OPT_NOARG))
 				break;
 			/* FALLTHROUGH */
@@ -152,7 +154,28 @@ static int get_value(struct parse_opt_ctx_t *p,
 		if (get_arg(p, opt, flags, &arg))
 			return -1;
 		return (*opt->callback)(opt, arg, 0) ? (-1) : 0;
-
+	case OPTION_NOTBUILT: {
+		char short_str[2] = {opt->short_name, '\0'};
+		int ret = -1;
+
+		pr_warning("%s: option '-%s%s' is not built (%s)\n",
+			   opt->flags & PARSE_OPT_CANSKIP ?
+				"WARNING" : "ERROR",
+			   opt->long_name ? "-" : short_str,
+			   opt->long_name ? : "",
+			   opt->notbuild_reason);
+		if (opt->flags & PARSE_OPT_CANSKIP)
+			ret = 0;
+		if (unset)
+			return ret;
+		if (opt->flags & PARSE_OPT_NOARG)
+			return ret;
+		if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
+			return ret;
+		if (get_arg(p, opt, flags, &arg))
+			return -1;
+		return ret;
+	}
 	case OPTION_INTEGER:
 		if (unset) {
 			*(int *)opt->value = 0;
@@ -607,6 +630,7 @@ static void print_option_help(const struct option *opts, int full)
 			pos += fprintf(stderr, " <n>");
 		break;
 	case OPTION_CALLBACK:
+	case OPTION_NOTBUILT:
 		if (opts->flags & PARSE_OPT_NOARG)
 			break;
 		/* FALLTHROUGH */
@@ -647,6 +671,10 @@ static void print_option_help(const struct option *opts, int full)
 		pad = USAGE_OPTS_WIDTH;
 	}
 	fprintf(stderr, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
+	if (opts->type == OPTION_NOTBUILT)
+		fprintf(stderr, "%*s(%s)\n",
+			USAGE_OPTS_WIDTH + USAGE_GAP, "",
+			opts->notbuild_reason);
 }
 
 static int option__cmp(const void *va, const void *vb)
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
index a8e407b..08cc9b5 100644
--- a/tools/perf/util/parse-options.h
+++ b/tools/perf/util/parse-options.h
@@ -22,6 +22,7 @@ enum parse_opt_type {
 	OPTION_CALLBACK,
 	OPTION_U64,
 	OPTION_UINTEGER,
+	OPTION_NOTBUILT,
 };
 
 enum parse_opt_flags {
@@ -41,6 +42,7 @@ enum parse_opt_option_flags {
 	PARSE_OPT_DISABLED = 32,
 	PARSE_OPT_EXCLUSIVE = 64,
 	PARSE_OPT_NOEMPTY  = 128,
+	PARSE_OPT_CANSKIP  = 256,
 };
 
 struct option;
@@ -96,6 +98,7 @@ struct option {
 	void *value;
 	const char *argh;
 	const char *help;
+	const char *notbuild_reason;
 
 	int flags;
 	parse_opt_cb *callback;
@@ -146,6 +149,19 @@ struct option {
 	  .value = (v), (a), .help = (h), .callback = (f), \
 	  .flags = PARSE_OPT_OPTARG, .data = (d) }
 
+#define OPT_NOTBUILT_NOARG(s, l, h, r, skip) \
+	{ .type = OPTION_NOTBUILT, .short_name = (s), .long_name = (l), \
+	  .help = (h), .notbuild_reason = (r), \
+	 .flags = PARSE_OPT_NOARG | (skip ? PARSE_OPT_CANSKIP : 0)}
+#define OPT_NOTBUILT_OPTARG(s, l, a, h, r, skip) \
+	{ .type = OPTION_NOTBUILT, .short_name = (s), .long_name = (l), \
+	  .argh = (a), .help = (h), .notbuild_reason = (r), \
+	  .flags = PARSE_OPT_OPTARG | (skip ? PARSE_OPT_CANSKIP : 0)}
+#define OPT_NOTBUILT(s, l, a, h, r, skip) \
+	{ .type = OPTION_NOTBUILT, .short_name = (s), .long_name = (l), \
+	  .argh = (a), .help = (h), .notbuild_reason = (r), \
+	  .flags = skip ? PARSE_OPT_CANSKIP : 0}
+
 /* parse_options() will filter out the processed options and leave the
  * non-option argments in argv[].
  * Returns the number of arguments left in argv[].
-- 
1.8.3.4


  reply	other threads:[~2015-11-19 14:04 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 12:10 [PATCH 00/13] perf tools: bpf: Improve BPF program ability Wang Nan
2015-11-16 12:10 ` [PATCH 01/13] perf probe: Fix memory leaking on faiulre by clearing all probe_trace_events Wang Nan
2015-11-16 12:10 ` [PATCH 02/13] perf probe: Clear probe_trace_event when add_probe_trace_event() fails Wang Nan
2015-11-16 12:10 ` [PATCH 03/13] perf tools: Allow BPF program attach to uprobe events Wang Nan
2015-11-16 14:14   ` Arnaldo Carvalho de Melo
2015-11-23 16:06   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 04/13] perf tools: Allow BPF program attach to modules Wang Nan
2015-11-23 16:06   ` [tip:perf/core] perf bpf: Allow attaching BPF programs to modules symbols tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 05/13] perf tools: Introduce strtobool() to string.c Wang Nan
2015-11-16 14:17   ` Arnaldo Carvalho de Melo
2015-11-16 14:49     ` Arnaldo Carvalho de Melo
2015-11-16 15:55       ` Arnaldo Carvalho de Melo
2015-11-23 16:04   ` [tip:perf/core] tools: Clone the kernel's strtobool function tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 06/13] perf tools: Allow BPF program config probing options Wang Nan
2015-11-23 16:06   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 07/13] bpf tools: Load a program with different instances using preprocessor Wang Nan
2015-11-16 19:02   ` Arnaldo Carvalho de Melo
2015-11-17  3:53     ` Wangnan (F)
2015-11-23 16:05   ` [tip:perf/core] " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 08/13] perf tools: Add BPF_PROLOGUE config options for further patches Wang Nan
2015-11-23 16:05   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 09/13] perf tools: Compile dwarf-regs.c if CONFIG_BPF_PROLOGUE is on Wang Nan
2015-11-23 16:05   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 10/13] perf tools: Add prologue for BPF programs for fetching arguments Wang Nan
2015-11-23 16:07   ` [tip:perf/core] perf bpf: " tip-bot for He Kuang
2015-11-16 12:10 ` [PATCH 11/13] perf tools: Generate prologue for BPF programs Wang Nan
2015-11-23 16:07   ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 12/13] perf test: Test BPF prologue Wang Nan
2015-11-17  1:29   ` Arnaldo Carvalho de Melo
2015-11-17  1:31     ` Wangnan (F)
2015-11-17  4:38     ` Wangnan (F)
2015-11-17 12:20       ` Arnaldo Carvalho de Melo
2015-11-17  8:32     ` [PATCH 0/5] perf tools: Improve BPF support Wang Nan
2015-11-17  8:32       ` [PATCH 1/5] perf test: Fix 2 bugs in 'perf test BPF' Wang Nan
2015-11-17 12:56         ` Arnaldo Carvalho de Melo
2015-11-17 13:01           ` pi3orama
2015-11-17 13:34             ` Arnaldo Carvalho de Melo
2015-11-23 16:08         ` [tip:perf/core] perf test: Fix 'perf test BPF' when it fails to find a suitable vmlinux tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 2/5] perf tools: Use same BPF program if arguments are identical Wang Nan
2015-11-23 16:08         ` [tip:perf/core] perf bpf: " tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 3/5] perf test: Print result for each subtest for llvm Wang Nan
2015-11-17 13:03         ` Arnaldo Carvalho de Melo
2015-11-23 16:09         ` [tip:perf/core] perf test: Print result for each LLVM subtest tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 4/5] perf test: Print result for each subtest for BPF Wang Nan
2015-11-23 16:09         ` [tip:perf/core] perf test: Print result for each BPF subtest tip-bot for Wang Nan
2015-11-17  8:32       ` [PATCH 5/5] perf test: Mute test cases if verbose == 0 Wang Nan
2015-11-17 13:11         ` Arnaldo Carvalho de Melo
2015-11-23 16:10         ` [tip:perf/core] perf test: Mute test cases error messages " tip-bot for Wang Nan
2015-11-17  8:38     ` [PATCH 12/13] perf test: Test BPF prologue Wangnan (F)
2015-11-17  9:44     ` [PATCH] perf record: Support custom vmlinux path Wang Nan
2015-11-17 12:33       ` Arnaldo Carvalho de Melo
2015-11-17 12:42         ` Arnaldo Carvalho de Melo
2015-11-17 12:45           ` pi3orama
2015-11-19 14:03           ` [PATCH 0/2] perf tools: Builtin options related improvements Wang Nan
2015-11-19 14:03             ` Wang Nan [this message]
2015-11-20 10:54               ` [PATCH 1/2] perf tools: Always give options even it not compiled 平松雅巳 / HIRAMATU,MASAMI
2015-11-26  8:05                 ` Wangnan (F)
2015-11-26  9:06                   ` Wangnan (F)
2015-11-19 14:03             ` [PATCH 2/2] perf record: Support custom vmlinux path Wang Nan
2015-11-23 16:08   ` [tip:perf/core] perf test: Test the BPF prologue adding infrastructure tip-bot for Wang Nan
2015-11-16 12:10 ` [PATCH 13/13] perf tools: Use same BPF program if arguments are identical Wang Nan
2015-11-17  3:05   ` Wangnan (F)
2015-11-17 13:16     ` Arnaldo Carvalho de Melo
2015-11-16 14:09 ` [PATCH 00/13] perf tools: bpf: Improve BPF program ability Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447941793-118639-2-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ast@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=namhyung@kernel.org \
    --cc=pi3orama@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.