public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	"David Ahern" <dsahern@gmail.com>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Matt Fleming" <matt@codeblueprint.co.uk>,
	"Raphaël Beamonte" <raphael.beamonte@gmail.com>
Subject: [PATCH 11/11] perf tools: Enhance parsing events tracepoint error output
Date: Wed, 26 Aug 2015 15:46:53 +0200	[thread overview]
Message-ID: <1440596813-12844-12-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1440596813-12844-1-git-send-email-jolsa@kernel.org>

Enhancing parsing events tracepoint error output. Adding
more verbose output when the tracepoint is not found or
the tracing event path cannot be access.

  $ sudo perf record -e sched:sched_krava ls
  event syntax error: 'sched:sched_krava'
                       \___ unknown tracepoint

  Error:  File /sys/kernel/debug/tracing//tracing/events/sched/sched_krava not found.
  Hint:   Perhaps this kernel misses some CONFIG_ setting to enable this feature?.

  Run 'perf list' for a list of valid events
  ...

  $ perf record -e sched:sched_krava ls
  event syntax error: 'sched:sched_krava'
                       \___ can't access trace events

  Error:  No permissions to read /sys/kernel/debug/tracing//tracing/events/sched/sched_krava
  Hint:   Try 'sudo mount -o remount,mode=755 /sys/kernel/debug'

  Run 'perf list' for a list of valid events
  ...

Link: http://lkml.kernel.org/n/tip-l0lu26995rir1h6v0e7kqyzz@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/parse-events.c | 30 +++++++++++++++++++++++++++---
 tools/perf/util/parse-events.y | 16 +++++++++-------
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index ff8a28ac31b7..1a6d8c80388d 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -387,6 +387,28 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 	return add_event(list, idx, &attr, name, NULL);
 }
 
+static void tracepoint_error(struct parse_events_error *error, int err,
+			     char *sys, char *name)
+{
+	char help[BUFSIZ];
+	err = abs(err);
+
+	switch (err) {
+	case EACCES:
+		error->str = strdup("can't access trace events");
+		break;
+	case ENOENT:
+		error->str = strdup("unknown tracepoint");
+		break;
+	default:
+		error->str = strdup("failed to add tracepoint");
+		break;
+	}
+
+	tracing_path_strerror_open_tp(err, help, sizeof(help), sys, name);
+	error->help = strdup(help);
+}
+
 static int add_tracepoint(struct list_head *list, int *idx,
 			  char *sys_name, char *evt_name,
 			  struct parse_events_error *error __maybe_unused)
