BPF List
 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@kernel.org>,  Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>,
	 Adrian Hunter <adrian.hunter@intel.com>,
	Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
	 Kan Liang <kan.liang@linux.intel.com>,
	linux-perf-users@vger.kernel.org,  linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org
Subject: [PATCH v2 10/13] perf parse-events: Additional error reporting
Date: Tue, 27 Jun 2023 11:10:27 -0700	[thread overview]
Message-ID: <20230627181030.95608-11-irogers@google.com> (raw)
In-Reply-To: <20230627181030.95608-1-irogers@google.com>

When no events or PMUs match report an error for event_pmu:

Before:
```
$ perf stat -e 'asdfasdf' -a sleep 1
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
```

After:
```
$ perf stat -e 'asdfasdf' -a sleep 1
event syntax error: 'asdfasdf'
                     \___ Bad event name

Unabled to find PMU or event on a PMU of 'asdfasdf'
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
```

Fixes the inadvertent removal when hybrid parsing was modified.

Fixes: ("70c90e4a6b2f perf parse-events: Avoid scanning PMUs before parsing")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/parse-events.y | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index f090a85c4518..a636a7db6e6f 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -291,7 +291,6 @@ PE_NAME opt_pmu_config
 {
 	struct parse_events_state *parse_state = _parse_state;
 	struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
-	struct parse_events_error *error = parse_state->error;
 	char *pattern = NULL;
 
 #define CLEANUP						\
@@ -303,9 +302,6 @@ PE_NAME opt_pmu_config
 		free(pattern);				\
 	} while(0)
 
-	if (error)
-		error->idx = @1.first_column;
-
 	if (parse_events_copy_term_list($2, &orig_terms)) {
 		CLEANUP;
 		YYNOMEM;
@@ -360,6 +356,14 @@ PE_NAME opt_pmu_config
 			$2 = NULL;
 		}
 		if (!ok) {
+			struct parse_events_error *error = parse_state->error;
+			char *help;
+
+			if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0)
+				help = NULL;
+			parse_events_error__handle(error, @1.first_column,
+						   strdup("Bad event or PMU"),
+						   help);
 			CLEANUP;
 			YYABORT;
 		}
@@ -376,9 +380,18 @@ PE_NAME sep_dc
 	int err;
 
 	err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
-	free($1);
-	if (err < 0)
+	if (err < 0) {
+		struct parse_events_state *parse_state = _parse_state;
+		struct parse_events_error *error = parse_state->error;
+		char *help;
+
+		if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0)
+			help = NULL;
+		parse_events_error__handle(error, @1.first_column, strdup("Bad event name"), help);
+		free($1);
 		PE_ABORT(err);
+	}
+	free($1);
 	$$ = list;
 }
 
-- 
2.41.0.162.gfafddb0af9-goog


  parent reply	other threads:[~2023-06-27 18:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-27 18:10 [PATCH v2 00/13] parse-events clean up Ian Rogers
2023-06-27 18:10 ` [PATCH v2 01/13] perf parse-events: Remove unused PE_PMU_EVENT_FAKE token Ian Rogers
2023-06-30 16:35   ` Markus Elfring
2023-06-30 17:05     ` Ian Rogers
2023-06-30 17:15       ` [v2 " Markus Elfring
2023-06-30 17:16         ` Ian Rogers
2023-06-30 17:23           ` Markus Elfring
2023-06-30 17:33             ` Ian Rogers
2023-06-30 17:52               ` Markus Elfring
2023-06-30 18:01                 ` Ian Rogers
2023-07-01  8:00                   ` Markus Elfring
2023-07-03 12:46       ` [PATCH v2 " Dan Carpenter
2023-07-03 13:08         ` [v2 " Markus Elfring
2023-06-27 18:10 ` [PATCH v2 02/13] perf parse-events: Remove unused PE_KERNEL_PMU_EVENT token Ian Rogers
2023-06-27 18:10 ` [PATCH v2 03/13] perf parse-events: Remove two unused tokens Ian Rogers
2023-06-27 18:10 ` [PATCH v2 04/13] perf parse-events: Add more comments to parse_events_state Ian Rogers
2023-06-27 18:10 ` [PATCH v2 05/13] perf parse-events: Avoid regrouped warning for wild card events Ian Rogers
2023-06-27 18:10 ` [PATCH v2 06/13] perf parse-event: Add memory allocation test for name terms Ian Rogers
2023-06-27 18:10 ` [PATCH v2 07/13] perf parse-events: Separate YYABORT and YYNOMEM cases Ian Rogers
2023-06-27 18:10 ` [PATCH v2 08/13] perf parse-events: Move instances of YYABORT to YYNOMEM Ian Rogers
2023-06-27 18:10 ` [PATCH v2 09/13] perf parse-events: Separate ENOMEM memory handling Ian Rogers
2023-06-27 18:10 ` Ian Rogers [this message]
2023-06-27 18:10 ` [PATCH v2 11/13] perf parse-events: Populate error column for BPF/tracepoint events Ian Rogers
2023-06-27 18:10 ` [PATCH v2 12/13] perf parse-events: Improve location for add pmu Ian Rogers
2023-06-27 18:10 ` [PATCH v2 13/13] perf parse-events: Remove ABORT_ON Ian Rogers
2023-06-29 21:49   ` Namhyung Kim
2023-06-30 15:14     ` Ian Rogers
2023-07-01 18:43       ` Namhyung Kim
2023-07-12  5:01         ` Ian Rogers
2023-06-30 16:56   ` Markus Elfring
2023-06-30 17:06     ` Ian Rogers
2023-06-30 17:40       ` [v2 " Markus Elfring
2023-06-30 18:05         ` Ian Rogers
2023-07-01  9:00           ` Markus Elfring
2023-07-01  9:32             ` Greg KH

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=20230627181030.95608-11-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /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