netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>, Andi Kleen <ak@linux.intel.com>,
	Jin Yao <yao.jin@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	John Garry <john.garry@huawei.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bpf@vger.kernel.org, clang-built-linux@googlegroups.com
Cc: Stephane Eranian <eranian@google.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH v5 10/10] perf tools: report initial event parsing error
Date: Wed, 30 Oct 2019 15:34:48 -0700	[thread overview]
Message-ID: <20191030223448.12930-11-irogers@google.com> (raw)
In-Reply-To: <20191030223448.12930-1-irogers@google.com>

Record the first event parsing error and report. Implementing feedback
from Jiri Olsa:
https://lkml.org/lkml/2019/10/28/680

An example error is:

$ tools/perf/perf stat -e c/c/
WARNING: multiple event parsing errors
event syntax error: 'c/c/'
                       \___ unknown term

valid terms: event,filter_rem,filter_opc0,edge,filter_isoc,filter_tid,filter_loc,filter_nc,inv,umask,filter_opc1,tid_en,thresh,filter_all_op,filter_not_nm,filter_state,filter_nm,config,config1,config2,name,period,percore

Initial error:
event syntax error: 'c/c/'
                    \___ Cannot find PMU `c'. Missing kernel support?
Run 'perf list' for a list of valid events

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

    -e, --event <event>   event selector. use 'perf list' to list available events

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/arch/powerpc/util/kvm-stat.c |  9 ++-
 tools/perf/builtin-stat.c               |  2 +
 tools/perf/builtin-trace.c              | 16 ++++--
 tools/perf/tests/parse-events.c         |  3 +-
 tools/perf/util/metricgroup.c           |  2 +-
 tools/perf/util/parse-events.c          | 73 ++++++++++++++++++-------
 tools/perf/util/parse-events.h          |  4 ++
 7 files changed, 82 insertions(+), 27 deletions(-)

diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c b/tools/perf/arch/powerpc/util/kvm-stat.c
index 9cc1c4a9dec4..30f5310373ca 100644
--- a/tools/perf/arch/powerpc/util/kvm-stat.c
+++ b/tools/perf/arch/powerpc/util/kvm-stat.c
@@ -113,10 +113,15 @@ static int is_tracepoint_available(const char *str, struct evlist *evlist)
 	struct parse_events_error err;
 	int ret;
 
-	err.str = NULL;
+	bzero(&err, sizeof(err));
 	ret = parse_events(evlist, str, &err);
-	if (err.str)
+	if (err.str) {
 		pr_err("%s : %s\n", str, err.str);
+		free(&err->str);
+		free(&err->help);
+		free(&err->first_str);
+		free(&err->first_help);
+	}
 	return ret;
 }
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c88d4e118409..5d2fc8bed5f8 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1260,6 +1260,7 @@ static int add_default_attributes(void)
 	if (stat_config.null_run)
 		return 0;
 
+	bzero(&errinfo, sizeof(errinfo));
 	if (transaction_run) {
 		/* Handle -T as -M transaction. Once platform specific metrics
 		 * support has been added to the json files, all archictures
@@ -1317,6 +1318,7 @@ static int add_default_attributes(void)
 			return -1;
 		}
 		if (err) {
+			parse_events_print_error(&errinfo, smi_cost_attrs);
 			fprintf(stderr, "Cannot set up SMI cost events\n");
 			return -1;
 		}
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 43c05eae1768..46a72ecac427 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3016,11 +3016,18 @@ static bool evlist__add_vfs_getname(struct evlist *evlist)
 {
 	bool found = false;
 	struct evsel *evsel, *tmp;
-	struct parse_events_error err = { .idx = 0, };
-	int ret = parse_events(evlist, "probe:vfs_getname*", &err);
+	struct parse_events_error err;
+	int ret;
 
-	if (ret)
+	bzero(&err, sizeof(err));
+	ret = parse_events(evlist, "probe:vfs_getname*", &err);
+	if (ret) {
+		free(err.str);
+		free(err.help);
+		free(err.first_str);
+		free(err.first_help);
 		return false;
+	}
 
 	evlist__for_each_entry_safe(evlist, evsel, tmp) {
 		if (!strstarts(perf_evsel__name(evsel), "probe:vfs_getname"))
@@ -4832,8 +4839,9 @@ int cmd_trace(int argc, const char **argv)
 	 * wrong in more detail.
 	 */
 	if (trace.perfconfig_events != NULL) {
-		struct parse_events_error parse_err = { .idx = 0, };
+		struct parse_events_error parse_err;
 
+		bzero(&parse_err, sizeof(parse_err));
 		err = parse_events(trace.evlist, trace.perfconfig_events, &parse_err);
 		if (err) {
 			parse_events_print_error(&parse_err, trace.perfconfig_events);
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 25e0ed2eedfc..091c3aeccc27 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1768,10 +1768,11 @@ static struct terms_test test__terms[] = {
 
 static int test_event(struct evlist_test *e)
 {
-	struct parse_events_error err = { .idx = 0, };
+	struct parse_events_error err;
 	struct evlist *evlist;
 	int ret;
 
+	bzero(&err, sizeof(err));
 	if (e->valid && !e->valid()) {
 		pr_debug("... SKIP");
 		return 0;
diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index a7c0424dbda3..6a4d350d5cdb 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -523,7 +523,7 @@ int metricgroup__parse_groups(const struct option *opt,
 	if (ret)
 		return ret;
 	pr_debug("adding %s\n", extra_events.buf);
-	memset(&parse_error, 0, sizeof(struct parse_events_error));
+	bzero(&parse_error, sizeof(parse_error));
 	ret = parse_events(perf_evlist, extra_events.buf, &parse_error);
 	if (ret) {
 		parse_events_print_error(&parse_error, extra_events.buf);
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6d18ff9bce49..28fa6ec7d2a2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -189,12 +189,29 @@ void parse_events__handle_error(struct parse_events_error *err, int idx,
 		free(help);
 		return;
 	}
-	WARN_ONCE(err->str, "WARNING: multiple event parsing errors\n");
-	err->idx = idx;
-	free(err->str);
-	err->str = str;
-	free(err->help);
-	err->help = help;
+	switch (err->num_errors) {
+	case 0:
+		err->idx = idx;
+		err->str = str;
+		err->help = help;
+		break;
+	case 1:
+		err->first_idx = err->idx;
+		err->idx = idx;
+		err->first_str = err->str;
+		err->str = str;
+		err->first_help = err->help;
+		err->help = help;
+		break;
+	default:
+		WARN_ONCE(1, "WARNING: multiple event parsing errors\n");
+		free(err->str);
+		err->str = str;
+		free(err->help);
+		err->help = help;
+		break;
+	}
+	err->num_errors++;
 }
 
 struct tracepoint_path *tracepoint_id_to_path(u64 config)
@@ -2007,15 +2024,14 @@ static int get_term_width(void)
 	return ws.ws_col > MAX_WIDTH ? MAX_WIDTH : ws.ws_col;
 }
 
-void parse_events_print_error(struct parse_events_error *err,
-			      const char *event)
+static void __parse_events_print_error(int err_idx, const char *err_str,
+				const char *err_help, const char *event)
 {
 	const char *str = "invalid or unsupported event: ";
 	char _buf[MAX_WIDTH];
 	char *buf = (char *) event;
 	int idx = 0;
-
-	if (err->str) {
+	if (err_str) {
 		/* -2 for extra '' in the final fprintf */
 		int width       = get_term_width() - 2;
 		int len_event   = strlen(event);
@@ -2038,8 +2054,8 @@ void parse_events_print_error(struct parse_events_error *err,
 		buf = _buf;
 
 		/* We're cutting from the beginning. */
-		if (err->idx > max_err_idx)
-			cut = err->idx - max_err_idx;
+		if (err_idx > max_err_idx)
+			cut = err_idx - max_err_idx;
 
 		strncpy(buf, event + cut, max_len);
 
@@ -2052,16 +2068,33 @@ void parse_events_print_error(struct parse_events_error *err,
 			buf[max_len] = 0;
 		}
 
-		idx = len_str + err->idx - cut;
+		idx = len_str + err_idx - cut;
 	}
 
 	fprintf(stderr, "%s'%s'\n", str, buf);
 	if (idx) {
-		fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err->str);
-		if (err->help)
-			fprintf(stderr, "\n%s\n", err->help);
-		zfree(&err->str);
-		zfree(&err->help);
+		fprintf(stderr, "%*s\\___ %s\n", idx + 1, "", err_str);
+		if (err_help)
+			fprintf(stderr, "\n%s\n", err_help);
+	}
+}
+
+void parse_events_print_error(struct parse_events_error *err,
+			      const char *event)
+{
+	if (!err->num_errors)
+		return;
+
+	__parse_events_print_error(err->idx, err->str, err->help, event);
+	zfree(&err->str);
+	zfree(&err->help);
+
+	if (err->num_errors > 1) {
+		fputs("\nInitial error:\n", stderr);
+		__parse_events_print_error(err->first_idx, err->first_str,
+					err->first_help, event);
+		zfree(&err->first_str);
+		zfree(&err->first_help);
 	}
 }
 
@@ -2071,7 +2104,9 @@ int parse_events_option(const struct option *opt, const char *str,
 			int unset __maybe_unused)
 {
 	struct evlist *evlist = *(struct evlist **)opt->value;
-	struct parse_events_error err = { .idx = 0, };
+	struct parse_events_error err;
+
+	bzero(&err, sizeof(err));
 	int ret = parse_events(evlist, str, &err);
 
 	if (ret) {
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 5ee8ac93840c..ff367f248fe8 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -110,9 +110,13 @@ struct parse_events_term {
 };
 
 struct parse_events_error {
+	int   num_errors;       /* number of errors encountered */
 	int   idx;	/* index in the parsed string */
 	char *str;      /* string to display at the index */
 	char *help;	/* optional help string */
+	int   first_idx;/* as above, but for the first encountered error */
+	char *first_str;
+	char *first_help;
 };
 
 struct parse_events_state {
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog


  parent reply	other threads:[~2019-10-30 22:35 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191017170531.171244-1-irogers@google.com>
2019-10-23  0:53 ` [PATCH v2 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-23  0:53   ` [PATCH v2 1/9] perf tools: add parse events append error Ian Rogers
2019-10-23  8:36     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 2/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-23  8:40     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 3/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-23  8:50     ` Jiri Olsa
2019-10-23  0:53   ` [PATCH v2 4/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-23  8:55     ` Jiri Olsa
2019-10-23 12:37       ` Arnaldo Carvalho de Melo
2019-11-12 11:18     ` [tip: perf/core] perf tools: Move " tip-bot2 for Ian Rogers
2019-10-23  0:53   ` [PATCH v2 5/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-23  8:58     ` Jiri Olsa
2019-10-23 12:38       ` Arnaldo Carvalho de Melo
2019-11-12 11:18     ` [tip: perf/core] perf tools: Avoid a malloc() " tip-bot2 for Ian Rogers
2019-10-23  0:53   ` [PATCH v2 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-23  9:01     ` Jiri Olsa
2019-10-24 19:03       ` Ian Rogers
2019-10-23  0:53   ` [PATCH v2 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-23  0:53   ` [PATCH v2 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-23  0:53   ` [PATCH v2 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-24 19:01   ` [PATCH v3 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-24 19:01     ` [PATCH v3 1/9] perf tools: add parse events append error Ian Rogers
2019-10-25  7:58       ` Jiri Olsa
2019-10-25 15:14         ` Ian Rogers
2019-10-28 19:32           ` Jiri Olsa
2019-10-28 21:06             ` Ian Rogers
2019-10-28 21:36               ` Jiri Olsa
2019-11-04 20:37                 ` Ian Rogers
2019-10-24 19:01     ` [PATCH v3 2/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-25  8:01       ` Jiri Olsa
2019-10-25 15:47         ` Ian Rogers
2019-10-28 21:06           ` Jiri Olsa
2019-10-24 19:01     ` [PATCH v3 3/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-25  8:10       ` Jiri Olsa
2019-10-25 15:52         ` Ian Rogers
2019-10-24 19:01     ` [PATCH v3 4/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-24 19:01     ` [PATCH v3 5/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-24 19:01     ` [PATCH v3 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-25  8:27       ` Jiri Olsa
2019-10-25 16:08         ` Ian Rogers
2019-10-28 19:33           ` Jiri Olsa
2019-10-24 19:02     ` [PATCH v3 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-24 19:02     ` [PATCH v3 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-24 19:02     ` [PATCH v3 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-25 18:08     ` [PATCH v4 0/9] Improvements to memory usage by parse events Ian Rogers
2019-10-25 18:08       ` [PATCH v4 1/9] perf tools: add parse events handle error Ian Rogers
2019-10-25 18:08       ` [PATCH v4 2/9] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-25 18:08       ` [PATCH v4 3/9] perf tools: avoid a malloc for array events Ian Rogers
2019-10-25 18:08       ` [PATCH v4 4/9] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-28 21:07         ` Jiri Olsa
2019-10-30 11:56           ` Arnaldo Carvalho de Melo
2019-11-12 11:18         ` [tip: perf/core] perf tools: Splice " tip-bot2 for Ian Rogers
2019-10-25 18:08       ` [PATCH v4 5/9] perf tools: ensure config and str in terms are unique Ian Rogers
2019-10-25 18:08       ` [PATCH v4 6/9] perf tools: add destructors for parse event terms Ian Rogers
2019-10-25 18:08       ` [PATCH v4 7/9] perf tools: before yyabort-ing free components Ian Rogers
2019-10-25 18:08       ` [PATCH v4 8/9] perf tools: if pmu configuration fails free terms Ian Rogers
2019-10-25 18:08       ` [PATCH v4 9/9] perf tools: add a deep delete for parse event terms Ian Rogers
2019-10-30 22:34       ` [PATCH v5 00/10] Improvements to memory usage by parse events Ian Rogers
2019-10-30 22:34         ` [PATCH v5 01/10] perf tools: add parse events handle error Ian Rogers
2019-11-06 14:06           ` Jiri Olsa
2019-11-06 14:29             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 02/10] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-10-30 22:34         ` [PATCH v5 03/10] perf tools: avoid a malloc for array events Ian Rogers
2019-10-30 22:34         ` [PATCH v5 04/10] perf tools: splice events onto evlist even on error Ian Rogers
2019-10-30 22:34         ` [PATCH v5 05/10] perf tools: ensure config and str in terms are unique Ian Rogers
2019-11-06 14:25           ` Jiri Olsa
2019-11-06 14:31             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Ensure " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 06/10] perf tools: add destructors for parse event terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:35             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 07/10] perf tools: before yyabort-ing free components Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:37             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Before " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 08/10] perf tools: if pmu configuration fails free terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:38             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: If " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` [PATCH v5 09/10] perf tools: add a deep delete for parse event terms Ian Rogers
2019-11-06 14:24           ` Jiri Olsa
2019-11-06 14:39             ` Arnaldo Carvalho de Melo
2019-11-12 11:17           ` [tip: perf/core] perf parse: Add " tip-bot2 for Ian Rogers
2019-10-30 22:34         ` Ian Rogers [this message]
2019-11-06 14:24           ` [PATCH v5 10/10] perf tools: report initial event parsing error Jiri Olsa
2019-11-07 22:14         ` [PATCH v6 00/10] Improvements to memory usage by parse events Ian Rogers
2019-11-07 22:14           ` [PATCH v6 01/10] perf tools: add parse events handle error Ian Rogers
2019-11-07 22:14           ` [PATCH v6 02/10] perf tools: move ALLOC_LIST into a function Ian Rogers
2019-11-07 22:14           ` [PATCH v6 03/10] perf tools: avoid a malloc for array events Ian Rogers
2019-11-07 22:14           ` [PATCH v6 04/10] perf tools: splice events onto evlist even on error Ian Rogers
2019-11-07 22:14           ` [PATCH v6 05/10] perf tools: ensure config and str in terms are unique Ian Rogers
2019-11-07 22:14           ` [PATCH v6 06/10] perf tools: add destructors for parse event terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 07/10] perf tools: before yyabort-ing free components Ian Rogers
2019-11-07 22:14           ` [PATCH v6 08/10] perf tools: if pmu configuration fails free terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 09/10] perf tools: add a deep delete for parse event terms Ian Rogers
2019-11-07 22:14           ` [PATCH v6 10/10] perf tools: report initial event parsing error Ian Rogers
2019-11-07 22:23           ` [PATCH v6 00/10] Improvements to memory usage by parse events Arnaldo Carvalho de Melo
2019-11-08 18:18             ` Ian Rogers

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=20191030223448.12930-11-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=daniel@iogearbox.net \
    --cc=eranian@google.com \
    --cc=john.garry@huawei.com \
    --cc=jolsa@redhat.com \
    --cc=kafai@fb.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=songliubraving@fb.com \
    --cc=yao.jin@linux.intel.com \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).