@@ -394,8 +416,10 @@ static int add_tracepoint(struct list_head *list, int *idx,
 	struct perf_evsel *evsel;
 
 	evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
-	if (IS_ERR(evsel))
+	if (IS_ERR(evsel)) {
+		tracepoint_error(error, PTR_ERR(evsel), sys_name, evt_name);
 		return -ENOMEM;
+	}
 
 	list_add_tail(&evsel->node, list);
 
@@ -414,7 +438,7 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
 	snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
 	evt_dir = opendir(evt_path);
 	if (!evt_dir) {
-		perror("Can't open event dir");
+		tracepoint_error(error, errno, sys_name, evt_name);
 		return -1;
 	}
 
@@ -454,7 +478,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 
 	events_dir = opendir(tracing_events_path);
 	if (!events_dir) {
-		perror("Can't open event dir");
+		tracepoint_error(error, errno, sys_name, evt_name);
 		return -1;
 	}
 
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 742914746794..2ccc6911dc5e 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -371,28 +371,30 @@ event_legacy_tracepoint:
 PE_NAME '-' PE_NAME ':' PE_NAME
 {
 	struct parse_events_evlist *data = _data;
+	struct parse_events_error *error = data->error;
 	struct list_head *list;
 	char sys_name[128];
 	snprintf(&sys_name, 128, "%s-%s", $1, $3);
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, data->error));
+	if (parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, error)) {
+		if (error)
+			error->idx = @1.first_column;
+		return -1;
+	}
 	$$ = list;
 }
 |
 PE_NAME ':' PE_NAME
 {
 	struct parse_events_evlist *data = _data;
+	struct parse_events_error *error = data->error;
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	if (parse_events_add_tracepoint(list, &data->idx, $1, $3, data->error)) {
-		struct parse_events_error *error = data->error;
-
-		if (error) {
+	if (parse_events_add_tracepoint(list, &data->idx, $1, $3, error)) {
+		if (error)
 			error->idx = @1.first_column;
-			error->str = strdup("unknown tracepoint");
-		}
 		return -1;
 	}
 	$$ = list;
-- 
2.4.3


      parent reply	other threads:[~2015-08-26 13:47 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-26 13:46 [RFC 00/11] perf tools: Enhance parsing events tracepoint error output Jiri Olsa
2015-08-26 13:46 ` [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Jiri Olsa
2015-08-28 16:21   ` Arnaldo Carvalho de Melo
2015-08-31  7:37     ` Jiri Olsa
2015-08-31 15:27       ` Arnaldo Carvalho de Melo
2015-08-26 13:46 ` [PATCH 02/11] perf tools: Add tracing_path and remove unneeded functions Jiri Olsa
2015-08-27 22:47   ` Matt Fleming
2015-08-28 16:27     ` Arnaldo Carvalho de Melo
2015-08-29 10:25       ` Jiri Olsa
2015-08-31  8:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
2015-08-26 13:46 ` [PATCH 03/11] perf tools: Do not change lib/api/fs/debugfs directly Jiri Olsa
     [not found]   ` <CAE_Gge2cn8LpuETTTkf2nP8JLj=9RDiuW3M8BXzv7ZTJpY9x7w@mail.gmail.com>
2015-08-26 14:17     ` Jiri Olsa
2015-08-26 14:27     ` Arnaldo Carvalho de Melo
2015-08-28 12:26       ` Matt Fleming
2015-08-28 12:19   ` Matt Fleming
2015-08-31  8:33   ` [tip:perf/core] perf tools: Do not change lib/api/fs/ debugfs directly tip-bot for Jiri Olsa
2015-08-26 13:46 ` [PATCH 04/11] perf tools: Move debugfs__strerror_open into util.c object Jiri Olsa
2015-08-26 13:52   ` Arnaldo Carvalho de Melo
2015-08-26 14:16     ` Jiri Olsa
2015-08-28 12:59   ` Matt Fleming
2015-08-26 13:46 ` [PATCH 05/11] perf tools: Move tracing_path stuff under same namespace Jiri Olsa
2015-08-26 14:42   ` Arnaldo Carvalho de Melo
2015-08-26 14:48     ` Jiri Olsa
2015-08-26 14:58       ` Arnaldo Carvalho de Melo
2015-08-26 15:06         ` Jiri Olsa
2015-08-28 13:06           ` Matt Fleming
2015-08-31  7:43             ` Jiri Olsa
2015-08-26 13:46 ` [PATCH 06/11] perf tools: Move tracing_path interface into trace-event-path.c Jiri Olsa
2015-08-26 13:46 ` [PATCH 07/11] perf tools: Make tracing_path_strerror_open message generic Jiri Olsa
2015-08-26 13:46 ` [PATCH 08/11] perf tools: Do not export debugfs_mountpoint and tracefs_mountpoint Jiri Olsa
2015-08-26 13:46 ` [PATCH 09/11] perf tools: Propagate error info for the tracepoint parsing Jiri Olsa
2015-08-28 13:20   ` Matt Fleming
2015-08-28 13:32     ` Jiri Olsa
2015-08-26 13:46 ` [PATCH 10/11] perf tools: Propagate error info from tp_format Jiri Olsa
2015-08-26 13:46 ` Jiri Olsa [this message]

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=1440596813-12844-12-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=raphael.beamonte@gmail.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